Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear point for the code in Blackjack example #155

Open
eatam opened this issue Feb 6, 2022 · 1 comment
Open

Unclear point for the code in Blackjack example #155

eatam opened this issue Feb 6, 2022 · 1 comment

Comments

@eatam
Copy link

eatam commented Feb 6, 2022

       % If the player's sum is larger than 21, he may hold one or two aces.
        if player_sum > 21:
            assert player_sum == 22
            # last card must be ace
            player_sum -= 10
        else:
            usable_ace_player |= (1 == card)

Question: in the "if" part of the above code, when last card must be ace, why do you not set "usable_ace_player |= (1 == card)"?

@eatam eatam changed the title Unclear code section in Blackjack example it will be better to write more comments for the code section in Blackjack example Feb 7, 2022
@eatam eatam changed the title it will be better to write more comments for the code section in Blackjack example It will be better to write more comments (to make the steps and purposes) for the code in Blackjack example Feb 7, 2022
@eatam eatam changed the title It will be better to write more comments (to make the steps and purposes) for the code in Blackjack example It will be better to write more comments (to make the steps and purposes clearer) for the code in Blackjack example Feb 7, 2022
@eatam eatam closed this as completed Feb 7, 2022
@eatam eatam reopened this Feb 7, 2022
@eatam eatam changed the title It will be better to write more comments (to make the steps and purposes clearer) for the code in Blackjack example Unclear point for the code in Blackjack example Feb 7, 2022
@tommasomarzi
Copy link

tommasomarzi commented Dec 13, 2022

The description of the example 5.1 of the book states:

If the player holds an ace that he could count as 11 without going bust, then the ace is said to be usable.

Therefore, if the condition player_sum > 21 is satisfied, this means that it came out one of the following combinations (otherwise we would be outside of the while loop):

  • ace + ace
  • card_1 + card_2 + ace, where card_1 + card_2 = 11

In both cases, the sum is equal to 22 and the ace (the second one for the first case) is not usable since the player goes bust and therefore it is correct not to set "usable_ace_player |= (1 == card)".
Notice that in the first case the first ace leads to usable_ace_player = True since it is actually usable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants