()
| 10 | |
| 11 | |
| 12 | def main(): |
| 13 | print('Welcome to Tic-Tac-Toe!') |
| 14 | # (!) Try replacing TTTBoard() with MiniTTTBoard() or HintTTTBoard() |
| 15 | gameBoard = TTTBoard() # Create a TTT board object. |
| 16 | currentPlayer, nextPlayer = X, O # X goes first, O goes next. |
| 17 | |
| 18 | while True: # Main game loop. |
| 19 | # Display the board on the screen: |
| 20 | print(gameBoard.getBoardStr()) |
| 21 | |
| 22 | # Keep asking the player until they enter a number 1-9: |
| 23 | move = None |
| 24 | while not gameBoard.isValidSpace(move): |
| 25 | print('What is {}\'s move? (1-9)'.format(currentPlayer)) |
| 26 | move = input('> ') |
| 27 | gameBoard.updateBoard(move, currentPlayer) # Make the move. |
| 28 | |
| 29 | # Check if the game is over: |
| 30 | if gameBoard.isWinner(currentPlayer): # Check for a winner. |
| 31 | print(gameBoard.getBoardStr()) |
| 32 | print(currentPlayer + ' has won the game!') |
| 33 | break |
| 34 | elif gameBoard.isBoardFull(): # Next check for a tie. |
| 35 | print(gameBoard.getBoardStr()) |
| 36 | print('The game is a tie!') |
| 37 | break |
| 38 | # Switch turns to the next player: |
| 39 | currentPlayer, nextPlayer = nextPlayer, currentPlayer |
| 40 | print('Thanks for playing!') |
| 41 | |
| 42 | |
| 43 | class TTTBoard: |
no test coverage detected