def test_turn(self): deck = card.Deck() turn_card = self._game.turn(deck, self._p1, self._board) self.assertTrue(turn_card is not None) deck = card.Deck([card.Card('11', 'H')]) turn_card = self._game.turn(deck, self._p1, self._board) self.assertEqual(card.Card('11', 'H'), turn_card) self.assertEqual(2, self._board.player_score(self._p1))
def test_decide_dealer(self): deck = card.Deck() deck.shuffle() for _ in range(100): dealer, non_dealer, dealer_card, non_dealer_card = self._game.decide_dealer(deck) self.assertTrue(dealer_card < non_dealer_card) self.assertEqual(52, deck.cards_remaining())
def test_discard(self): deck = card.Deck() hands = deck.deal(2, 6) dealer_hand, non_dealer_hand, box = self._game.discard(self._p1, self._p2, hands[0], hands[1]) self.assertEqual(4, len(dealer_hand)) self.assertEqual(4, len(non_dealer_hand)) self.assertEqual(4, len(box)) self.assertTrue(all([x not in dealer_hand and x not in non_dealer_hand for x in box]))
def run_some_hands(num): deck = card.Deck() for _ in range(num): deck.shuffle() print('*' * 70) hands = deck.deal(1, 4) turn_card = deck.next_card() print(f'Hand: {hands[0]}') print(f'Turn: {turn_card}') print(f' Runs: {runs(hands[0], turn_card)}') print(f' Flushes: {flushes(hands[0], turn_card)}') print(f' 15s: {fifteens(hands[0], turn_card)}') print(f' Pairs: {pairs(hands[0], turn_card)}') print(f' Nob : {nob(hands[0], turn_card)}') print(f' Score: {score_hand(hands[0], turn_card)}') deck.return_cards(*hands) deck.return_cards([turn_card]) print(f'Card remaining: {deck.cards_remaining()}')
def _multi_process(self, target_score, num_attempts): with multiprocessing.Pool() as pool: return pool.starmap(self.attempts_for_score, [(card.Deck(), target_score)] * num_attempts)
def _multi_threaded(self, target_score, num_attempts): with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: return list( executor.map(self.attempts_for_score, [card.Deck() for _ in range(num_attempts)], [target_score] * num_attempts))
def _single_thread(self, target_score, num_attempts): deck = card.Deck() return [ self.attempts_for_score(deck, target_score) for _ in range(num_attempts) ]