I have a code almost done I just need for you guys to complete it. The specifications of the assignment are the file called "PA2 Spring 2022" and the work I have done is called "PA2 Draft (1).zip". There is also this code provided by the professor that we should have on the program which is the the word file called "code that needs to be added given by prof"
COP-3337 Programming II Programming Assignment 2: FIU Knight Foundation School of Computing & Info. Sciences In this assignment, you are asked to complete a Java program that uses inheritance and polymorphism to implement the Chess game. Your program must keep track of pieces on the chess board from the time that game begins until the time that players make their final moves/captures. The program needs to prevent the players from making illegal moves. 1 Given Classes 1.1 util.Piece This class (which is the superclass of all classes representing Pawn (p), Knight (N), Bishop (B), Rook (R), Queen (Q) and King (K)) contains a protected boolean variable named “white” and is true if the piece color is white and false otherwise. It also has a constructor initializing white, and a method boolean isLegal(Move move, Game game) to check the legal- ity of a given move/capture in a given game. This method returns true if the move/capture is legal and returns false otherwise. Since the legality of a move/capture depends on the type of piece that is displaced, you need to override this method in every subclass of this class. 1.2 util.Square This class which represents one of the 64 squares of the chess board contains two private instance fields boolean lightcolor and Piece occupant. The first variable has a public getter and the second one has a getter and setter. The square is light-color if and only if the lightcolor is true. Also, the square is empty if and only if the occupant is null. In the case that the square is not empty, occupant refers to the piece occupying that square. 1.3 game.Move This class represent a move or capture made by a player on the chessboard in a game. A chessboard is a 8 × 8 table of objects of class Square. In this table, rows are called ranks, and columns are called files. As seen in Figure 1, the table row/rank with index 0 is labeled with “8”, index 1 is labeled with “1”, . . . , and index 7 is labeled by “1”. Also, the table column/file with index 0 is labeled with “a”, index 1 is labeled by “b”, . . . , and index 7 is labeled with “h”. 1 Figure 1: Row and column labels in a chessboard. To specify a move or capture, this class uses the coordinates (rank and file) of two squares: the source and the target. For example, move d2d4 represents the move/capture in which the piece occupying square d2 (source square with row index 6 and column index 3) has been placed on square d4 (target square with row index 4 and column index 3). Class Move is made of five private instance fields: String move which keeps track of the string representation of the move (e.g. a8b7 or d2d4), int row0, col0 which store the coordinates of source square, and int row1, col1 which store the coordinates of target square. The first one can be accessed by calling the toString method of this class. The other four have public getters. 1.4 game.Game This class represents a Chess game and is made of the following private instance fields: String player1 : name of the first player String player2 : name of the second player ArrayList〈Move〉 moves : list of all moves played in the game so far Square[][] board : A 2D array of Square objects to keep track of the occupants of every square in the board. It also has public getters for players’ names, the public method Piece getPiece(int row, int col) to get the piece occupying a given square, and the public method boolean isWhiteTurn() which returns true if it is player one’s turn to move and returns false if it is player two’s to move. Another public method of this class is boolean move(Move move) which moves a piece from one square to the other. Obviously the source and target squares are given by the 2 object of class Move passed to this method. As the return value, this method returns true if the move is legal; otherwise, it returns false. Moreover, there exists another public method with signature void showBoard(PrintStream stream) that gets a out stream (e.g. System.out) and prints the board and its occupants on the out stream. Finally, it has a constructor that places all pieces on the board and initializes the instance fields of the class. Below you can see the initial setting of pieces made by Game’s constructor: r n b q k b n r p p p p p p p p P P P P P P P P R N B Q K B N R 2 Program Commands Your program must be responsive to the following commands entered by user via standard input stream: new game PLAYER1 PLAYER2: creates a new game between two players with given names PLAYER1 and PLAYER2. The first player owns white pieces while the second player plays with black pieces. mv α0β0α1β1: moves the piece from square α0β0 to square α1β1 where α0 and α1 can be letters from a to h; while β0 and β1 can be integers from 1 to 8. If the move is legal, you need to print the following message and then display the board; otherwise, you need to print an “illegal move” message on screen. player1 + “ moves: α0β0α1β1\n” OR player2 + “ moves: α0β0α1β1\n” cp α0β0 α1β1: captures the piece in square α1β1 with the piece in square α0β0 where α0 and α1 can be letters from a to h; while β0 and β1 can be integers from 1 to 8. If the 3 capture is legal, you need to print the following message and then display the board; otherwise, you need to print an “illegal capture” message on screen. player1 + “ captures: α0β0α1β1\n” OR player2 + “ captures: α0β0α1β1\n” undo: undoes the previous move/capture and displays the updated board. print status: prints out the current status of pieces on the board followed by the list of moves played in the game. 3 Legal Moves and Captures 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. 4 30% Bonus Parts 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) 4 3. As the third bonus part, your program must print a “check” message once the king is in check and print “checkmate” once the king is in check and there is no legal move that gets king out of check. 4. (ungraded extra items) your program must support castling long and short moves. 5. (ungraded extra items) your program must support draw offers and draw by three-fold repetition. 5 Submissions You need to submit a .zip file compressing the following folders: the packages containing all the java source files related to the assignment (.java files). A readme file clearly explaining what parts have/haven’t been implemented. 5 What main should contain: case "print": String secondToken = scnr.next(); if(secondToken.equals("status"){ game.showBoard(System.out); System.out.println("List of moves: " + game); } else{ System.out.prinln("Illegal command! please try again"); } case "undo": Game alternative = new Game(game.getPlayer1(), game.getPlayer2()); /*...*/ game = alternative; What Pawn.isLegal should contain: @Override public boolean isLegal(Move move, Game game) { if(!super.isLegal(move, game)) return false; //rules for pawn only! int rowDiff = move.getRow1() - move.getRow0(); int colDiff = move.getCol1() - move.getCol0(); if(rowDiff > 0 && white || rowDiff < 0 && !white) return false;//pawn doesn't move backward! //add more rules here if(game.getpiece(move.getrow1(),move.getcol1()) == null){//move not capture if (coldiff != 0)//non-vertical return false; return math.abs(rowdiff) == 1 || math.abs(rowdiff) == 2 && move.getrow0() == 1 && !white && game.getpiece(2,move.getcol0()) == null || math.abs(rowdiff) == 2 && move.getrow0() == 6 && white && game.getpiece(5,move.getcol0()) == null; }else return math.abs(rowdiff) * math.abs(coldiff) == 1; } what king.islegal should contain: @override public boolean islegal(move move, game game) { if(!super.islegal(move, game)) return false; int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return math.abs(rowdiff) == 1 && math.abs(coldiff) == 1 || math.abs(rowdiff) + math.abs(coldiff) == 1; } what bishop.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return rowdiff * coldiff != 0; what rook.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return rowdiff * coldiff == 0; what knight.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return math.abs(rowdiff * coldiff) == 2 previousnext 0="" &&="" !white)="" ="" ="" ="" ="" return="" false;//pawn="" doesn't="" move="" backward!="" ="" ="" add="" more="" rules="" here="" ="" ="" if(game.getpiece(move.getrow1(),move.getcol1())="=" null){//move="" not="" capture="" ="" ="" ="" ="" if="" (coldiff="" !="0)//non-vertical" ="" ="" ="" ="" ="" ="" return="" false;="" ="" ="" ="" ="" return="" math.abs(rowdiff)="=" 1="" || ="" ="" ="" ="" ="" ="" ="" math.abs(rowdiff)="=" 2="" &&="" move.getrow0()="=" 1="" &&="" !white="" &&="" game.getpiece(2,move.getcol0())="=" null="" ||="" ="" ="" ="" ="" ="" ="" math.abs(rowdiff)="=" 2="" &&="" move.getrow0()="=" 6="" &&="" white="" &&="" game.getpiece(5,move.getcol0())="=" null;="" ="" ="" }else="" ="" ="" ="" ="" return="" math.abs(rowdiff)="" *="" math.abs(coldiff)="=" 1;="" ="" ="" }="" what="" king.islegal="" should="" contain:="" @override="" ="" ="" public="" boolean="" islegal(move="" move,="" game="" game)="" {="" ="" ="" if(!super.islegal(move,="" game))="" ="" ="" ="" ="" return="" false;="" ="" ="" int="" rowdiff="move.getRow1()" -="" move.getrow0();="" ="" ="" int="" coldiff="move.getCol1()" -="" move.getcol0();="" ="" ="" return="" math.abs(rowdiff)="=" 1="" &&="" math.abs(coldiff)="=" 1="" ||="" math.abs(rowdiff)="" +="" math.abs(coldiff)="=" 1;="" ="" ="" }="" what="" bishop.islegal="" should="" contain:="" int="" rowdiff="move.getRow1()" -="" move.getrow0();="" ="" ="" int="" coldiff="move.getCol1()" -="" move.getcol0();="" ="" ="" return="" rowdiff="" *="" coldiff="" !="0;" what="" rook.islegal="" should="" contain:="" int="" rowdiff="move.getRow1()" -="" move.getrow0();="" ="" ="" int="" coldiff="move.getCol1()" -="" move.getcol0();="" ="" ="" return="" rowdiff="" *="" coldiff="=" 0;="" what="" knight.islegal="" should="" contain:="" int="" rowdiff="move.getRow1()" -="" move.getrow0();="" ="" ="" int="" coldiff="move.getCol1()" -="" move.getcol0();="" ="" ="" return="" math.abs(rowdiff="" *="" coldiff)="=" 2=""> 0 && !white) return false;//pawn doesn't move backward! //add more rules here if(game.getpiece(move.getrow1(),move.getcol1()) == null){//move not capture if (coldiff != 0)//non-vertical return false; return math.abs(rowdiff) == 1 || math.abs(rowdiff) == 2 && move.getrow0() == 1 && !white && game.getpiece(2,move.getcol0()) == null || math.abs(rowdiff) == 2 && move.getrow0() == 6 && white && game.getpiece(5,move.getcol0()) == null; }else return math.abs(rowdiff) * math.abs(coldiff) == 1; } what king.islegal should contain: @override public boolean islegal(move move, game game) { if(!super.islegal(move, game)) return false; int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return math.abs(rowdiff) == 1 && math.abs(coldiff) == 1 || math.abs(rowdiff) + math.abs(coldiff) == 1; } what bishop.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return rowdiff * coldiff != 0; what rook.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return rowdiff * coldiff == 0; what knight.islegal should contain: int rowdiff = move.getrow1() - move.getrow0(); int coldiff = move.getcol1() - move.getcol0(); return math.abs(rowdiff * coldiff) == 2 previousnext>