TicTacToe game in IntelliJ without using an array?

Answered

Write a program to maintain a Tic Tac Toe game board. Here, 2 Users will alternately enter their next moves. You are required to accept the move by number 1 to 9, mark the position with the user's index (1 or 2), and print out the board condition after each input. The game ends when a user enter 0 to exit, or when the board is full make sure your program conforms to the following requirements and steps:

A. Initialize the 3*3 board with 9 integers and with all 0 values. The 9 variables represent the board like: 1 2 3 4 5 6 7 8 9

B. A scanner to receive user input positions. A loop to continue the game terms.

C. Receive the first client’s next move. And alter client in the next loop if the move is valid (first client-> second client-> first client-> second client-> …). Clients can enter “0” to end the game.

D. Determine if the move is valid. A valid move must between 1~9, and has nothing on that position (target move position == 0, which is the initial value).

E. If it’s a valid move, change the mark on target position from 0 to client’s index (change 0 to 1 if by the first client, change 0 to 2 if by the second client). Alter client and print out the board.

F. If it’s an invalid move choice, stay on current client and ask for another try.

G. Check if the board is full. If not, and if the next enter is not 0, go on the loop.

h. At current stage, we only require you to follow the changes on the 3*3 board. You can ignore checking if one side wins, or other Tic Tac Toe rules.

I. You can use methods whenever you want, as long as the code works. But you are not allowed to use array. (You can use “switch” to relate the user input move and your own position variables.)

J. Match the output format in the samples as much as you can.

If nothing else, how to begin this would be nice because I cannot use an array. I’ve been stuck on this for a minute.

1 comment
Comment actions Permalink

Hello, this forum is for IntelliJ IDEA product questions only. Please discuss programming-related questions at https://stackoverflow.com .

Thank you!

0

Please sign in to leave a comment.