Question: Write a program that allows two players to play a game on a board that looks like this: Here is an example of how you

Write a program that allows two players to play a game on a board that looks like this:

Write a program that allows two players to play a game on

Here is an example of how you would print out the board (game in progress):

 0 1 2 0 x . . 1 . . o 2 x . . 

The numbers along the top and left are for the players to enter the coordinates pertaining to a move. The rules of the game are as follows:

- Each player has three pieces which begin the game off of the board.

- If not all of a player's pieces are on the board, they place one of them on any empty square of the board. The first player cannot take the center as the first move of the game.

- If all a player's pieces are on the board, they move one of them to any empty square that is (orthogonally or diagonally) adjacent.

- If after a move (as in #2 or in #3) a player has all three of their pieces in a row, that player wins.

The program should start with an empty board and alternate asking players for their move.

If a player tries to move to an occupied square, or tries to move from a square where they don't have a piece, or tries to move a piece on the board to a non-adjacent square, then the program should tell them it's an illegal move and ask them to re-enter their move.

You should print the new board state after each player's move. When the game is over, the program should declare the winner.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!