Question: Question 3 ( 3 3 marks ] Vou are asked to write in Java a ChessBoard clas ( Defiition ) which provides methods to L
Question marks
Vou are asked to write in Java a ChessBoard clas Defiition which provides methods to
L initalse game,
checkIf amove s possible not to be accessible from outsde this class
undo the last move t be accessible from autside this class
make & move it Is possible returning success or falure and
determine f there s CHECKMATE and who won
You may assume thet you have a ChessPlece class which provides the following methods:
i ChessPiece int piecelype, int colour, int row, char column
which intalises the piece.
i boolean carMakeMove int newRow, char neuColumn, ChessBoasd board
which determines whether tis pece can move to the aew location. Note that tis metha does
ot determmine whether or not the resulting move results in CHECK foreitaer KING.
void maelove int cofew, int toColumn
which chanes the location o the pece,
W void incheck
which informs a KING plec that It s Incheck
You may also assume that BLACK, WHITE, KING, QUEEN, BISHOP, KNIGHT, CASTLE and PAWN are
defined as constants.
Chessisatwophyerthedyess o p & o
referred BACKand WHITE o T X S
g s TR S Nide S O
square hoarc. Each square is T e s aes
e sans
Lroandeolumn o leterfrom S T SR AR
toR There are ypesof pioces I B
and they are ntially aid out a e
shown In the diagram. The object e
ofthe geme stotake the KING ~ P i
XING can be taken ina single R e S e
move its sad that the KING sin Foid
CHECK. Each playeraltenately
i : TR n
tekesa move, rormally moving dkA SN NI I
s one oftherown lces Al ST e S S S
theplces can be moves toaree Eeri;glwg; J
sovare and may ke oppanent e SIS S LS LIRS
pleces ie cemove them fomthe e wibur i kil srbor
boerd by landing on the scuare
occupied by the pce. Each of the pieces actsas follows:
The KING can normlly nly move one square at a me i any direction. The KING cannot.
moveinto apostion where t in CHECK. Ifthe KING i n CHECK then cithcr the KING
must be moved toa poston where s nat in CHECK o another piece mustbe moved to
Qwestion continues on ext page
vage'sof s
ensure that the KING s no longer in CHECK. If neither of hesc moves can be made then
he KING is Ir CHECKMATE and the payer whose KING is i CHECKMATE loses the game
The QUEEN can move in any direction vertical horizontzly o diaganally ina sraight
fine for any number of scares although i annot jump over ot pieces.
The CASTLE can normally move vertically or horizontally for any number of squares
although it cannot jump over other pieces.
THE BISHOP can move diagonally for any number of squares although It cannot jump over
other pieces.
THE KNIGHT moves in an L shiape two steps forward and one to the right o left either
horizontally or vertically and can jump over other pieces.
o The PAWN moves towards the opponents side of the board only. I taking another piece it
must move diagonally forwards by one square If nat taking a plece it must move
vertically forwards ane square or for it first move can move vertically forwards two
squares If a PAWN reaches the far opponent's end of the board then the PAWN is
replaced with any piece of the player's choice.
Thereis a special move called CASTLING where a KING which has never moved nd has never
been In CHECK may be moved twa squares to the left or right and the CASTLE on that side moved
to directly to the right or left of the KING respectively as long as there are no pieces between the
CASTLE and the KING.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
