Question: Help with creating Chess game in Java In this assignment, you are asked to write a Java program that stores a chessboard in a 2D

Help with creating Chess game in Java Help with creating Chess game in Java In this assignment, you areasked to write a Java program that stores a chessboard in a2D array. Your program must make necessary changes on the array aftereach move or capture of the two players of the game. 1Array Format A chessboard can be represented by an 8 x 8

In this assignment, you are asked to write a Java program that stores a chessboard in a 2D array. Your program must make necessary changes on the array after each move or capture of the two players of the game. 1 Array Format A chessboard can be represented by an 8 x 8 table of objects instantiated from Piece class (or its subclasses). Every cell in this array is corresponding to one of the 64 squares of the board and determines the occupant of the square. As seen in Figure 1, the table row with 6 N h Figure 1: Row and column labels in a chessboard. index 0 is labeled with "g" and the table row with index 7 is labeled with 1. Also, the table column with index 0 is labeled with "a", while the table column with index 7 is labeled with "h". The Piece class has two boolean instance fields "white" (to store the color of piece) and "dummy" (to determine whether the piece is dummy and its containing square is empty) and is defined in the following way: public class Piece { protected boolean white; private boolean dummy; public Piece(boolean white, boolean dummy) { this.white = white; this.dummy = dummy: } public String toString() { return (white?"W Pce": "B Pce"); } public boolean isEmpty() { return dummy; } } If the dummy field of a table cell is zero, it means that the square corresponding to that cell is empty. If its white field is true, it means that a white piece occupies the corresponding square; while a false white field means that the occupying piece color is black. The dynamic type of the cell specifies type of piece occupying the corresponding square. For example, the following three subclasses of Piece class represent the Pawn piece, Knight piece, and the Empty square: public class Pawn extends Piece { public Pawn(boolean white) { super(white,false); } public String toString() { return (white?"W":"B")+"Pwn"; } } public class Knight extends Piece { public Knight(boolean white) { super(white,false); } public String toString() { return (white?"W":"B")+"Knt"; } } public class Empty extends Piece { public Empty() { super(true,true); } public String toString() { return" "; } } 2 Initial Setting of Pieces on the Board The program starts by initializing the table in the following fashion: B Rok B Knt B Bsp B Qun B Kng B Bsp B Pwn B Knt B Pwn B Rok B Pwn B Pwn B Pwn B Pwn B Pwn B Pwn W Pwn W Rok W PwnW Pwn W Knt W Bsp W Pwn W Pwn W Pwn W Pwn W Pwn W Qun | W KngW Bsp W Knt W Rok which corresponds to the following chessboard setup: a h Il t - i iiiiiii 1 2 DEE M 22 3 Program Commands Your program must start by inputting the players name and elo rating (see the incomplete program available on Canvas for more details). Then, it should be responsive to the following commands entered by user via standard input stream: my cao Q2B1: moves the piece in cell with label Qo, to cell with label 13, where al and ay can be letters from a to h; while B, and B, can be integers from 1 to 8. cp QoBo B, captures the piece in cell with label & B, with the piece in cell coBo where do and ai can be letters from a to h; while Bo and B, can be integers from 1 to 8. print: prints out the current status of the game on the screen in the form of a table like this (the ranks 1,2, ..., 8 and files A, B, ..., H must be printed as well): 8 Player2's Name, elo: Player2's rating B Rok B Knt B Bsp B Qun B Kng B Bsp B Knt B Rok 7 B Pwn B Pwn B Pwn B Pwn B Pwn B Pwn B Pwn B Pwn 6 5 4 3 2 W Pwn W Pwn W Pwn W Pwn W Pwn W Pwn W Pwn W Pwn 1 W Rok w Knt W Bspw Qun W Kng W Bsp W Knt W Rok A B D E F G H Playerl's Name, elo: Player l's rating Figure 2 shows how knight can move on the board and capture pieces with opposite color on the board. Also, it shows the direction in which white pawn moves and captures. The black pawn moves and captures in the opposite direction. In summary, a pawn can move only one cell forward at a time; however, if it is white and is in the second rank (or is black and is in the seventh rank), it has the option of moving two cells forward as well if there is no piece on its way. Figure 2: Movement and capture of knight (left), movement (middle) and capture of pawn (right) on chessboard. Bishop moves diagonally and rook moves vertically or horizontally. Neither bishop nor rook cam jump over any piece while moving from one square to the other. Queen can move like a bishop or rook. King moves one square at a time to one of the four adjacent squares. If a 'cp' or 'my' command tries to make illegal move, your program throws an exception in Game class which must later be handled gracefully. Also, the first move has to be made with a white piece, the second one must be made with a black piece and the following moves/captures must be made with alternating white and black pieces. In other words, your program must be mindful of turn in the game. 1. As the first bonus point, your program must support promotion of white/black pawn to a queen, knight, rook or bishop once it reaches to the eighth/first rank. 2. As the second bonus part, your program must support en passant move (see https://en.wikipedia.org/wiki/En passant for details) 3. As the third bonus part, your program must print a "check message once the king is in check

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!