Also add some comments to the new operator~(Piece).
No functional change.
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = PAWN; pt <= KING; ++pt)
- for (Square s = SQ_A1; s <= SQ_H8; ++s)
- Zobrist::psq[make_piece(c, pt)][s] = rng.rand<Key>();
+ for (Piece pc : Pieces)
+ for (Square s = SQ_A1; s <= SQ_H8; ++s)
+ Zobrist::psq[pc][s] = rng.rand<Key>();
for (File f = FILE_A; f <= FILE_H; ++f)
Zobrist::enpassant[f] = rng.rand<Key>();
for (File f = FILE_A; f <= FILE_H; ++f)
Zobrist::enpassant[f] = rng.rand<Key>();
si->pawnKey ^= Zobrist::psq[piece_on(s)][s];
}
si->pawnKey ^= Zobrist::psq[piece_on(s)][s];
}
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = PAWN; pt <= KING; ++pt)
- for (int cnt = 0; cnt < pieceCount[make_piece(c, pt)]; ++cnt)
- si->materialKey ^= Zobrist::psq[make_piece(c, pt)][cnt];
+ for (Piece pc : Pieces)
+ {
+ if (type_of(pc) != PAWN && type_of(pc) != KING)
+ si->nonPawnMaterial[color_of(pc)] += pieceCount[pc] * PieceValue[MG][pc];
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = KNIGHT; pt <= QUEEN; ++pt)
- si->nonPawnMaterial[c] += pieceCount[make_piece(c, pt)] * PieceValue[MG][pt];
+ for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
+ si->materialKey ^= Zobrist::psq[pc][cnt];
+ }
- for (Color c = WHITE; c <= BLACK; ++c)
- for (PieceType pt = PAWN; pt <= KING; ++pt)
- {
- Piece pc = make_piece(c, pt);
+ for (Piece pc : Pieces)
+ {
+ if (pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc))))
+ return false;
- if (pieceCount[pc] != popcount(pieces(c, pt)))
+ for (int i = 0; i < pieceCount[pc]; ++i)
+ if (board[pieceList[pc][i]] != pc || index[pieceList[pc][i]] != i)
-
- for (int i = 0; i < pieceCount[pc]; ++i)
- if (board[pieceList[pc][i]] != pc || index[pieceList[pc][i]] != i)
- return false;
- }
if (step == Castling)
for (Color c = WHITE; c <= BLACK; ++c)
if (step == Castling)
for (Color c = WHITE; c <= BLACK; ++c)
+const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
+ B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
+
enum Depth {
ONE_PLY = 1,
enum Depth {
ONE_PLY = 1,
extern Value PieceValue[PHASE_NB][PIECE_NB];
inline Color operator~(Color c) {
extern Value PieceValue[PHASE_NB][PIECE_NB];
inline Color operator~(Color c) {
- return Color(c ^ BLACK);
+ return Color(c ^ BLACK); // Toggle color
}
inline Square operator~(Square s) {
}
inline Square operator~(Square s) {
}
inline Piece operator~(Piece pc) {
}
inline Piece operator~(Piece pc) {
+ return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
}
inline CastlingRight operator|(Color c, CastlingSide s) {
}
inline CastlingRight operator|(Color c, CastlingSide s) {