def test_winner_3(self): game3 = FiveInARow() game3.add_player('P1') game3.setP1Token(1) game3.add_player('p2') game3.takeTurn(1) game3.change_turn() game3.takeTurn(2) game3.change_turn() game3.takeTurn(2) game3.change_turn() game3.takeTurn(4) game3.change_turn() game3.takeTurn(3) game3.change_turn() game3.takeTurn(3) game3.change_turn() game3.takeTurn(3) game3.change_turn() game3.takeTurn(4) game3.change_turn() game3.takeTurn(4) game3.change_turn() game3.takeTurn(5) game3.change_turn() game3.takeTurn(4) game3.change_turn() game3.takeTurn(5) game3.change_turn() game3.takeTurn(5) game3.change_turn() game3.takeTurn(5) game3.change_turn() game3.takeTurn(5) game3.change_turn() self.assertEqual(game3.is_over(), True) self.assertEqual(game3.winner, 1)
from flask import Flask, jsonify from five_in_a_row import FiveInARow from player import Player app = Flask(__name__) # when server starts, game starts and players can connect # Not the most scalable solution but I think its alright rather than over complicating whats in the brief # could save games into an array if we wanted to handle multiple games game = FiveInARow() @app.route('/') def index(): return 'Welcome to my awesome connect 5 game \n please use \'/join\' to enter the game' @app.route('/join/<string:name>', methods=['POST']) def join_game(name): if game.num_players < 2: game.add_player(name) player = Player(name, game.num_players) response = jsonify(data=player.__dict__, status=200) return response error_response = jsonify( data={'message': 'Sorry 2 players already participating'}, status=401) return error_response @app.route('/print', methods=['GET']) def display():
def test_winner_2(self): game2 = FiveInARow() game2.add_player('P1') game2.setP1Token(1) game2.add_player('P2') game2.takeTurn(9) game2.change_turn() game2.takeTurn(1) game2.change_turn() game2.takeTurn(8) game2.change_turn() game2.takeTurn(2) game2.change_turn() game2.takeTurn(9) game2.change_turn() game2.takeTurn(3) game2.change_turn() game2.takeTurn(8) game2.change_turn() game2.takeTurn(4) game2.change_turn() game2.takeTurn(9) game2.change_turn() game2.takeTurn(5) game2.change_turn() self.assertEqual(game2.is_over(), True) self.assertEqual(game2.winner, 2)
def test_create_and_start_game(self): game = FiveInARow() self.assertEqual(game.winner, None) self.assertEqual(game.turn, 1) self.assertEqual(game.is_over(), False) self.assertEqual(game.is_started(), False) game.add_player('p1') game.setP1Token(1) self.assertEqual(game.is_started(), False) game.add_player('p2') self.assertEqual(game.is_started(), True) self.assertEqual(game.is_over(), False)
def test_winner_1(self): game1 = FiveInARow() game1.add_player('p1') game1.setP1Token(1) game1.add_player('p2') game1.takeTurn(1) game1.change_turn() game1.takeTurn(2) game1.change_turn() game1.takeTurn(1) game1.change_turn() game1.takeTurn(2) game1.change_turn() game1.takeTurn(1) game1.change_turn() game1.takeTurn(2) game1.change_turn() game1.takeTurn(1) game1.change_turn() game1.takeTurn(2) game1.change_turn() game1.takeTurn(1) game1.change_turn() self.assertEqual(game1.is_over(), True) self.assertEqual(game1.winner, 1)
def test_game_winner(self): game = FiveInARow() game.add_player('p1') game.setP1Token(1) game.add_player('p2') game.setWinner(1) print(game.turn) self.assertEqual(game.is_over(), True) self.assertEqual(game.winner, 1)
def test_winner_4(self): game4 = FiveInARow() game4.add_player('P1') game4.setP1Token(1) game4.add_player('p2') game4.takeTurn(9) game4.change_turn() game4.takeTurn(8) game4.change_turn() game4.takeTurn(8) game4.change_turn() game4.takeTurn(6) game4.change_turn() game4.takeTurn(7) game4.change_turn() game4.takeTurn(7) game4.change_turn() game4.takeTurn(7) game4.change_turn() game4.takeTurn(6) game4.change_turn() game4.takeTurn(6) game4.change_turn() game4.takeTurn(5) game4.change_turn() game4.takeTurn(6) game4.change_turn() game4.takeTurn(5) game4.change_turn() game4.takeTurn(5) game4.change_turn() game4.takeTurn(5) game4.change_turn() game4.takeTurn(5) game4.change_turn() self.assertEqual(game4.is_over(), True) self.assertEqual(game4.winner, 1)