def test_full_game(self): """ Test that I can run a game all the way to the end without an error.""" # Random, but fixed, opening hands. hand_0 = ['EA_', 'EO_', 'S10', 'G8_', 'S7_', 'SA_', 'GU_', 'E7_'] hand_1 = ['S8_', 'E10', 'SU_', 'GA_', 'HO_', 'H9_', 'H7_', 'SO_'] hand_2 = ['EU_', 'H8_', 'SK_', 'G7_', 'G9_', 'EK_', 'HU_', 'GO_'] hand_3 = ['HK_', 'HA_', 'GK_', 'H10', 'E9_', 'G10', 'E8_', 'S9_'] player_dict = {0: hand_0, 1: hand_1, 2: hand_2, 3: hand_3} # Player 1 calls a eichel partner play, (with player 0.) state = GameState(game_mode="Partner Eichel", offensive_player=1, active=0) for i in range(8): for j in range(4): hand = player_dict[state.active] possible = state.actions(hand) chosen = possible[0] # pick the first of the possible moves, don't want randomness in unittests. state = state.result(chosen) hand.remove(chosen) state.calculate_round_winner(state.history[-16:]) state.utilities() self.assertTrue(state.terminal_test()) self.assertEqual(state.played_the_ace(), 0) # correctly identifies who the partner is.
def test_full_game(self): """ Test to see if during the course of a full game, we can correctly deduce which cards the other player has. I'm undecided as to whether we want this test to have a random element or not.""" # Random but fixed hands. hands = { 0: {'SK_', 'S7_', 'H10', 'H7_', 'HK_', 'E8_', 'HU_', 'GU_'}, 1: {'G9_', 'HO_', 'S10', 'H9_', 'EO_', 'E10', 'GO_', 'GK_'}, 2: {'G10', 'SU_', 'G8_', 'E9_', 'G7_', 'SO_', 'S9_', 'S8_'}, 3: {'GA_', 'EU_', 'E7_', 'H8_', 'SA_', 'EA_', 'EK_', 'HA_'} } state = GameState(game_mode="Herz Solo", offensive_player=1, active=0) for _ in range(32): active = state.active action = random.choice(state.actions(hands[active])) hands[active].remove(action) state = state.result(action) for i in range(4): card_constraints, _ = inverse_legal_moves(state, hands[i], i) for p_num, card_set in card_constraints.items(): actual_hand = hands[p_num] self.assertTrue(actual_hand.issubset(card_set))
def test_empty_piles_game_over(self): state = GameState() card_piles = [[[], [], []], [[], [], []], [[], [], []]] state.start_new_game(lucky_card=Card("Q", "s"), card_piles=card_piles) state.discards_remaining = 2 assert len(state.actions()) == 0 assert state.is_game_over()
def test_all_piles_same_row_not_game_over(self): state = GameState() card_piles = [[[Card("A", "s")], [Card("2", "s")], [Card("3", "s")]], [[], [], []], [[], [], []]] state.start_new_game(lucky_card=Card("4", "s"), card_piles=card_piles) state.discards_remaining = 1 assert len(state.actions()) == 3 assert not state.is_game_over()
class CheckDavonlaufen(unittest.TestCase): def setUp(self): self.gamemode = "Partner Eichel" self.hand = ["E7_", "E8_", "E9_", "EA_", "S7_"] self.state = GameState(game_mode=self.gamemode, offensive_player=1, active=0) def test_open_davonlaufen(self): allowed = self.state.actions(self.hand) self.assertEqual(allowed, self.hand) def test_follow(self): new_state = self.state.result("E10") allowed = new_state.actions(self.hand) expected = ["EA_"] self.assertEqual(allowed, expected) def test_open_normal(self): self.hand.remove("E9_") allowed = self.state.actions(self.hand) expected = ["EA_", "S7_"] self.assertEqual(allowed, expected) def test_follow_not_called(self): new_state = self.state.result("G10") allowed = new_state.actions(self.hand) expected = ["E7_", "E8_", "E9_", "S7_"] self.assertEqual(allowed, expected) def test_last_card(self): new_state = self.state.result("G10") new_hand = ["EA"] allowed = new_state.actions(new_hand) expected = new_hand self.assertEqual(allowed, expected)
def test_full_game_2(self): """ Test to see if during the course of a full game, we can correctly assign cards to players without raising any exceptions. I'm undecided as to whether we want this test to have a random element or not.""" # Random but fixed hands. hands = { 0: {'SK_', 'S7_', 'H10', 'H7_', 'HK_', 'E8_', 'HU_', 'GU_'}, 1: {'G9_', 'HO_', 'S10', 'H9_', 'EO_', 'E10', 'GO_', 'GK_'}, 2: {'G10', 'SU_', 'G8_', 'E9_', 'G7_', 'SO_', 'S9_', 'S8_'}, 3: {'GA_', 'EU_', 'E7_', 'H8_', 'SA_', 'EA_', 'EK_', 'HA_'} } state = GameState(game_mode="Herz Solo", offensive_player=1, active=0) for _ in range(32): active = state.active action = random.choice(state.actions(hands[active])) hands[active].remove(action) state = state.result(action) for i in range(4): arbitrary_assignment = assign_hands(state, hands[i], i)
def test_near_game_end_actions(self): turn20_state = GameState() card_piles = [[[], [], [Card("5", "d")]], [[Card("9", "d"), Card("4", "h")], [Card("4", "d"), Card("T", "d")], [Card("K", "h")]], [[Card("8", "c")], [], [Card("T", "h")]]] turn20_state.start_new_game(lucky_card=Card("7", "h"), card_piles=card_piles) turn20_state.discards_remaining = 2 turn20_state_actions = turn20_state.actions() assert len(turn20_state_actions ) == 7 # six piles to discard from, only one possible hand turn21_state = turn20_state.copy() turn21_state.card_num_piles[0][2] = turn20_state.card_num_piles[0][2][ 1:] turn21_state.discards_remaining = 1 assert (set([(0, 2)]), turn21_state, 150) in turn20_state_actions turn21_state_actions = turn21_state.actions() assert len(turn21_state_actions ) == 6 # five piles to discard from, only one possible hand turn22_state = turn21_state.copy() turn22_state.card_num_piles[1][0] = turn21_state.card_num_piles[1][0][ 1:] turn22_state.card_num_piles[2][0] = turn21_state.card_num_piles[2][0][ 1:] turn22_state.card_num_piles[2][2] = turn21_state.card_num_piles[2][2][ 1:] turn22_state.discards_remaining = 2 turn22_state.dead_card_nums.add(turn21_state.card_num_piles[1][0][1]) # a three-straight with lucky bonus and 2x 50 pt pile clear bonuses assert (set([(1, 0), (2, 0), (2, 2)]), turn22_state, 40 + 50 + 50) in turn21_state_actions turn22_state_actions = turn22_state.actions() assert len( turn22_state_actions ) == 3 # only three non-empty piles left, all on the same row turn23_state = turn22_state.copy() turn23_state.card_num_piles[1][0] = turn22_state.card_num_piles[1][0][ 1:] turn23_state.discards_remaining = 1 assert (set([(1, 0)]), turn23_state, 100) in turn22_state_actions turn23_state_actions = turn23_state.actions() assert len( turn23_state_actions ) == 2 # only two non-empty piles left, both on the same row turn24_state = turn23_state.copy() turn24_state.card_num_piles[1][2] = turn23_state.card_num_piles[1][2][ 1:] turn24_state.discards_remaining = 0 assert (set([(1, 2)]), turn24_state, 100) in turn23_state_actions assert len(turn24_state.actions()) == 0 assert turn24_state.is_game_over()
def test_discard_clear_bonus(self): state = GameState() card_piles = [[[Card("2", "s")], [Card("K", "h")], [Card("K", "s")]], [[Card("3", "c")], [Card("A", "s")], [Card("6", "s")]], [[Card("3", "s")], [Card("A", "c")], [Card("K", "c")]]] state.start_new_game(lucky_card=Card("7", "h"), card_piles=card_piles) state.discards_remaining = 1 state_actions = state.actions() # print(state_actions) assert len(state_actions) == 21 # 4 pairs (can't pick both Kings on the top row) new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.card_num_piles[2][2] = [] new_state.discards_remaining = 2 assert (set([ (0, 1), (2, 2) ]), new_state, 20 + 150 + 50) in state_actions # note the lucky bonus new_state = state.copy() new_state.card_num_piles[0][2] = [] new_state.card_num_piles[2][2] = [] new_state.discards_remaining = 2 assert (set([(0, 2), (2, 2)]), new_state, 10 + 150 + 50) in state_actions new_state = state.copy() new_state.card_num_piles[1][0] = [] new_state.card_num_piles[2][0] = [] new_state.discards_remaining = 2 assert (set([(1, 0), (2, 0)]), new_state, 10 + 100 + 50) in state_actions new_state = state.copy() new_state.card_num_piles[1][1] = [] new_state.card_num_piles[2][1] = [] new_state.discards_remaining = 2 assert (set([(1, 1), (2, 1)]), new_state, 10 + 100 + 50) in state_actions # this isn't a valid hand (the cards are on the same row) new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.card_num_piles[0][2] = [] new_state.discards_remaining = 2 assert (set([(0, 1), (0, 2)]), new_state, 20 + 150 + 150) not in state_actions # 1 trips new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.card_num_piles[0][2] = [] new_state.card_num_piles[2][2] = [] new_state.discards_remaining = 2 assert (set([(0, 1), (0, 2), (2, 2)]), new_state, 60 + 150 + 150 + 50) in state_actions # note the lucky bonus # 2 full houses new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.card_num_piles[0][2] = [] new_state.card_num_piles[2][2] = [] new_state.card_num_piles[1][1] = [] new_state.card_num_piles[2][1] = [] new_state.discards_remaining = 2 assert (set([(0, 1), (0, 2), (2, 2), (1, 1), (2, 1)]), new_state, 140 + 150 + 150 + 50 + 100 + 50) in state_actions # note the lucky bonus new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.card_num_piles[0][2] = [] new_state.card_num_piles[2][2] = [] new_state.card_num_piles[1][0] = [] new_state.card_num_piles[2][0] = [] new_state.discards_remaining = 2 assert (set([(0, 1), (0, 2), (2, 2), (1, 0), (2, 0)]), new_state, 140 + 150 + 150 + 50 + 100 + 50) in state_actions # note the lucky bonus # 4 three-straights new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.card_num_piles[1][0] = [] new_state.card_num_piles[1][1] = [] new_state.discards_remaining = 2 assert (set([(0, 0), (1, 0), (1, 1)]), new_state, 20 + 150 + 100 + 100) in state_actions new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.card_num_piles[2][0] = [] new_state.card_num_piles[1][1] = [] new_state.discards_remaining = 2 assert (set([(0, 0), (2, 0), (1, 1)]), new_state, 20 + 150 + 50 + 100) in state_actions new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.card_num_piles[1][0] = [] new_state.card_num_piles[2][1] = [] new_state.discards_remaining = 2 assert (set([(0, 0), (1, 0), (2, 1)]), new_state, 20 + 150 + 100 + 50) in state_actions new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.card_num_piles[2][0] = [] new_state.card_num_piles[2][1] = [] new_state.discards_remaining = 2 assert (set([(0, 0), (2, 0), (2, 1)]), new_state, 20 + 150 + 50 + 50) in state_actions # 1 flush new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.card_num_piles[0][2] = [] new_state.card_num_piles[1][1] = [] new_state.card_num_piles[1][2] = [] new_state.card_num_piles[2][0] = [] new_state.discards_remaining = 2 assert (set([(0, 0), (0, 2), (1, 1), (1, 2), (2, 0)]), new_state, 90 + 150 + 150 + 100 + 100 + 50) in state_actions # 9 discard actions new_state = state.copy() new_state.card_num_piles[0][0] = [] new_state.discards_remaining = 0 assert (set([(0, 0)]), new_state, 150) in state_actions new_state = state.copy() new_state.card_num_piles[0][1] = [] new_state.discards_remaining = 0 assert (set([(0, 1)]), new_state, 150) in state_actions new_state = state.copy() new_state.card_num_piles[0][2] = [] new_state.discards_remaining = 0 assert (set([(0, 2)]), new_state, 150) in state_actions new_state = state.copy() new_state.card_num_piles[1][0] = [] new_state.discards_remaining = 0 assert (set([(1, 0)]), new_state, 100) in state_actions new_state = state.copy() new_state.card_num_piles[1][1] = [] new_state.discards_remaining = 0 assert (set([(1, 1)]), new_state, 100) in state_actions new_state = state.copy() new_state.card_num_piles[1][2] = [] new_state.discards_remaining = 0 assert (set([(1, 2)]), new_state, 100) in state_actions new_state = state.copy() new_state.card_num_piles[2][0] = [] new_state.discards_remaining = 0 assert (set([(2, 0)]), new_state, 50) in state_actions new_state = state.copy() new_state.card_num_piles[2][1] = [] new_state.discards_remaining = 0 assert (set([(2, 1)]), new_state, 50) in state_actions new_state = state.copy() new_state.card_num_piles[2][2] = [] new_state.discards_remaining = 0 assert (set([(2, 2)]), new_state, 50) in state_actions