Asks the player which pit on their side of the board they select to sow seeds from. Returns the uppercase letter label of the selected pit as a string.
(playerTurn, board)
| 109 | |
| 110 | |
| 111 | def askForPlayerMove(playerTurn, board): |
| 112 | """Asks the player which pit on their side of the board they |
| 113 | select to sow seeds from. Returns the uppercase letter label of the |
| 114 | selected pit as a string.""" |
| 115 | |
| 116 | while True: # Keep asking the player until they enter a valid move. |
| 117 | # Ask the player to select a pit on their side: |
| 118 | if playerTurn == '1': |
| 119 | print('Player 1, choose move: A-F (or QUIT)') |
| 120 | elif playerTurn == '2': |
| 121 | print('Player 2, choose move: G-L (or QUIT)') |
| 122 | response = input('> ').upper().strip() |
| 123 | |
| 124 | # Check if the player wants to quit: |
| 125 | if response == 'QUIT': |
| 126 | print('Thanks for playing!') |
| 127 | sys.exit() |
| 128 | |
| 129 | # Make sure it is a valid pit to select: |
| 130 | if (playerTurn == '1' and response not in PLAYER_1_PITS) or ( |
| 131 | playerTurn == '2' and response not in PLAYER_2_PITS |
| 132 | ): |
| 133 | print('Please pick a letter on your side of the board.') |
| 134 | continue # Ask player again for their move. |
| 135 | if board.get(response) == 0: |
| 136 | print('Please pick a non-empty pit.') |
| 137 | continue # Ask player again for their move. |
| 138 | return response |
| 139 | |
| 140 | |
| 141 | def makeMove(board, playerTurn, pit): |