Question: Use java to write code, you can answer half of them or 1/3 of them and I will post new questions and you can answer
Use java to write code, you can answer half of them or 1/3 of them and I will post new questions and you can answer the rest of them.
This is a board game.
Class BoardGame:
This class implements all the support methods needed by the algorithm that plays the board game. For details on this algorithm see the additional documentation posted on the courses website. The constructor for this class must be as follows :
public BoardGame (int board size, int empty positions, int max levels)
The first parameter specifies the size of the gameboard, the second one is the number of positions on the board that must remain empty, and the third one specifies the playing quality of the program (the higher this value is the better the program will play, but the slower it will be; when you test your program use values between 3 and 5 so the program plays OK and it is not too slow).
This class must have an instance variable called gameBoard of type char[][] to store the gameboard. This variable is initialized inside the above constructor method so that every entry of gameBoard stores a g. As the game is played, every entry of gameBoard will store one of the characters b, o, or g. This class must also implement the following public methods.
public HashDictionary makeDictionary(): returns an empty HashDictionary of the size that you have selected.
public int isRepeatedConfig(HashDictionary dict): This method first represents the content of gameBoard as a string as described above; then it checks whether the string representing the gameBoard is in dict: If it is, this method returns its associated score; otherwise it returns the value -1
public void putConfig(HashDictionary dict, int score): This method first represents the content of gameBoard as a string as described above; then it inserts this string and its score in dict.
public void savePlay(int row, int col, char symbol): This method stores symbol in gameBoard[row][col].
public boolean positionIsEmpty (int row, int col): This method returns true if gameBoard[row][col] is g; otherwise it returns false.
public boolean tileOfComputer (int row, int col): This method returns true if gameBoard[row][col] is o; otherwise it returns false
public boolean tileOfHuman (int row, int col): Returns true if gameBoard[row][col] is b; otherwise it returns false
public boolean wins (char symbol): Returns true if there are n adjacent tiles of type symbol in the same row, column, or diagonal of gameBoard, where n is the size of the gameboard.
public boolean isDraw(char symbol, int empty positions): Returns true if the game configuration corresponding to gameBoard is a draw assuming that the player that will perform the next move uses tiles of the type specified by symbol. The second parameter is the number of positions of the gameboard that must remain empty.
Remember that a game is a draw if no player has won and either:
empty positions = 0 and there are no empty positions left on the game board, or
empty positions > 0 and none of the empty positions on the gameboard has a tile of the type specified by symbol adjacent to it.
public int evalBoard(char symbol, int empty positions): Returns one of the following values:
3, if the computer has won, i.e. there are n adjacent os in the same row, column, or diagonal of gameBoard.
0, if the human player has won, i.e. there are n adjacent bs in the same row, column, or diagonal of gameBoard.
2, if the game is a draw when the player that needs to make the next move uses tiles of the type specified by symbol. The second parameter is the number of positions of the gameboard that must remain empty.
1, if the game is still undecided, i.e. no player has won and the game is not a draw.
You can implement more methods in this class, if you want, but they must be declared as private.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
