Asks the player for their move, and returns 'H' for hit, 'S' for stand, and 'D' for double down.
(playerHand, money)
| 216 | |
| 217 | |
| 218 | def getMove(playerHand, money): |
| 219 | """Asks the player for their move, and returns 'H' for hit, 'S' for |
| 220 | stand, and 'D' for double down.""" |
| 221 | while True: # Keep looping until the player enters a correct move. |
| 222 | # Determine what moves the player can make: |
| 223 | moves = ['(H)it', '(S)tand'] |
| 224 | |
| 225 | # The player can double down on their first move, which we can |
| 226 | # tell because they'll have exactly two cards: |
| 227 | if len(playerHand) == 2 and money > 0: |
| 228 | moves.append('(D)ouble down') |
| 229 | |
| 230 | # Get the player's move: |
| 231 | movePrompt = ', '.join(moves) + '> ' |
| 232 | move = input(movePrompt).upper() |
| 233 | if move in ('H', 'S'): |
| 234 | return move # Player has entered a valid move. |
| 235 | if move == 'D' and '(D)ouble down' in moves: |
| 236 | return move # Player has entered a valid move. |
| 237 | |
| 238 | |
| 239 | # If the program is run (instead of imported), run the game: |