Question: Question 3 ( 3 3 marks ] Vou are asked to write in Java a ChessBoard clas ( Defiition ) which provides methods to L

Question3(33 marks]
Vou are asked to write in Java a ChessBoard clas (Defiition) which provides methods to
L. initalse 2 game,
2. checkIf amove s possible (not to be accessible from outsde this class),
3. undo the last move (10t 20 be accessible from autside this class),)
4. make & move it Is possible (returning success or falure),) and
5. 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.
1) 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.
Chessisatwophyer(thedyess o 5 p & o
referred 035 BACKand WHITE)| o T X S
g s TR S Nide S O
square hoarc. Each square is T e s aes
e sans 113148111
Lro8)andeolumn o leterfrom .| S T SR AR
toR), There are ypesof pioces I | B
and they are ntially aid out a5 e
shown In the diagram. The object 5|[] 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 3[ Foid
CHECK. Each playeraltenately |<=|51=
i : TR n
tekesa move, rormally moving 2|\dkA SN NI I
s one oftherown lces Al |5 ST e S S S
theplces can be moves toaree 113(( Eer\\i??;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 1t 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 3 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 2nd 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!