To start us off, create an abstract ChessPiece class. What instance data would all chess pieces...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
To start us off, create an abstract ChessPiece class. What instance data would all chess pieces have? Knowing that all the chess pieces move in different ways, declare an abstract method called move. This method will return true or false depending if the move is valid or not. PART A. The Chess Board Now, create the board of the game using a 2D array. To display a chess board, we will do a basic print out like shown: =6= 2 == =1= =2= =3= =4= =5= =6= =7= Notice that this board follows the Cartesian Coordinate System, except that the (0,0) coordinate pair is not the intersection of the two planes. Also note that we are used to printing out our 2D arrays beginning with (0,0) at the top left of the grid. That is not the case here. Figure out how to do this. How would the code look? Perhaps write down the coordinates for each element in the grid to figure out how to print your 2D array. PART B. Place the chess pieces on the board. At this point, you need to create the chess pieces. Here is the SUBSET of chess pieces you need to implement and how each piece can move on the board. 1. PAWN - This piece moves one space forward/back at a time. However, it can move 2 spaces ONLY if it's that pawn's first move of the "game." 2. ROOK - This pieces moves forwards/backwards and sideways. 3. KNIGHT - This piece can jump in an L-shaped pattern. 4. BISHOP - This piece moves diagonally. Make sure the four classes above use ChessPiece as its super class. Now create a driver program, Setup.java to test what you have so far. In this driver program, create your board, use the file input1.txt to place chess pieces on your board and display them after each additional piece is set. =7= =6= -r- =5= -b- --- -p- =4= =3= -b- --- -- =2= =1= --- =0= -h- -p- --- === =0= =1= =2= =3= =4= =5= =6= =7= Above is a sample initial state of the board with the given input file : knight e e раwn 5 5 раwn 7 @ rook 2 6 bishop 2 5 bishop 7 3 rook 3 4 Note: the knight is denoted as an "-h-" on the board to avoid confusion with the presence of a king in the future. PART C. Move the chess pieces. Now build upon what you have in Setup.java by creating ChessMoves.java using input2.txt The next part of this input file will give you a list of moves that you should attempt to accomplish. One such move is having the pawn at coordinate (7,0) move to (7,2). If the move is illegal, do not allow the move. PAWN: (7,0) (7,2) Moved! (7,0) (7,2) BISHOP: (0,3) (0,1) Invalid move. (0,3) (0,1) ==== ==== !========== =7= =7= --- =6= =6= =5= =5= =4= =4= =3= -b- =3= -b- -b- =2= -p- =2= =1= =1= --- -h- =0= -h- =0= --- --- === =0= =1= =2= =3= =4= =5= =6= =7= === =0= =1= =2= =3= =4= =5= =6= =7= | | | | | | } | | | | | | | | | | | } | | | | | 4 | | | | PART D. Creating Exceptions for Error Cases. When a chess piece attempts to move illegally, we will throw exceptions. First, create an OutOfBoardException, wherein you throw this exception for a move whose destination is outside the playing board. Second, create an IllegalChessMoveException that is thrown for illegal chess piece movements -- such as a pawn moving diagonally or sideways. Note: These new Exceptions you create shall be subclasses of the Exception class. Also, make sure to handle the exception by telling the user the error and allowing the program to continue (i.e. program does not quit.). Invalid Board Position. (7,3) (8,4) =7= =6= =5= =4= =3= -b- -b- =2= --- =1= -h- =0= === =0= =1= =2= =3= =4= =5= =6%= =73=D | | | | | | | | | | PART E. Complete Board Complete the setup of the board by creating a new Driver, ChessBasics.java 1. First you need to create two new ChessPiece subclasses o King - This piece moves one space in any direction o Queen This piece moves any amount of spaces in any direction 2. Create a new input file, game.txt that sets up the board such that a complete chess set is on the board. =7= -r- -h- -b- -K- -Q- -b- -h- -r- 363D -р- -р- -р- -р- -р- -р- -р- -р- =5%3= =4= =3= =2= %3D13 -р- -р- -р--р- -р- -р- -р- -р- =0= -r- -h- -b- -K- -Q- -b- -h- -r- === =0= =1= =2= =3= =4= =5= =6= =73 3. Then modify your new input file to contain moves which showcase that each chess piece works as expected. BONUS PART: Create a PathwayException wherein it is an illegal move if there is another chess piece on the way - either at the destination coordinate or in the path to the destination coordinate. (Remember, a knight can jump over chess pieces.) To start us off, create an abstract ChessPiece class. What instance data would all chess pieces have? Knowing that all the chess pieces move in different ways, declare an abstract method called move. This method will return true or false depending if the move is valid or not. PART A. The Chess Board Now, create the board of the game using a 2D array. To display a chess board, we will do a basic print out like shown: =6= 2 == =1= =2= =3= =4= =5= =6= =7= Notice that this board follows the Cartesian Coordinate System, except that the (0,0) coordinate pair is not the intersection of the two planes. Also note that we are used to printing out our 2D arrays beginning with (0,0) at the top left of the grid. That is not the case here. Figure out how to do this. How would the code look? Perhaps write down the coordinates for each element in the grid to figure out how to print your 2D array. PART B. Place the chess pieces on the board. At this point, you need to create the chess pieces. Here is the SUBSET of chess pieces you need to implement and how each piece can move on the board. 1. PAWN - This piece moves one space forward/back at a time. However, it can move 2 spaces ONLY if it's that pawn's first move of the "game." 2. ROOK - This pieces moves forwards/backwards and sideways. 3. KNIGHT - This piece can jump in an L-shaped pattern. 4. BISHOP - This piece moves diagonally. Make sure the four classes above use ChessPiece as its super class. Now create a driver program, Setup.java to test what you have so far. In this driver program, create your board, use the file input1.txt to place chess pieces on your board and display them after each additional piece is set. =7= =6= -r- =5= -b- --- -p- =4= =3= -b- --- -- =2= =1= --- =0= -h- -p- --- === =0= =1= =2= =3= =4= =5= =6= =7= Above is a sample initial state of the board with the given input file : knight e e раwn 5 5 раwn 7 @ rook 2 6 bishop 2 5 bishop 7 3 rook 3 4 Note: the knight is denoted as an "-h-" on the board to avoid confusion with the presence of a king in the future. PART C. Move the chess pieces. Now build upon what you have in Setup.java by creating ChessMoves.java using input2.txt The next part of this input file will give you a list of moves that you should attempt to accomplish. One such move is having the pawn at coordinate (7,0) move to (7,2). If the move is illegal, do not allow the move. PAWN: (7,0) (7,2) Moved! (7,0) (7,2) BISHOP: (0,3) (0,1) Invalid move. (0,3) (0,1) ==== ==== !========== =7= =7= --- =6= =6= =5= =5= =4= =4= =3= -b- =3= -b- -b- =2= -p- =2= =1= =1= --- -h- =0= -h- =0= --- --- === =0= =1= =2= =3= =4= =5= =6= =7= === =0= =1= =2= =3= =4= =5= =6= =7= | | | | | | } | | | | | | | | | | | } | | | | | 4 | | | | PART D. Creating Exceptions for Error Cases. When a chess piece attempts to move illegally, we will throw exceptions. First, create an OutOfBoardException, wherein you throw this exception for a move whose destination is outside the playing board. Second, create an IllegalChessMoveException that is thrown for illegal chess piece movements -- such as a pawn moving diagonally or sideways. Note: These new Exceptions you create shall be subclasses of the Exception class. Also, make sure to handle the exception by telling the user the error and allowing the program to continue (i.e. program does not quit.). Invalid Board Position. (7,3) (8,4) =7= =6= =5= =4= =3= -b- -b- =2= --- =1= -h- =0= === =0= =1= =2= =3= =4= =5= =6%= =73=D | | | | | | | | | | PART E. Complete Board Complete the setup of the board by creating a new Driver, ChessBasics.java 1. First you need to create two new ChessPiece subclasses o King - This piece moves one space in any direction o Queen This piece moves any amount of spaces in any direction 2. Create a new input file, game.txt that sets up the board such that a complete chess set is on the board. =7= -r- -h- -b- -K- -Q- -b- -h- -r- 363D -р- -р- -р- -р- -р- -р- -р- -р- =5%3= =4= =3= =2= %3D13 -р- -р- -р--р- -р- -р- -р- -р- =0= -r- -h- -b- -K- -Q- -b- -h- -r- === =0= =1= =2= =3= =4= =5= =6= =73 3. Then modify your new input file to contain moves which showcase that each chess piece works as expected. BONUS PART: Create a PathwayException wherein it is an illegal move if there is another chess piece on the way - either at the destination coordinate or in the path to the destination coordinate. (Remember, a knight can jump over chess pieces.)
Expert Answer:
Answer rating: 100% (QA)
Answers TASK 1 Setupjava import javaio import javautilScanner public class Setup initialize the empty board with no pieces public static void initBoardString chessBoard chessBoard80 forint i0i 8i int ... View the full answer
Related Book For
Posted Date:
Students also viewed these general management questions
-
1. Question 1: Make following hierarchy structure of directories. Java is file. Create it in Section 2 And copy in Section 1 and Section 3 2. Use different options of directory and file commands of...
-
Develop a linear regression model: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 A Year 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007...
-
A 1 defects size B D E 88888888888888888888888888 2 21 3 24 4 16 5 12 6 15 7 5 8 28 9 20 10 31 11 25 12 20 13 24 14 16 15 19 16 10 17 17 18 13 19 22 20 18 21 39 22 30 23 24 24 16 25 19 26 17 27 15...
-
Suppose that the government of Malud increases both its own spending and autonomous taxes by $300 and the economys multiplier equals 2.5. If consumers spend 95% of their disposable (after-tax)...
-
The Cotton Mill is an upscale chain of womens clothing stores, located primarily in the southwest United States. Due to recent success, The Cotton Mills top management is planning to expand by...
-
Review the process of voir dire. When questioning a potential juror in voir dire, what are some of the personality traits and characteristics the attorneys are trying to determine prior to trial?...
-
Tracing copies of sales invoices to shipping documents provides evidence that: a. Shipments were recorded as receivables. b. Billed sales were shipped. c. Debits to the accounts receivable were for...
-
Since the terrorist attacks of 9/11 and the ensuing measures by the federal Transportation Security Administration (TSA) to increase airline security, airports have faced the problem of long waiting...
-
What advanced methodologies are used to measure and quantify stress, and how reliable are these methods in different contexts ?
-
Billingham Packaging is considering expanding its production capacity by purchasing a new machine, the XC-750. The cost of the XC-750 is $2.75 million. Unfortunately, installing this machine will...
-
Compose a paper on electrocardiogram (ECG) that presents an FPGA design and completion of embedded systems, Biomedical (ECG-SOC)
-
1. How well did Sarahs Snacks fit Nadler and Tushmans congruence model before it began its organizational change? 2. Why have the changes at Sarahs Snacks not produced the expected results? 3. What...
-
The most appropriate asset allocation for the Martins new charitable gift sub-portfolio is: A. 40% equities/60% bonds. B. 70% equities/30% bonds. C. 100% equities/0% bonds. lsbeth Quinn and Dean...
-
In given sequence of numbers: 3, 9, 5, 4, 8, 1, 5, 2, 7, 6. Construct a Min-heap by calling Create Heap function. PriorityQueue pq = new PriorityQueue (arr, false);
-
Given an array contain 0s and 1s, sort the array such that all the 0s come before 1s. //Sorts a given list by selection sort //Input: An array A[0..n-1] of orderable elements. //Output: List...
-
An investor is considering adding three new securities to her internationally focused, fixed-income portfolio. She considers the following non-callable securities: 1-year government bond 10-year...
-
On 1 September 2022 a Contracting Officer properly awards a contract to ABCCorporation for 1000 widgets. The widgets are delivered on 1 November 2022. TheContracting Officer correctly determined that...
-
In the series connection below, what are the respective power consumptions of R, R2, and R3? R R www 4 V=6V P1-3 W; P2=3W; and P3= 3 W OP10.5 W; P2-1 W; and P3= 1.5 W P1=1.5 W; P2=1 W; and P3= 0.5 W...
-
You have created a number of programs for Carlys Catering. Now, create an interactive GUI program that allows the user to enter the number of guests for an event into a text field; if the value...
-
You modified the EventDemo program for Carlys Catering to accept and display data for an array of three Event objects. Now, modify the program to use an array of eight Event objects. Prompt the user...
-
The memory location where the computer stores the list of method locations to which the system must return is known as the ____________. A. Registry B. Archive C. Chronicle D. Call stack
-
Under what conditions is an auditor most likely to confirm payables?
-
Explain how an auditor determines whether all recorded payables actually represent bona fide obligations of the entity.
-
Why is confirmation ineffective in detecting understatement of liabilities?
Malaysia 50 Economic Development Distribution Disparities 1st Edition - ISBN: 9814571385 - Free Book
Study smarter with the SolutionInn App