Tic-tac-toe is a game for two players that is played on a three-by-three arrangement of squares that we will call the game board. Players alternately claim a square by marking it in a distinctive way,...


Tic-tac-toe is a game for two players that is played on a three-by-three arrangement of squares that we will call the game board. Players alternately claim a square by marking it in a distinctive way, traditionally with Xs and Os. The first player to claim three squares that are adjacent either horizontally, vertically, or diagonally wins. Tie games, which have no winner, are possible. Define a Java class that represents the game board of tic-tac-toe. This class is responsible for displaying the board, reporting its status, and marking the squares with Xs and Os, all under control of its client.


Number the squares on the board as follows:


123


456


789


The players use these numbers to indicate their moves.


Write a program that uses your class to play tic-tac-toe. Display the empty board with its squares numbered, as just shown. Alternate turns between player X and player O, marking each move on the board. For example, if player X makes the first move by choosing square 5, if the move is legal, display the board as


123


4X6


789


and tell player O to make the next move. When the game ends, announce the outcome.


You can allow either two human players or one player who plays against your program. In the latter case, you must develop a strategy for choosing squares. This strategy can be as simple or complex as you choose. You can use a strategy that never loses or one that chooses squares randomly.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here