def _setup_equal_scores_state() -> BlackjackState:
     """Both dealer and player have the same score in this state."""
     initial_state = BlackjackState.new_initial_state(
         player_hand=Hand(cards_list=[Card("10"), Card("10")]),
         dealer_hand=Hand(cards_list=[Card("10")]))
     equal_scores_state = Transition(initial_state).dealer().draw(
         Card("10"))
     return equal_scores_state
 def _setup_bust_player_state() -> BlackjackState:
     """In this state the player is bust while the dealer is not."""
     initial_state = BlackjackState.new_initial_state(
         player_hand=Hand(cards_list=[Card("K"), Card("K")]),
         dealer_hand=Hand(cards_list=[Card("K")]),
     )
     bust_player_state = Transition(initial_state).player().draw(Card("K"))
     return bust_player_state
    def test_choose_action_draw_if_lower_score_than_opponent_and_under_21(
            self):
        equal_scores_state = self._setup_equal_scores_state()
        winning_state_for_player = \
            Transition(equal_scores_state).player().draw(Card("A"))
        expected_dealer_action = BlackjackAction.DRAW

        agent_choice = self.DEALER.choose_action(winning_state_for_player)
        self.assertEqual(expected_dealer_action, agent_choice.action_chosen)
    def test_choose_action_pass_if_score_greater_than_player(self):
        equal_scores_state = self._setup_equal_scores_state()
        winning_state_for_dealer = \
            Transition(equal_scores_state).dealer().draw(Card("A"))

        expected_dealer_action = BlackjackAction.PASS

        agent_choice = self.DEALER.choose_action(winning_state_for_dealer)
        self.assertEqual(expected_dealer_action, agent_choice.action_chosen)
Exemplo n.º 5
0
    def test_target_draws_card_dealer_gets_new_card(self):
        initial_state = self._setup_initial_state()
        new_card_name = "A"
        new_state = Transition(initial_state).dealer().draw(
            Card(new_card_name))

        self.assertFalse(new_card_name in initial_state.dealer_hand.card_names)
        self.assertTrue(new_card_name in new_state.dealer_hand.card_names)
        self.assertFalse(new_card_name in new_state.player_hand.card_names)
        self.assertTrue(
            self._states_are_equal_except_for_hands(initial_state, new_state))
 def _init_max_score_state() -> BlackjackState:
     return BlackjackState.new_initial_state(player_hand=Hand(
         [Card("A"), Card("K")]),
                                             dealer_hand=Hand([Card("2")]))
 def draw_card(self):
     """Returns one of the possible 13 poker cards at random."""
     card_name = random.sample(self._possible_cards_names, 1)[0]  # unpack
     return Card(card_name)
Exemplo n.º 8
0
    def test_target_draws_card_old_state_unchanged(self):
        initial_state = self._setup_initial_state()
        unchanged_initial_state = self._setup_initial_state()
        Transition(initial_state).dealer().draw(Card("10"))

        self.assertEqual(initial_state, unchanged_initial_state)
Exemplo n.º 9
0
 def _setup_initial_state() -> BlackjackState:
     player_hand = Hand([Card("10"), Card("10")])
     dealer_hand = Hand([Card("10")])
     return BlackjackState.new_initial_state(player_hand, dealer_hand)