Question:
a. Create a Tic Tac Toe game. In this game, two players alternate placing Xs and Os into a grid until one player has three matching symbols in a row, horizontally, vertically, or diagonally. Create a game in which the user is presented with a three-by-three grid containing the digits 1 through 9. When the user chooses a position by typing a number, place an X in the appropriate spot. Generate a random number for the position where the computer will place an O. Do not allow the player or the computer to place a symbol where one has already been placed. Figure 9-29 shows the first four windows in a typical game. When either the player or computer has three symbols in a row, declare a winner; if all positions have been exhausted and no one has three symbols in a row, declare a tie. Save the game as TicTacToe.java.
b. In the TicTacToe application, the computers selection is chosen randomly. Improve the game so that when the computer has two Os in any row, column, or diagonal, it selects the winning position for its next move rather than selecting a position randomly. Save the improved game as TicTacToe2.java.
Transcribed Image Text:
Input Enter the position where you want to piay Message 123 45 6 х Welcome to Tic Tac Toe. You will have X and the computer will have O 78 0 ок Cancel Ок Message Message Your move is recorded; now the computer will play The computer has played 123 123 456 4 56 X 8 9 хо9 Ок ок