Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You should create a class named Board in java . This class is where you store a Tic Tac Toe board as an array of

You should create a class named Board in java . This class is where you store a Tic Tac Toe board as an array of 9 values

Each board position should be stored as an array (one- or two-dimensional) of 9 values, in the class Board, representing who is occupying each of the 9 squares. Note that a square can be occupied by X or by O, or it can be empty.

? The board position should be the key for the dictionary. The type of array you choose to use is up to you. Choose something that is easy to work with. All you are trying to do is indicate whether each of the 9 squares is X, O, or empty.

? In our game, X will always make the first move.

? The value associated with each board should be the best move that can be made in that position.

Again, the data type you choose to use is up to you. The move could be represented by a row and column, or by a number in the range 0 to 8. Note that you should not have to indicate WHO moves (it should be obvious from the board). It should only have to indicate where to move. If there is more than one best move, it is up to you which of those best moves you choose to return.

? Important: thus, the key-value pair in your dictionary will be a board (key) and a move (value).

? Although there are 3^9 board configurations (in which each square is X, O, or empty), many of

those configurations are not valid in the game of Tic Tac Toe. For example, you cannot have a board in which X appears 7 times and O appears only 1 time. Similarly, you cannot have a board where both players have 3 in a row. You also cannot have a board where O appears 3 times and X appears 2 times (because X goes first). You only need to store valid board positions in your dictionary. It is OK if you want to store ALL positions in the dictionary, but then you should have a

plan for what the "best move" value will be for each of those positions, even in the board is not

valid. You can use recursion to generate all valid boards. You can also use an iterative process.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions