Question: Please send me the fode ASAP In this exercise, you will write a Java program to play the game of reversi, sometimes known by its







In this exercise, you will write a Java program to play the game of reversi, sometimes known by its trademark name of Othello. Reversi is played on an 8 by 8 board, initially set up as shown in figure 1, with the players moving alternately by placing their own pieces (black or white) on the board, one at a time. Black always goes first. Figure 1: The opening position in a reversi game; black to move. In the following description, a line segment is a sequence of board squares forming a contiguous straight line (horizontal, vertical or diagonal). The rule for a player to place a piece is: The piece must be placed on an empty square such that there is a line segment passing through the piece played, then through one or more pieces of the opposing colour, and ending on a piece of the player's own colour. a When such a line segment exists, we say that the opponent's pieces on that line segment are bracketed. When a piece is played, bracketed pieces change colour according to the following rule: For every a line segment passing through the piece played, then through one or more pieces of the opposing colour, and ending on a piece of the player's own colour, the pieces of opposing colour through which that line segment passes are all changed to pieces of the player's own colour. In Fig. 2, the left-hand picture shows a possible move for white, which brackets three of his opponent's pieces, resulting in the position shown in the right-hand picture. If, and only if, a player cannot move, but his opponent can, he misses a turn. The game ends when neither player can move. (This usually, but not always, happens because all the squares have been occupied.) The winner is the player with the greater number of pieces of his own colour on the board; if there is no such player, the result is a draw. Figure 2: A move by white in a reversi game, and its result. Othello.java. The subsequent call java Othello will invoke a simple program that allows a human player (always black) to play against the computer (always white). The provided graphical interface is rather basic, to put it mildly: clicking on squares which do not represent legal moves just produces an irritating beep; if it is your go, but you have no legal move, then you must click anywhere on the board to allow play to pass to the computer; if you want to play another game, you need to close the window and re-run the program. Also, it's better not to click while the computer is thinking'. Finally, as a special irritation, if the game ends with the computer's move, then you have to click on the board to see the result. Try it out, and play a few games. You will see that the computer plays terribly. In fact, it computes the possible moves in the current position, but just selects the first one! Your task is to modify the program so that it uses minimax search with alpha-beta pruning to play a better game, The main game logic is in the class BoardState. An instance of this class rep- resents a situation in the game. The field colour encodes whose turn it is (1 for white; - 1 for black), while the low-level methods int getContents(int x, int y) and void setContents(int x, int y, int piece) allow retrieval and set- ting on the invididual board squares. Here, a value of 1,-1 or 0 represents pres- ence of, respectively, a white piece, a black piece or no piece at all at the square on rank x and file y. To make things easier for you, we have included the method boolean checkLegal Move (int x, int y), which checks whether it is possible for the current player to move on square (x,y), and void makeLegal Move(int x, int y), which actually executes the move. In fact, to make things really easy, we have provided a method to return the list of all and only those legal moves for the current player. Here, we rely on a class Move to encode the actual moves; it has just two public fields, x and y; so that instances of this class rep- resent moves (legal or illegal) in the obvious way. The method for retrieving the list of legal moves for the current player is ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
