def play_round(self, round):
        self.rounds.append(round)
        self.current_round = round

        pairings = itertools.combinations(self.lobby.values(), 2)

        for pairing in pairings:
            player_1 = pairing[0]
            player_2 = pairing[1]

            # TODO: since X always has the advantage, would it be better
            # to generate two games for each pairing?  To give them an
            # equal chance at the advantage?

            new_game = Game("{} vs {}".format(player_1.name, player_2.name),
                            uuid4(),
                            deepcopy(player_1),
                            deepcopy(player_2),
                            size_x=round.x_size,
                            size_y=round.y_size,
                            winning_length=round.winning_length)
            new_game.state = GAME_INPROGRESS

            round.games.append(new_game)
            game_thread(new_game)

        self.process_completed_game()
Exemple #2
0
    def test__game_thread__will_terminate_when_player_o_wins(self, mock_post):
        mock_post.side_effect = _post_fake_o_wins
        game_thread(self.game)

        call_count = mock_post.call_count
        self.assertEqual(8, call_count)
        self.assertEqual(GAME_COMPLETED, self.game.state)
        self.assertEqual(False, self.game.player_x.winner)
        self.assertEqual(True, self.game.player_o.winner)
Exemple #3
0
    def test__game_thread__will_terminate_with_a_draw_when_exception_raised(
            self, mock_post):
        mock_post.side_effect = ValueError("ugh")

        game_thread(self.game)

        self.assertEqual(GAME_COMPLETED, self.game.state)
        self.assertEqual(False, self.game.player_x.winner)
        self.assertEqual(False, self.game.player_o.winner)
Exemple #4
0
    def test__game_thread__will_terminate_in_size_x_times_size_y_moves_at_most(
            self, mock_post):
        mock_post.side_effect = _post_fake_no_winner
        game_thread(self.game)

        call_count = mock_post.call_count
        self.assertEqual(self.game.max_moves + 2, call_count)
        self.assertEqual(GAME_COMPLETED, self.game.state)
        self.assertEqual(False, self.game.player_x.winner)
        self.assertEqual(False, self.game.player_o.winner)