@@ -99,6 +99,25 @@ private Piece makeMove(Position source, Position target) {
9999 piecesOnTheBoard .remove (capturedPiece );
100100 CapturedPieces .add (capturedPiece );
101101 }
102+
103+ //#specialmove castling kinside rook
104+ if (p instanceof King && target .getColumn () == source .getColumn () + 2 ) {
105+ Position sourceT = new Position (source .getRow (), source .getColumn () + 3 );
106+ Position targetT = new Position (source .getRow (), source .getColumn () + 1 );
107+ ChessPiece rook = (ChessPiece )board .removePiece (sourceT );
108+ board .placePiece (rook , targetT );
109+ rook .increaseMoveCount ();
110+ }
111+
112+ //#specialmove castling kinside rook
113+ if (p instanceof King && target .getColumn () == source .getColumn () - 2 ) {
114+ Position sourceT = new Position (source .getRow (), source .getColumn () - 4 );
115+ Position targetT = new Position (source .getRow (), source .getColumn () - 1 );
116+ ChessPiece rook = (ChessPiece )board .removePiece (sourceT );
117+ board .placePiece (rook , targetT );
118+ rook .increaseMoveCount ();
119+ }
120+
102121 return capturedPiece ;
103122 }
104123
@@ -111,6 +130,25 @@ private void undoMove(Position source, Position target, Piece capturedPiece) {
111130 CapturedPieces .remove (capturedPiece );
112131 piecesOnTheBoard .add (capturedPiece );
113132 }
133+
134+ //#specialmove castling kinside rook
135+ if (p instanceof King && target .getColumn () == source .getColumn () + 2 ) {
136+ Position sourceT = new Position (source .getRow (), source .getColumn () + 3 );
137+ Position targetT = new Position (source .getRow (), source .getColumn () + 1 );
138+ ChessPiece rook = (ChessPiece )board .removePiece (targetT );
139+ board .placePiece (rook , sourceT );
140+ rook .decreaseMoveCount ();
141+ }
142+
143+ //#specialmove castling kinside rook
144+ if (p instanceof King && target .getColumn () == source .getColumn () - 2 ) {
145+ Position sourceT = new Position (source .getRow (), source .getColumn () - 4 );
146+ Position targetT = new Position (source .getRow (), source .getColumn () - 1 );
147+ ChessPiece rook = (ChessPiece )board .removePiece (targetT );
148+ board .placePiece (rook , sourceT );
149+ rook .decreaseMoveCount ();
150+ }
151+
114152 }
115153
116154
@@ -198,7 +236,7 @@ private void initialSetup() {
198236 placeNewPiece ('b' , 1 , new Knight (board , Color .WHITE ));
199237 placeNewPiece ('c' , 1 , new Bishop (board , Color .WHITE ));
200238 placeNewPiece ('d' , 1 , new Queen (board , Color .WHITE ));
201- placeNewPiece ('e' , 1 , new King (board , Color .WHITE ));
239+ placeNewPiece ('e' , 1 , new King (board , Color .WHITE , this ));
202240 placeNewPiece ('f' , 1 , new Bishop (board , Color .WHITE ));
203241 placeNewPiece ('g' , 1 , new Knight (board , Color .WHITE ));
204242 placeNewPiece ('h' , 1 , new Rook (board , Color .WHITE ));
@@ -216,7 +254,7 @@ private void initialSetup() {
216254 placeNewPiece ('b' , 8 , new Knight (board , Color .BLACK ));
217255 placeNewPiece ('c' , 8 , new Bishop (board , Color .BLACK ));
218256 placeNewPiece ('d' , 8 , new Queen (board , Color .BLACK ));
219- placeNewPiece ('e' , 8 , new King (board , Color .BLACK ));
257+ placeNewPiece ('e' , 8 , new King (board , Color .BLACK , this ));
220258 placeNewPiece ('f' , 8 , new Bishop (board , Color .BLACK ));
221259 placeNewPiece ('g' , 8 , new Knight (board , Color .BLACK ));
222260 placeNewPiece ('h' , 8 , new Rook (board , Color .BLACK ));
0 commit comments