Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how do i write the interface, abstract, classes and the JUnit 4 tests all in java? Each chess piece can move in a specific way.

how do i write the interface, abstract, classes and the JUnit 4 tests all in java? image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Each chess piece can move in a specific way. In addition to moving, each chess piece can also kill/capture a chess piece of the opposite color if it moves to its place. The rules for each chess piece are as follows: Bishop: A bishop can only move diagonally, and kill any opponent's piece if it can move to its place. Knight: A knight can move only in an L pattern: two cells horizontally and one vertically or vice versa. It can kill any opponent's piece if it can move to its place. Queen: A queen can move horizontally, vertically and diagonally. It can kill any opponent's piece if it can move to its place. Rook: A rook can move horizontally or vertically. It can kill any opponent's piece if it can move to its place. Pawn: A pawn is interesting: it can move only "ahead," not backwards towards where its color started. It can move only one place forward in its own column. However, to kill it must move one place forward diagonally (it cannot kill by moving straight). You must design and implement classes that represent the above chess pieces. These classes should be named exactly as their names above, and all of them should implement the ChessPiece interface. Unlike previous assignments, we're not explicitly giving the interface code to you; develop the ChessPiece interface based on the following (NB: ensure your ChessPiece interface is spelled the same way as you see here). ChessPiece contract: Each chess piece should be able to: (a) return its current position on the chess board, as methods getRow () and getColumn() (b) return its color as an enum Color (c) determine if it can move to a given cell, as a method canMove (int row, int col), (d) determine if it can kill a provided piece starting from where it currently is, as a method canKill (ChessPiece piece). In addition, each chess piece should have a constructor that takes in an initial position as a row and column, and a color as an enum Color with values BLACK and WHITE. Note: All rows and columns begin at "index" O. Rows decrease in number from top to bottom in the above chessboard. Therefore the "top"row shown on the graphic above (where the Black non-pawn pieces are positioned) is row 7. Beyond the classes, enum, interface and methods specified here, you are free to design any other interfaces and classes as you see fit. However, they must have good justification, be designed appropriately, and be used in the appropriate place. You must write tests for each chess piece! Test your operations thoroughly. NB: We are not considering the "board setup" with obstruction pieces. This exercise is much simpler than factoring in "collision detection" with obstructing pieces. Answer the question: it a "is this a valid move for this piece, assuming there are no other obstructing pieces on the board"? when creating your solution. In other words, given what you know about the variation in behavior for moves, just determine if the move to a new location is valid. Or, determine if the capture/kill is "index" O. Rows decrease in number from top to bottom in the above chessboard. Therefore the "top" row shown on the graphic above (where the Black non-pawn pieces are positioned) is row 7. Beyond the classes, enum, interface and methods specified here, you are free to design any other interfaces and classes as you see fit. However, they must have good justification, be designed appropriately, and be used in the appropriate place. You must write tests for each chess piece! Test your operations thoroughly. NB: We are not considering the "board setup" with obstruction pieces. This exercise is much simpler than factoring in "collision detection" with obstructing pieces. Answer the question: it a "is this a valid move for this piece, assuming there are no other obstructing pieces on the board"? when creating your solution. In other words, given what you know about the variation in behavior for moves, just determine if the move to a new location is valid. Or, determine if the capture/kill is valid assuming one other piece is in the "target" location

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. What are the major sources of stress in your life?

Answered: 1 week ago

Question

What tools might be helpful?

Answered: 1 week ago