Asks the player which space on which small board to move on. The focusX and focusY values determine which small board the player can move on, but if they are both None the player can freely choose a small board. Returns the (x, y) of the small board the next player plays on.
(player, board, focusX, focusY)
| 166 | |
| 167 | |
| 168 | def askForPlayerMove(player, board, focusX, focusY): |
| 169 | """Asks the player which space on which small board to move on. |
| 170 | The focusX and focusY values determine which small board the player |
| 171 | can move on, but if they are both None the player can freely choose |
| 172 | a small board. Returns the (x, y) of the small board the next player |
| 173 | plays on. |
| 174 | """ |
| 175 | # Check if the player can freely select any small board: |
| 176 | if focusX is None and focusY is None: |
| 177 | # Let the player pick which board they want to move on: |
| 178 | print(player + ': Enter the BOARD you want to move on.') |
| 179 | validBoardsToSelect = [] |
| 180 | for xyTuple, smallBoard in board.items(): |
| 181 | if getWinner(smallBoard) is None: |
| 182 | validBoardsToSelect.append(xyTuple) |
| 183 | selectedBoard = enter1Through9(validBoardsToSelect) |
| 184 | focusX = selectedBoard % 3 |
| 185 | focusY = selectedBoard // 3 |
| 186 | |
| 187 | # Select the space on the focused small board: |
| 188 | smallXDesc = ['left', 'middle', 'right'][focusX] |
| 189 | smallYDesc = ['top', 'middle', 'bottom'][focusY] |
| 190 | print(player, 'moves on the', smallYDesc, smallXDesc, 'board.') |
| 191 | validSpacesToSelect = [] |
| 192 | for xyTuple, tile in board[(focusX, focusY)].items(): |
| 193 | if tile == EMPTY_SPACE: |
| 194 | validSpacesToSelect.append(xyTuple) |
| 195 | selectedSpace = enter1Through9(validSpacesToSelect) |
| 196 | x = selectedSpace % 3 |
| 197 | y = selectedSpace // 3 |
| 198 | |
| 199 | board[(focusX, focusY)][(x, y)] = player |
| 200 | |
| 201 | # Figure out the small board that the next player must move on: |
| 202 | if getWinner(board[x, y]) is None: |
| 203 | return (x, y) |
| 204 | else: |
| 205 | # If the small board has a winner or is tied, the next player |
| 206 | # can move on any small board: |
| 207 | return (None, None) |
| 208 | |
| 209 | |
| 210 | def enter1Through9(validMoves): |
no test coverage detected