Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to complete a simple chess program below. All that is needed is to implement the heirarchy of classes that corresponds to the logic

I need to complete a simple chess program below. All that is needed is to implement the heirarchy of classes that corresponds to the logic that you already have in the program. The program is sucessfull when a bunch of test passed! are printed. Do not alter the main method or the test method. Assume that there are no other pieces on the board and that you do not need to worry about taking pieces etc.. just make sure that they move in accordance with their respective chess laws.
class Piece {
//...
/**
* This method does not have to check the validity of the position
*/
public void setArbitraryPosition(Position currentPosition){
//...
}
/**
* This method checks if the position is a valid position
*/
public boolean isValidPosition(Position newPosition){
//...
}
}
//...
// write here all missing classes
//...
public class Chess {
public static void main(String[] args){
Player p1= new Player("White player");
p1.setColorWhite(true);
Player p2= new Player("Black player");
p2.setColorWhite(false);
System.out.println("Testing kings:");
Piece whiteKing = new King(p1);
whiteKing.setArbitraryPosition(new Position('f',5));
test(whiteKing,'a',1, false);
test(whiteKing,'f',4, true);
System.out.println("Testing rooks:");
Rook blackRook = new Rook(p2);
blackRook.setArbitraryPosition('d',5);
test(blackRook,'h',5, true);
test(blackRook,'h',1, false);
test(blackRook,'d',9, false);
System.out.println("Testing bishops:");
Piece whiteBishop = new Bishop(p1);
whiteBishop.setArbitraryPosition(new Position('d',5));
test(whiteBishop,'b',2, false);
test(whiteBishop,'a',8, true);
System.out.println("Testing knigts:");
Knight blackKnight = new Knight(p2);
blackKnight.setArbitraryPosition('d',4);
test(blackKnight,'e',6, true);
test(blackKnight,'f',6, false);
test(blackKnight,'c',2, true);
test(blackKnight,'i',8, false);
System.out.println("Testing pawns:");
Pawn whitePawn = new Pawn(p1);
Pawn blackPawn = new Pawn(p2);
blackPawn.setArbitraryPosition('b',4);
test(blackPawn,'b',3, true);
test(blackPawn,'b',5, false);
whitePawn.setArbitraryPosition('f',2);
test(whitePawn,'f',3, true);
test(whitePawn,'f',4, true);
blackPawn.setArbitraryPosition('g',5);
test(blackPawn,'g',4, true);
test(blackPawn,'g',3, false);
whitePawn.setArbitraryPosition('e',7);
test(whitePawn,'d',8, false);
test(whitePawn,'f',8, false);
}
public static void test(Piece p, char x, int y, boolean valid){
if (p.isValidPosition(new Position(x, y))== valid){
System.out.println("> Test passed!");
} else {
System.out.println(" X Test NOT passed!");
}
}
}

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

2-11. Why do governments intervene in free-market systems?

Answered: 1 week ago

Question

using signal flow graph

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago