def test_known_cards_in_hand(self):
        """Idea to test function is to simulate a whole bunch of games and check at each point
        if the set of known cards and possible cards calculated is valid
        """
        whole_deck = sorted([
            Card(suite, face_card) for face_card in FaceCard for suite in Suite
        ])
        controller = GameController([RandomPlayer(0) for _ in range(4)],
                                    CardDeck(0))
        controller.play()
        for g_round in controller.game.rounds:
            if len(g_round.tricks) > 0:
                player_cards = g_round.players_cards[0]
                possible_cards = possible_cards_in_hand(
                    player_cards.hand, player_cards.index, player_cards.order,
                    g_round.kitty[0], g_round.trump, g_round.tricks)
                known_cards, possible_cards = update_possible_cards(
                    player_cards.hand, player_cards.index, g_round.tricks,
                    possible_cards)

                self.assertTrue(
                    len(list(chain(*list(possible_cards)))) == 0,
                    "Entire game should be played, possible cards are 0")
                self.assertListEqual(sorted(list(chain(*list(known_cards)))),
                                     whole_deck)
                self.assertListEqual(sorted(known_cards[4]),
                                     sorted(g_round.kitty))

                for i in range(5):
                    possible_cards = possible_cards_in_hand(
                        player_cards.hand, player_cards.index,
                        player_cards.order, g_round.kitty[0], g_round.trump,
                        g_round.tricks)
                    known_cards, possible_cards = update_possible_cards(
                        player_cards.hand, player_cards.index, g_round.tricks,
                        possible_cards)
                    # No repeats in known cards
                    all_known_cards = list(chain(*list(known_cards)))
                    self.assertEqual(len(all_known_cards),
                                     len(set(all_known_cards)))
                    # all cards accounted for
                    self.assertEqual(
                        set(
                            list(chain(*list(possible_cards))) +
                            all_known_cards), set(whole_deck))
from euchre.game_controller import GameController
from euchre.data_model import CardDeck
from euchre.players.RandomPlayer import RandomPlayer
from euchre.players.CommandLinePlayer import CommandLinePlayer

if __name__ == '__main__':
    controller = GameController([RandomPlayer(0)
                                 for _ in range(3)] + [CommandLinePlayer()],
                                CardDeck(0))
    controller.play()
Example #3
0
 def test_repeatability_game(self):
     controller1 = GameController([RandomPlayer(0) for _ in range(4)], CardDeck(0))
     controller1.play()
     controller2 = GameController([RandomPlayer(0) for _ in range(4)], CardDeck(0))
     controller2.play()
     self.__check_two_games_equal(controller1.game, controller2.game)
Example #4
0
 def test_web_player(self):
     controller = GameController([RandomPlayer(0) for _ in range(4)], CardDeck(0))
     controller.play()
     self.assertEqual(controller.game.current_action, GameAction.GAME_OVER)
     for r in controller.game.rounds:
         is_game_json_valid(game_to_json(r))
 def test_random_player(self):
     self.__execute_player_calls(RandomPlayer())
import cProfile
from performance.test_performance_util import EuchreSim
from euchre.players.RandomPlayer import RandomPlayer

# Print out time to run 1000 games with random players
euchre_sim = EuchreSim([RandomPlayer(i) for i in range(4)])
results = euchre_sim.simulate()
print("Sim Time: " + str(euchre_sim.sim_time))

# Actual profile of 1000 games
cProfile.run('EuchreSim([RandomPlayer(i) for i in range(4)]).simulate()')