Answered step by step
Verified Expert Solution
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 setArbitraryPositionPosition currentPosition
This method checks if the position is a valid position
public boolean isValidPositionPosition newPosition
write here all missing classes
public class Chess
public static void mainString args
Player p new PlayerWhite player";
psetColorWhitetrue;
Player p new PlayerBlack player";
psetColorWhitefalse;
System.out.printlnTesting kings:";
Piece whiteKing new Kingp;
whiteKing.setArbitraryPositionnew Positionf;
testwhiteKinga false;
testwhiteKingf true;
System.out.printlnTesting rooks:";
Rook blackRook new Rookp;
blackRook.setArbitraryPositiond;
testblackRookh true;
testblackRookh false;
testblackRookd false;
System.out.printlnTesting bishops:";
Piece whiteBishop new Bishopp;
whiteBishop.setArbitraryPositionnew Positiond;
testwhiteBishopb false;
testwhiteBishopa true;
System.out.printlnTesting knigts:";
Knight blackKnight new Knightp;
blackKnight.setArbitraryPositiond;
testblackKnighte true;
testblackKnightf false;
testblackKnightc true;
testblackKnighti false;
System.out.printlnTesting pawns:";
Pawn whitePawn new Pawnp;
Pawn blackPawn new Pawnp;
blackPawn.setArbitraryPositionb;
testblackPawnb true;
testblackPawnb false;
whitePawn.setArbitraryPositionf;
testwhitePawnf true;
testwhitePawnf true;
blackPawn.setArbitraryPositiong;
testblackPawng true;
testblackPawng false;
whitePawn.setArbitraryPositione;
testwhitePawnd false;
testwhitePawnf false;
public static void testPiece p char x int y boolean valid
if pisValidPositionnew Positionx 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started