@@ -43,14 +43,14 @@ void ChessBoard::makeZobristKey() {
4343
4444 for (u64 x2 = rightCastle; x2; RESET_LSB (x2)) {
4545 const int position = BITScanForward (x2);
46- updateZobristKey (RIGHT_CASTLE_IDX , position);// 12
46+ updateZobristKey (RIGHT_CASTLE_RAND , position);// 12
4747 }
4848
4949 if (enPassant != NO_ENPASSANT) {
50- updateZobristKey (ENPASSANT_IDX , enPassant);// 13
50+ updateZobristKey (ENPASSANT_RAND , enPassant);// 13
5151 }
52-
53- updateZobristKey (SIDETOMOVE_IDX , sideToMove); // 14
52+ static constexpr uchar SIDETOMOVE_RAND = 14 ;
53+ updateZobristKey (SIDETOMOVE_RAND , sideToMove);
5454
5555}
5656
@@ -159,19 +159,16 @@ void ChessBoard::display() const {
159159 cout << endl;
160160}
161161
162- string ChessBoard::moveToString (const _Tmove *move) {
163- string a = decodeBoardinv (move->type , move->from , move->side );
164- if (move->type & 0xc ) return a;
165- string b = decodeBoardinv (move->type , move->to , move->side );
166- if (move->promotionPiece != NO_PROMOTION) (a + b) += (char ) tolower (FEN_PIECE[move->promotionPiece ]);
167- return a + b;
168- }
169-
170162void ChessBoard::print (const _Tmove *move) {
171- cout << moveToString (move) << " " << flush;
163+ cout << decodeBoardinv (move, move-> side ) << " " << flush;
172164}
173165
174- string ChessBoard::decodeBoardinv (const uchar type, const int a, const uchar side) {
166+ string
167+ ChessBoard::decodeBoardinv (const _Tmove *move, const uchar side, const bool verbose) {
168+ const uchar type = move->type ;
169+ const int from = move->from ;
170+ const int to = move->to ;
171+ const int promotionPiece = move->promotionPiece ;
175172 if (type & QUEEN_SIDE_CASTLE_MOVE_MASK && side == WHITE) {
176173 return isChess960 () ? BOARD[startPosWhiteKing] + BOARD[startPosWhiteRookQueenSide] : " e1c1" ;
177174 }
@@ -185,17 +182,24 @@ string ChessBoard::decodeBoardinv(const uchar type, const int a, const uchar sid
185182 return isChess960 () ? BOARD[startPosBlackKing] + BOARD[startPosBlackRookKingSide] : " e8g8" ;
186183 }
187184 assert (!(type & 0xC ));
188- if (a >= 0 && a < 64 ) {
189- return BOARD[a];
185+ assert (to >= 0 && to < 64 );
186+ string cap = " " ;
187+ string res = " " ;
188+ if (verbose) {
189+ if (move->capturedPiece != SQUARE_EMPTY) cap = " *" ; else cap = " -" ;
190+ }
191+ res = BOARD[from] + cap + BOARD[to];
192+ if (promotionPiece != NO_PROMOTION) {
193+ res += tolower (FEN_PIECE[promotionPiece]);
190194 }
191- _assert ( 0 )
195+ return res;
192196}
193197
194198void ChessBoard::clearChessboard () {
195199 memset (chessboard, 0 , sizeof (_Tchessboard));
196200 enPassant = NO_ENPASSANT;
197201 rightCastle = 0 ;
198- sideToMove= 0 ;
202+ sideToMove = 0 ;
199203}
200204
201205int ChessBoard::loadFen (const string &fen) {
@@ -226,7 +230,7 @@ int ChessBoard::loadFen(const string &fen) {
226230 iss >> a2;
227231 a2 += " 1" ;
228232 if (String::isNumber (a2))
229- movesCount = stoi (a2);
233+ movesCount = stoi (a2);
230234
231235 int ix = 0 ;
232236 array<int , 64 > s;
@@ -268,28 +272,28 @@ int ChessBoard::loadFen(const string &fen) {
268272 startPosBlackKing = BITScanForward (chessboard[KING_BLACK]);
269273 auto whiteRookKingSide = [&](const char c) {
270274 startPosWhiteRookKingSide = BITScanForward (chessboard[ROOK_WHITE] & 0xffULL );
271- updateZobristKey (RIGHT_CASTLE_IDX , 4 );
275+ updateZobristKey (RIGHT_CASTLE_RAND , 4 );
272276 assert (4 == BITScanForward (RIGHT_KING_CASTLE_WHITE_MASK));
273277 rightCastle |= RIGHT_KING_CASTLE_WHITE_MASK;
274278 whiteRookKingSideCastle = c;
275279 };
276280 auto blackRookKingSide = [&](const char c) {
277281 startPosBlackRookKingSide = BITScanForward (chessboard[ROOK_BLACK] & 0xff00000000000000ULL );
278- updateZobristKey (RIGHT_CASTLE_IDX , 6 );
282+ updateZobristKey (RIGHT_CASTLE_RAND , 6 );
279283 assert (6 == BITScanForward (RIGHT_KING_CASTLE_BLACK_MASK));
280284 rightCastle |= RIGHT_KING_CASTLE_BLACK_MASK;
281285 blackRookKingSideCastle = c;
282286 };
283287 auto whiteRookQueenSide = [&](const char c) {
284288 startPosWhiteRookQueenSide = BITScanReverse (chessboard[ROOK_WHITE] & 0xffULL );
285- updateZobristKey (RIGHT_CASTLE_IDX , 5 );
289+ updateZobristKey (RIGHT_CASTLE_RAND , 5 );
286290 assert (5 == BITScanForward (RIGHT_QUEEN_CASTLE_WHITE_MASK));
287291 rightCastle |= RIGHT_QUEEN_CASTLE_WHITE_MASK;
288292 whiteRookQueenSideCastle = c;
289293 };
290294 auto blackRookQueenSide = [&](const char c) {
291295 startPosBlackRookQueenSide = BITScanReverse (chessboard[ROOK_BLACK] & 0xff00000000000000ULL );
292- updateZobristKey (RIGHT_CASTLE_IDX , 7 );
296+ updateZobristKey (RIGHT_CASTLE_RAND , 7 );
293297 assert (7 == BITScanForward (RIGHT_QUEEN_CASTLE_BLACK_MASK));
294298 rightCastle |= RIGHT_QUEEN_CASTLE_BLACK_MASK;
295299 blackRookQueenSideCastle = c;
@@ -347,7 +351,7 @@ int ChessBoard::loadFen(const string &fen) {
347351 } else {
348352 enPassant += 8 ;
349353 }
350- updateZobristKey (ENPASSANT_IDX , enPassant);
354+ updateZobristKey (ENPASSANT_RAND , enPassant);
351355 break ;
352356 }
353357 }
0 commit comments