def setUp(self): self.hand_1 = Hand(1) self.hand_2 = Hand(2) self.c1 = Card(Colour.RED, 10) self.c2 = Card(Colour.BLUE, 1) self.c3 = Card(Colour.GREEN, 5) self.c4 = Card(Colour.PURPLE, 8) self.hand_1.add_card(self.c1) self.hand_1.add_card(self.c2) self.hand_2.add_card(self.c3) self.hand_2.add_card(self.c4) self.slot = Slot()
def test_is_this_card_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) c3 = Card(Colour.BLUE, 3) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c4, h2) slot_2.play_card(c2, h1) slot_2.play_card(c5, h2) slots = [slot_1, slot_2] self.assertTrue(self.slot.is_this_card_out(1, Colour.RED, slots)) self.assertTrue(self.slot.is_this_card_out(1, Colour.GREEN, slots)) self.assertFalse(self.slot.is_this_card_out(3, Colour.BLUE, slots)) self.assertFalse(self.slot.is_this_card_out(7, Colour.PURPLE, slots))
def test_get_highest_card_with_colour_not_played(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.BLUE, 9) c3 = Card(Colour.RED, 8) c4 = Card(Colour.RED, 6) c5 = Card(Colour.BLUE, 10) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slots = [slot_1, slot_2] self.assertEqual(self.slot.get_highest_card_with_colour_not_played(Colour.RED, slots), 10) self.assertEqual(self.slot.get_highest_card_with_colour_not_played(Colour.BLUE, slots), 8)
def load_game_objects(self): # Load Cards cm = CardManager.get_instance() cm.load_all_cards() # Load two Hands and add 7 starting cards to them self._h1 = Hand(1) self._h2 = Hand(2) self._h1.add_cards(cm.pick_random_inactive_cards(7)) self._h2.add_cards(cm.pick_random_inactive_cards(7)) # Load GameCards self._game_cards_1.extend( self.load_game_cards_for_hand(self._h1, self.P1_Y_VAL)) self._game_cards_2.extend( self.load_game_cards_for_hand(self._h2, self.P2_Y_VAL)) # Load Slots slots = [Slot() for i in range(9)] # Load GameSlots self._game_slots.extend(self.load_game_slots(slots, self.SLOTS_Y_VAL))
class TestSlot(unittest.TestCase): def setUp(self): self.hand_1 = Hand(1) self.hand_2 = Hand(2) self.c1 = Card(Colour.RED, 10) self.c2 = Card(Colour.BLUE, 1) self.c3 = Card(Colour.GREEN, 5) self.c4 = Card(Colour.PURPLE, 8) self.hand_1.add_card(self.c1) self.hand_1.add_card(self.c2) self.hand_2.add_card(self.c3) self.hand_2.add_card(self.c4) self.slot = Slot() def test_play_card(self): self.slot.play_card(self.c1, self.hand_1) self.assertEqual(len(self.hand_1.cards), 1) self.assertEqual(len(self.hand_2.cards), 2) self.assertEqual(len(self.slot.p1_played), 1) self.assertEqual(len(self.slot.p2_played), 0) def test_play_card_hand_does_not_have_card(self): try: self.slot.play_card(self.c1, self.hand_2) self.fail('ValueError not thrown') except ValueError: pass self.assertEqual(len(self.hand_1.cards), 2) self.assertEqual(len(self.hand_2.cards), 2) self.assertEqual(len(self.slot.p1_played), 0) self.assertEqual(len(self.slot.p2_played), 0) # Test when hand does not have any cards self.hand_1.remove_card(self.c1) self.hand_1.remove_card(self.c2) self.assertEqual(len(self.hand_1.cards), 0) try: self.slot.play_card(self.c1, self.hand_1) self.fail('ValueError not thrown') except ValueError: pass self.assertEqual(len(self.hand_1.cards), 0) self.assertEqual(len(self.hand_2.cards), 2) self.assertEqual(len(self.slot.p1_played), 0) self.assertEqual(len(self.slot.p2_played), 0) # Test both sides not full, so winner indeterminate def test_check_winner_neither_slots_full(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.RED, 4) h1.add_card(c1) h1.add_card(c2) h2.add_card(c4) h2.add_card(c5) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.assertEqual(self.slot.check_winner(None), 0) # Test full slots, p1 has wedge and p2 has host def test_check_winner_full_slot_wedge(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) c3 = Card(Colour.RED, 3) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.RED, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 1) # Test full slots, p2 has higher wedge than p1 def test_check_winner_full_slot_both_wedge(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) c3 = Card(Colour.RED, 3) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.GREEN, 9) c6 = Card(Colour.GREEN, 8) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 2) # Test full slots, tie def test_check_winner_full_slot_tie(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) c3 = Card(Colour.RED, 3) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.GREEN, 2) c6 = Card(Colour.GREEN, 3) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 0) # Test full slots, p1 has phalanx and p2 has host def test_check_winner_full_slot_phalanx(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 1) c3 = Card(Colour.BLUE, 1) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.RED, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 1) # Test full slots, p2 has better phalanx than p1 def test_check_winner_full_slot_both_phalanx(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 1) c3 = Card(Colour.BLUE, 1) c4 = Card(Colour.GREEN, 5) c5 = Card(Colour.RED, 5) c6 = Card(Colour.PURPLE, 5) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 2) # Test full slots, p1 has battalion order and p2 has host def test_check_winner_full_slot_border(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 5) c3 = Card(Colour.RED, 9) c4 = Card(Colour.GREEN, 10) c5 = Card(Colour.RED, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 1) # Test full slots, p2 has better battalion order than p1 def test_check_winner_full_slot_both_border(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 4) c3 = Card(Colour.RED, 2) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.GREEN, 4) c6 = Card(Colour.GREEN, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 2) # Test full slots, p1 has skirmish line and p2 has host def test_check_winner_full_slot_skirmish(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) c3 = Card(Colour.BLUE, 3) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 1) # Test full slots, p2 has better skirmish than p1 def test_check_winner_full_slot_both_skirmish(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) c3 = Card(Colour.BLUE, 3) c4 = Card(Colour.GREEN, 3) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 5) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 2) # Test full slots, p1 has better host than p2 def test_check_winner_full_slot_host(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 10) c3 = Card(Colour.BLUE, 9) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) self.slot.play_card(c1, h1) self.slot.play_card(c2, h1) self.slot.play_card(c3, h1) self.slot.play_card(c4, h2) self.slot.play_card(c5, h2) self.slot.play_card(c6, h2) self.assertEqual(self.slot.check_winner(None), 1) def test_get_values_to_complete_consecutive_first_is_1(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) cards = [c1, c2] values = self.slot.get_values_to_complete_consecutive(cards) self.assertTrue(3 in values) self.assertEqual(len(values), 1) def test_get_values_to_complete_consecutive_last_is_10(self): c1 = Card(Colour.RED, 9) c2 = Card(Colour.RED, 10) cards = [c1, c2] values = self.slot.get_values_to_complete_consecutive(cards) self.assertTrue(8 in values) self.assertEqual(len(values), 1) def test_get_values_to_complete_consecutive_two_choices(self): c1 = Card(Colour.RED, 5) c2 = Card(Colour.RED, 6) cards = [c1, c2] values = self.slot.get_values_to_complete_consecutive(cards) self.assertTrue(4 in values) self.assertTrue(7 in values) self.assertEqual(len(values), 2) def test_get_values_to_complete_consecutive_missing_middle(self): c1 = Card(Colour.RED, 5) c2 = Card(Colour.RED, 7) cards = [c1, c2] values = self.slot.get_values_to_complete_consecutive(cards) self.assertTrue(6 in values) self.assertEqual(len(values), 1) def test_is_this_card_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) c3 = Card(Colour.BLUE, 3) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.PURPLE, 7) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c4, h2) slot_2.play_card(c2, h1) slot_2.play_card(c5, h2) slots = [slot_1, slot_2] self.assertTrue(self.slot.is_this_card_out(1, Colour.RED, slots)) self.assertTrue(self.slot.is_this_card_out(1, Colour.GREEN, slots)) self.assertFalse(self.slot.is_this_card_out(3, Colour.BLUE, slots)) self.assertFalse(self.slot.is_this_card_out(7, Colour.PURPLE, slots)) def test_are_all_cards_of_this_val_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.ORANGE, 1) c3 = Card(Colour.YELLOW, 1) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 1) c6 = Card(Colour.PURPLE, 1) c7 = Card(Colour.PURPLE, 2) c8 = Card(Colour.GREEN, 2) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) h1.add_card(c7) h1.add_card(c8) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slot_1.play_card(c6, h2) slot_2.play_card(c7, h1) slot_2.play_card(c8, h1) slots = [slot_1, slot_2] self.assertTrue(self.slot.are_all_cards_of_this_val_out(1, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(2, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(7, slots)) def test_are_all_cards_of_this_colour_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.BLUE, 2) c3 = Card(Colour.RED, 2) c4 = Card(Colour.RED, 3) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.RED, 4) c7 = Card(Colour.RED, 5) c8 = Card(Colour.RED, 6) c9 = Card(Colour.RED, 7) c10 = Card(Colour.RED, 8) c11 = Card(Colour.RED, 9) c12 = Card(Colour.RED, 10) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) h1.add_card(c7) h1.add_card(c8) h1.add_card(c9) h2.add_card(c10) h2.add_card(c11) h2.add_card(c12) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slot_1.play_card(c6, h2) slot_2.play_card(c7, h1) slot_2.play_card(c8, h1) slot_2.play_card(c9, h1) slot_2.play_card(c10, h2) slot_2.play_card(c11, h2) slot_2.play_card(c12, h2) slots = [slot_1, slot_2] self.assertTrue(self.slot.are_all_cards_of_this_colour_out(Colour.RED, slots)) self.assertFalse(self.slot.are_all_cards_of_this_colour_out(Colour.BLUE, slots)) self.assertFalse(self.slot.are_all_cards_of_this_colour_out(Colour.GREEN, slots)) def test_get__highest_pos_formation_score_two_cards_wedge(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 2) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 5) def test_get__highest_pos_formation_score_two_cards_wedge_middle_missing(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 3) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 5) def test_get_highest_pos_formation_score_two_cards_phalanx(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 1) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 4) def test_get_highest_pos_formation_score_two_cards_border(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.RED, 5) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 3) def test_get_highest_pos_formation_score_two_cards_skirmish(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 2) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 2) def test_get_highest_pos_formation_score_two_cards_host(self): c1 = Card(Colour.RED, 1) c2 = Card(Colour.GREEN, 8) cards = [c1, c2] self.assertEqual(self.slot.get_highest_pos_formation_score(cards), 1) def test_get_highest_card_with_colour_not_played(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.BLUE, 9) c3 = Card(Colour.RED, 8) c4 = Card(Colour.RED, 6) c5 = Card(Colour.BLUE, 10) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slots = [slot_1, slot_2] self.assertEqual(self.slot.get_highest_card_with_colour_not_played(Colour.RED, slots), 10) self.assertEqual(self.slot.get_highest_card_with_colour_not_played(Colour.BLUE, slots), 8)
def test_are_all_cards_of_this_colour_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.BLUE, 2) c3 = Card(Colour.RED, 2) c4 = Card(Colour.RED, 3) c5 = Card(Colour.BLUE, 4) c6 = Card(Colour.RED, 4) c7 = Card(Colour.RED, 5) c8 = Card(Colour.RED, 6) c9 = Card(Colour.RED, 7) c10 = Card(Colour.RED, 8) c11 = Card(Colour.RED, 9) c12 = Card(Colour.RED, 10) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) h1.add_card(c7) h1.add_card(c8) h1.add_card(c9) h2.add_card(c10) h2.add_card(c11) h2.add_card(c12) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slot_1.play_card(c6, h2) slot_2.play_card(c7, h1) slot_2.play_card(c8, h1) slot_2.play_card(c9, h1) slot_2.play_card(c10, h2) slot_2.play_card(c11, h2) slot_2.play_card(c12, h2) slots = [slot_1, slot_2] self.assertTrue(self.slot.are_all_cards_of_this_colour_out(Colour.RED, slots)) self.assertFalse(self.slot.are_all_cards_of_this_colour_out(Colour.BLUE, slots)) self.assertFalse(self.slot.are_all_cards_of_this_colour_out(Colour.GREEN, slots))
def test_are_all_cards_of_this_val_out(self): h1 = Hand(1) h2 = Hand(2) c1 = Card(Colour.RED, 1) c2 = Card(Colour.ORANGE, 1) c3 = Card(Colour.YELLOW, 1) c4 = Card(Colour.GREEN, 1) c5 = Card(Colour.BLUE, 1) c6 = Card(Colour.PURPLE, 1) c7 = Card(Colour.PURPLE, 2) c8 = Card(Colour.GREEN, 2) h1.add_card(c1) h1.add_card(c2) h1.add_card(c3) h2.add_card(c4) h2.add_card(c5) h2.add_card(c6) h1.add_card(c7) h1.add_card(c8) slot_1 = Slot() slot_2 = Slot() slot_1.play_card(c1, h1) slot_1.play_card(c2, h1) slot_1.play_card(c3, h1) slot_1.play_card(c4, h2) slot_1.play_card(c5, h2) slot_1.play_card(c6, h2) slot_2.play_card(c7, h1) slot_2.play_card(c8, h1) slots = [slot_1, slot_2] self.assertTrue(self.slot.are_all_cards_of_this_val_out(1, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(2, slots)) self.assertFalse(self.slot.are_all_cards_of_this_val_out(7, slots))