Question: Main objective: Store the chess pieces on an 8 x 8 chessboard as a linked list. Implement the following procedures for a given chessboard: Determine

Main objective: Store the chess pieces on an 8 x 8 chessboard as a linked list. Implement the following procedures for a given chessboard: Determine Validity: Verify that two pieces do not occupy the same square, and there is exactly one king of each color (white and black). Find Piece on square: Given a square, determine the chess piece at that square, if any. As in HW1, squares are specified as (column, row). Discover an Attack (by a particular piece): Find out if the piece (found by Fine piece) attacks another piece. Note that the pieces must be of different colors. Do not worry about blocking--assume that pieces can pass through other pieces on the board. This is not true for proper chess, but it makes coding much easier for this assignment. Thus a piece x on a square can attack another piece y on a different square if x would be able travel to ys square (according to the rules of chess) if there were no other pieces on the board. (Youll just have to find one attack, not all of them.) Do not work about non-standard moves, such as castling. You will not get any credit if you do not implement using a linked list for the set of pieces on the board. Furthermore, you have to write your own linked list from scratch. You cannot use any built-in libraries for linked lists. Suggestions for coding: You do not have to follow the following instructions, but they might make life easier for you (and your code nicer). Create a (super)class Chess Piece with child subclasses for each different type of piece. Each of these subclasses can implement its own attacking function. Think about how you want to represent the position and color of each piece. Create a class ChessBoard that has a Linked List of ChessPiece objects. (You must do this via a Linked List.) This class can have methods for determining validity, finding, etc. 2 Format: You should provide a Makefile. Running make should create Chessboard.jar. Your program should take two command line arguments, an input file and an output file. The format of the input file is as follows. Each line starts with two integers, referring to a specific chessboard position; the integers specify a column and a row. This is followed by a colon. Then the line contains a list of pieces consisting of piece column row, where piece is a character that is one of k (king), q (queen), r (rook), b (bishop). (There are no pawns or knights in HW2.) If the character is capitalized, then the piece is black; if it is not capitalized, then the piece is white. For example, a line could be: 8 2: q 4 3 k 4 4 r 8 2 R 8 8 b 1 1 K 4 8 B 7 7 The portion after the colon describes the pieces on an 8 x 8 chessboard, and the portion before the colon is a query asking what is at position (8,2). The answer here is a white rook, denoted r. This pattern of pairs of lines continues throughout the input file. Do not worry about error handling on the input; you can assume that inputs will always have this format. No piece will be placed outside the chessboard. If you want to, you can use the Java split method to split strings; theres a good example of its use with white space (such as blanks) here. Output: On running (say) : java -jar Chessboard.jar in.txt out.txt the file in.txt is read in and the output file out.txt should be produced. The ith line of the output file out.txt corresponds to the ith chessboard in in.txt. The ith line of the output file should contain: If the ith chessboard is not valid, then the ith line should be Invalid (without the quotes). If the ith chessboard is valid, then first output the chess piece (if any) thats at the query square. If there is none, then just print - (without the quotes). If there is a piece at the query square, print a space, and then print y (the piece attacks some other piece) or n (it does not attack another piece). For the example given above, the output would be: r y because the white rook at (8.2) attacks a black rook at (8,8)

input.txt: 4 4: q 4 1 Q 4 5 k 3 1 q 8 6 Q 4 4 K 7 3 1 1: K 6 8 q 1 1 Q 1 2 q 4 5 b 1 2 k 3 7 2 3: r 2 4 q 2 3 Q 3 7 Q 8 8 Q 8 1 K 5 7 k 1 2 3 5: q 5 3 K 8 7 Q 4 3 q 1 3 b 5 5 k 8 1 2 2: k 7 5 r 2 2 Q 4 3 K 7 5 R 7 8 k 8 1

corresponding output: Q y Invalid q n - Invalid

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!