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
Exemple #3
0
 def get_initial_state(self) -> BlackjackState:
     """
     Returns an initial state formed by drawing two cards from the
     deck for the player and one card for the dealer.
     :return: The initial state.
     """
     initial_player_hand = Hand([self._shuffled_deck.draw_card(),
                                 self._shuffled_deck.draw_card()])
     dealer_hand = Hand([self._shuffled_deck.draw_card()])
     return BlackjackState.new_initial_state(
         player_hand=initial_player_hand,
         dealer_hand=dealer_hand)
Exemple #4
0
 def _build_new_state(self) -> BlackjackState:
     """
     Builds the new state and sets default values for current_bet and
     action_space.
     """
     # TODO: Action space changes while transitioning.
     return BlackjackState(player_hand=self._player_hand,
                           dealer_hand=self._dealer_hand,
                           current_bet=self._from_state.current_bet,
                           player_has_passed=self._player_has_passed,
                           dealer_has_passed=self._dealer_has_passed,
                           action_space=self._from_state.action_space)
Exemple #5
0
    def _calculate_reward(state: BlackjackState) -> int:
        if not state.is_final():
            return 0

        player_score = state.player_hand.score
        dealer_score = state.dealer_hand.score

        if player_score > 21:
            return -state.current_bet
        elif dealer_score > 21:
            return state.current_bet
        else:
            player_wins = dealer_score < player_score
            return state.current_bet if player_wins else -state.current_bet
 def _init_max_score_state() -> BlackjackState:
     return BlackjackState.new_initial_state(player_hand=Hand(
         [Card("A"), Card("K")]),
                                             dealer_hand=Hand([Card("2")]))
Exemple #7
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)