def test_straight(self): hand = CardSet( Counter({ Card.THREE: 2, Card.FOUR: 1, Card.FIVE: 1, Card.SIX: 1, Card.SEVEN: 1, Card.EIGHT: 1, Card.NINE: 2 })) self.assertTrue(len(hand._get_straights()) == 6) hand = CardSet( Counter({ Card.THREE: 2, Card.FOUR: 2, Card.FIVE: 3, Card.SIX: 2, Card.SEVEN: 2, Card.EIGHT: 2, Card.NINE: 2 })) self.assertTrue(len(hand._get_straights()) == 21) hand = CardSet( Counter({ Card.SEVEN: 1, Card.NINE: 2, Card.TEN: 1, Card.JACK: 2, Card.QUEEN: 2, Card.KING: 2 })) self.assertTrue(len(hand._get_straights()) == 2) self.assertTrue(len(hand._get_straights()[0].cards) == 5)
def test_joker_kickers(self): hand = CardSet( Counter({ Card.THREE: 3, Card.FOUR: 3, Card.LITTLE_JOKER: 1, Card.BIG_JOKER: 1 })) self.assertEqual(len(hand.get_all_moves()), 17)
def test_chains2(self): hand = CardSet( Counter({ Card.THREE: 2, Card.FOUR: 3, Card.FIVE: 2, Card.SIX: 2 })) self.assertTrue( len(hand._get_straights_from(Card.THREE, num_cards=2)) == 2)
def test_complex(self): hand = CardSet( Counter({ Card.THREE: 3, Card.FOUR: 1, Card.FIVE: 2, Card.SIX: 1, Card.SEVEN: 1, Card.LITTLE_JOKER: 1, Card.BIG_JOKER: 1 })) self.assertTrue(len(hand.get_all_moves()) == 19)
def get_legal_moves(self): if self.is_betting_complete(): hand = CardSet(Counter(self.get_hand(self.get_current_position()))) all_moves = hand.get_all_moves() # you can play anything if you have control if self._control_position == self.get_current_position(): return all_moves # otherwise you have to play moves that beat it, or pass return [move for move in all_moves if move.beats(self.get_last_played())] + [None] else: return [BetMove(x) for x in range(LandlordGame.MAX_BET + 1)]
def test_airplane(self): hand = CardSet(Counter({Card.JACK: 3, Card.QUEEN: 2, Card.KING: 3})) self.assertTrue(len(hand._get_airplanes()) == 0) hand = CardSet( Counter({ Card.JACK: 3, Card.QUEEN: 3, Card.THREE: 2, Card.TWO: 2 })) self.assertTrue(len(hand._get_airplanes()) == 2)
def parse_input(cls, input_string, bet_phase=False): if bet_phase: try: bet_amount = int(input_string) return BetMove(bet_amount) except Exception: pass cards = HumanPlayer.parse_input_for_cardset(input_string) if cards is None: return None all_possible_moves = CardSet(Counter(cards)).get_all_moves() for move in all_possible_moves: if move.get_cards() == Counter(cards): return move raise InvalidMoveError
def test_quads(self): hand = CardSet(Counter({Card.JACK: 4, Card.QUEEN: 2, Card.KING: 3})) self.assertTrue(len(hand._get_quad_moves()) == 3)
def test_simple_hand_2(self): hand = CardSet(Counter({Card.JACK: 3, Card.QUEEN: 2, Card.KING: 3})) self.assertTrue(len(hand._get_single_moves()) == 3) self.assertTrue(len(hand._get_pair_moves()) == 3) self.assertTrue(len(hand._get_triple_moves()) == 10)
def test_simple_hand(self): hand = CardSet(Counter({Card.JACK: 3, Card.QUEEN: 1})) self.assertTrue(len(hand._get_single_moves()) == 2) self.assertTrue(len(hand._get_pair_moves()) == 1) self.assertTrue(len(hand._get_triple_moves()) == 2)