Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chess Pieces in JAVA: A cell on the board is specified by a (row, column) tuple: rows increasing from bottom to top and columns increasing

Chess Pieces in JAVA:

A cell on the board is specified by a (row, column) tuple: rows increasing from bottom to top and columns increasing from left to right. Traditionally the black pieces are arranged in the top two rows as shown.

Each chess piece can move in a specific way. In addition to moving, each chess piece can also kill 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 opponents 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 opponents piece if it can move to its place.

  • Queen: A queen can move horizontally, vertically and diagonally. It can kill any opponents piece if it can move to its place.

  • Rook: A rook can move horizontally or vertically. It can kill any opponents 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. 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. All rows and columns begin with 0. Rows decrease in number from top to bottom in the above chessboard.

Beyond these classes, enum, interface and methods, 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 then write tests for each chess piece that test these operations thoroughly.

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

decide what data to gather and when;

Answered: 1 week ago