Question
Please ,I need some help with this java project.Tic-Tac-Toe game. Naming requirements : .?You should have a class named Board in the default package. This
Please ,I need some help with this java project.Tic-Tac-Toe game.
Naming requirements: .?You should have a class named Board in the default package. This class is where you store a Tic Tac Toe board as an array of 9 values.?You should have a class named Game in the default package. This class is where the logic of the game will be. This is the class that will contain a Dictionary for storing Tic Tac Toe boards.?You should have a class named GameInteraction in the default package. This is where the user interaction for the game should be. This is where the main() method should be.
Project Goal:Consider all the possible boards in a game of Tic Tac Toe. For each board position, there is a "best move" (or multiple moves that are tied for best). See programming project 6 in chapter 19 (page 573).Write a program that plays a game of Tic Tac Toe in which you use a dictionary to calculate and store all possible board positions, and the best move associated with that position.
Specifics:?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. ? To store the board positions and associated best moves, you must use one of the Dictionary implementations provided in the file DictionaryImplementations.zip. It is your choice which one you use. ? To interact with the user, you may use either a console-based or GUI-based game. Only choose GUI if you are very comfortable working with Java GUIs. If you use a console-based game, allow the human to always go first and always show the board before each human move. The human should enter her move as a single digit number in the range 0 through 8, where 0, 1, 2 are the top three cells, 3, 4, 5 are the middle three, and 6, 7, 8 are the top three. ? You get to decide what methods and constructors you want for the Game class. However, there is one public method that the Game class must have, in order to help me with grading your work: public int getBestMove(String board) { } This method should take a board in the form of a string, and return the best move as an int in the range 0 through 8. This method should not need much code. It should really just rely on your Dictionary to retrieve the correct move for a given board (first using the string to create a Board object and use it as a key).
It must be X's move. The best move is to place the X in the lower-right corner. If we number the squares 0 through 8 (by beginning at the top-left and going left-to-right, top-to-bottom), we would represent this board with the string "X--XXOOO-". Thus, getBestMove("X--XXOOO-") should return 8 indicating that the best move is the lower-right corner. Similarly,for the board below, getBestMove("--OXXO--X") should return 0, because the best move for O right now is in the upper-left corner, blocking X from winning.
Just to re-emphasize: the getBestMove() is essential for assisting your instructor in testing your code. It does not mean you must store boards in the dictionary as strings. You could save this method for last if you want because you do not need it for other parts of the program to work.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started