def test__is_field_slot_done__invalide(self): self.assertFalse(Gameboard._is_field_slot_done([ Card(0, Suit.Club), Card(0, Suit.Heart), Card(0, Suit.Heart), Card(0, Suit.Heart), ])) self.assertFalse(Gameboard._is_field_slot_done([ Card(10, Suit.Spade), Card(9, Suit.Spade), Card(8, Suit.Diamond), Card(7, Suit.Spade), Card(6, Suit.Heart), ])) self.assertFalse(Gameboard._is_field_slot_done([ Card(10, Suit.Club), Card(9, Suit.Diamond), Card(8, Suit.Spade), Card(7, Suit.Heart), Card(7, Suit.Spade), ])) self.assertFalse(Gameboard._is_field_slot_done([ Card(6, Suit.Club), Card(9, Suit.Diamond), Card(8, Suit.Spade), Card(7, Suit.Heart), Card(10, Suit.Spade), ]))
def test__some_board(self): self.gameboard = Gameboard.from_str("0d10s6s10s0s6d0c9d8d7s9s0d0h7s10d0s6d0c10d0d8s0s7d0h0c8d7d0h0s0h9s9d6s0c0d8c") solution = [Move(before=1, after=0, num_cards=1), Move(before=2, after=4, num_cards=1), Move(before=5, after=6, num_cards=1), Move(before=5, after=8, num_cards=1), Move(before=3, after=5, num_cards=1), Move(before=2, after=3, num_cards=1), Move(before=2, after=3, num_cards=2), Move(before=1, after=2, num_cards=1), Move(before=1, after=3, num_cards=1), Move(before=1, after=5, num_cards=1), Move(before=5, after=1, num_cards=3), Move(before=5, after=0, num_cards=1), Move(before=6, after=5, num_cards=2), Move(before=8, after=7, num_cards=2), Move(before=8, after=4, num_cards=1), Move(before=2, after=8, num_cards=1), Move(before=6, after=2, num_cards=1), Move(before=2, after=0, num_cards=1), Move(before=0, after=2, num_cards=4), Move(before=0, after=2, num_cards=1), Move(before=7, after=0, num_cards=3), Move(before=6, after=7, num_cards=1), Move(before=6, after=8, num_cards=1), Move(before=0, after=6, num_cards=4), Move(before=0, after=4, num_cards=1), Move(before=3, after=0, num_cards=5), Move(before=3, after=7, num_cards=1), Move(before=3, after=5, num_cards=1), Move(before=4, after=3, num_cards=4), Move(before=7, after=4, num_cards=3), Move(before=5, after=7, num_cards=3), Move(before=4, after=5, num_cards=4), Move(before=4, after=8, num_cards=1), Move(before=4, after=5, num_cards=1), Move(before=7, after=4, num_cards=4), Move(before=1, after=7, num_cards=3), Move(before=8, after=1, num_cards=4), Move(before=8, after=6, num_cards=1)] for move in solution: print(move) self.gameboard.execute(move) print(self.gameboard)
def test__get_field_slot_moves__happy_case(self): expected = [Move(before=2, after=5, num_cards=1), Move(before=5, after=3, num_cards=1)] self.assertEqual(expected, self.gameboard.get_field_slot_moves()) self.gameboard = Gameboard.from_str("_|10D,9C,8D,7C,6D|0H,0H,0H|10H,9S,8H,7S,6H|0H|10S,9D,8C,7D,6C|0S,0S,0S,0S|0D,0D,0D,0D|10C,9H,8S,7H,6S|0C,0C,0C,0C") expected = [Move(before=1, after=3, num_cards=3), Move(before=3, after=1, num_cards=1)] self.assertEqual(expected, self.gameboard.get_field_slot_moves())
def _identify_board(self) -> Gameboard: # Identify card locations screenshot = pyautogui.screenshot(region=DETECTION_REGION) card_location_dict = {} for i in range(6, 11): fn = str(i) + 'R' card_location_dict[str(i) + 'D'] = self._find_locations(screenshot, self._get_filepath(fn), 2) fn = str(i) + 'B' card_location_dict[str(i) + 'S'] = self._find_locations(screenshot, self._get_filepath(fn), 2) for suit in Suit: card_location_dict['0' + suit.value] = self._find_locations(screenshot, self._get_filepath(suit.value), 4) # Reverse to get location and its card location_card_list = [] for card, locations in card_location_dict.items(): for location in locations: location_card_list.append((location, card)) assert len(location_card_list) == 36, f"We detected {len(location_card_list)} card locations." # Sort locations from left to right location_card_list.sort(key=lambda t: t[0].left) field_slot_boxes = [location_card_list[i:i+4] for i in range(0, 36, 4)] field_slots = [] for field_slot_box in field_slot_boxes: # Sort locations from top to bottom field_slot_box.sort(key=lambda t: t[0].top) field_slot = [] for dummy, card_str in field_slot_box: field_slot.append(Card.from_str(card_str)) field_slots.append(field_slot) return Gameboard(field_slots=field_slots)
def test__wildcard_slot_moves__valid_moves(self): self.gameboard = Gameboard.from_str("_|10D,9C,8D,7C|0H,0H,0H,6D|10H,9S,8H,7S,6H|0H|10S,9D,8C,7D,6C|0S,0S,0S,0S|0D,0D,0D,0D|10C,9H,8S,7H,6S|0C,0C,0C,0C") expected = [Move(before=1, after=-1, num_cards=1)] self.assertEqual(expected, self.gameboard.get_wildcard_slot_moves())
def setUp(self): self.gameboard = Gameboard.from_str(SOME_INITIAL_GAMEBOARD)