};
// To convert a Piece to and from a FEN char
-static const string PieceToChar(" PNBRQK pnbrqk .");
+static const string PieceToChar(" PNBRQK pnbrqk");
/// CheckInfo c'tor
sq += Square(token - '0'); // Advance the given number of files
else if (token == '/')
- sq = make_square(FILE_A, rank_of(sq) - Rank(2));
+ sq -= Square(16);
else if ((p = PieceToChar.find(token)) != string::npos)
{
for (rsq = relative_square(c, SQ_A1); type_of(piece_on(rsq)) != ROOK; rsq++) {}
else if (token >= 'A' && token <= 'H')
- rsq = make_square(File(token - 'A'), relative_rank(c, RANK_1));
+ rsq = File(token - 'A') | relative_rank(c, RANK_1);
else
continue;
if ( ((fen >> col) && (col >= 'a' && col <= 'h'))
&& ((fen >> row) && (row == '3' || row == '6')))
{
- st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
+ st->epSquare = File(col - 'a') | Rank(row - '1');
- if (!(attackers_to(st->epSquare) & pieces(PAWN, sideToMove)))
+ if (!(attackers_to(st->epSquare) & pieces(sideToMove, PAWN)))
st->epSquare = SQ_NONE;
}
for (File file = FILE_A; file <= FILE_H; file++)
{
- sq = make_square(file, rank);
+ sq = file | rank;
- if (square_empty(sq))
+ if (is_empty(sq))
emptyCnt++;
else
{
void Position::print(Move move) const {
- const char* dottedLine = "\n+---+---+---+---+---+---+---+---+\n";
+ const string dottedLine = "\n+---+---+---+---+---+---+---+---+";
+ const string twoRows = dottedLine + "\n| | . | | . | | . | | . |"
+ + dottedLine + "\n| . | | . | | . | | . | |";
+
+ string brd = twoRows + twoRows + twoRows + twoRows + dottedLine;
if (move)
{
cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
}
- for (Rank rank = RANK_8; rank >= RANK_1; rank--)
- {
- cout << dottedLine << '|';
- for (File file = FILE_A; file <= FILE_H; file++)
- {
- Square sq = make_square(file, rank);
- Piece piece = piece_on(sq);
- char c = (color_of(piece) == BLACK ? '=' : ' ');
-
- if (piece == NO_PIECE && !opposite_colors(sq, SQ_A1))
- piece++; // Index the dot
+ for (Square sq = SQ_A1; sq <= SQ_H8; sq++)
+ if (piece_on(sq) != NO_PIECE)
+ brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)];
- cout << c << PieceToChar[piece] << c << '|';
- }
- }
- cout << dottedLine << "Fen is: " << to_fen() << "\nKey is: " << st->key << endl;
+ cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl;
}
while (pinners)
{
- b = squares_between(ksq, pop_1st_bit(&pinners)) & pieces();
+ b = between_bb(ksq, pop_1st_bit(&pinners)) & pieces();
- if (b && single_bit(b) && (b & pieces(sideToMove)))
+ if (b && !more_than_one(b) && (b & pieces(sideToMove)))
result |= b;
}
return result;
Bitboard Position::attackers_to(Square s, Bitboard occ) const {
- return (attacks_from<PAWN>(s, BLACK) & pieces(PAWN, WHITE))
- | (attacks_from<PAWN>(s, WHITE) & pieces(PAWN, BLACK))
+ return (attacks_from<PAWN>(s, BLACK) & pieces(WHITE, PAWN))
+ | (attacks_from<PAWN>(s, WHITE) & pieces(BLACK, PAWN))
| (attacks_from<KNIGHT>(s) & pieces(KNIGHT))
| (attacks_bb<ROOK>(s, occ) & pieces(ROOK, QUEEN))
| (attacks_bb<BISHOP>(s, occ) & pieces(BISHOP, QUEEN))
Square to = to_sq(m);
Piece piece = piece_moved(m);
- assert(!square_empty(from));
+ assert(!is_empty(from));
// Update occupancy as if the piece is moving
occ = pieces() ^ from ^ to;
return true;
// Scan for possible X-ray attackers behind the moved piece
- xray = (attacks_bb<ROOK>(s, occ) & pieces(ROOK, QUEEN, color_of(piece)))
- |(attacks_bb<BISHOP>(s, occ) & pieces(BISHOP, QUEEN, color_of(piece)));
+ xray = (attacks_bb< ROOK>(s, occ) & pieces(color_of(piece), QUEEN, ROOK))
+ | (attacks_bb<BISHOP>(s, occ) & pieces(color_of(piece), QUEEN, BISHOP));
// Verify attackers are triggered by our move and not already existing
return xray && (xray ^ (xray & attacks_from<QUEEN>(s)));
assert(piece_on(capsq) == make_piece(them, PAWN));
assert(piece_on(to) == NO_PIECE);
- return !(attacks_bb<ROOK>(ksq, b) & pieces(ROOK, QUEEN, them))
- && !(attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, them));
+ return !(attacks_bb< ROOK>(ksq, b) & pieces(them, QUEEN, ROOK))
+ && !(attacks_bb<BISHOP>(ksq, b) & pieces(them, QUEEN, BISHOP));
}
// If the moving piece is a king, check whether the destination
case DELTA_N:
case DELTA_S:
// Pawn push. The destination square must be empty.
- if (!square_empty(to))
+ if (!is_empty(to))
return false;
break;
// Double white pawn push. The destination square must be on the fourth
// rank, and both the destination square and the square between the
// source and destination squares must be empty.
- if ( rank_of(to) != RANK_4
- || !square_empty(to)
- || !square_empty(from + DELTA_N))
+ if ( rank_of(to) != RANK_4
+ || !is_empty(to)
+ || !is_empty(from + DELTA_N))
return false;
break;
// Double black pawn push. The destination square must be on the fifth
// rank, and both the destination square and the square between the
// source and destination squares must be empty.
- if ( rank_of(to) != RANK_5
- || !square_empty(to)
- || !square_empty(from + DELTA_S))
+ if ( rank_of(to) != RANK_5
+ || !is_empty(to)
+ || !is_empty(from + DELTA_S))
return false;
break;
return false;
// Our move must be a blocking evasion or a capture of the checking piece
- if (!((squares_between(checksq, king_square(us)) | checkers()) & to))
+ if (!((between_bb(checksq, king_square(us)) | checkers()) & to))
return false;
}
// In case of king moves under check we have to remove king so to catch
if (ci.dcCandidates && (ci.dcCandidates & from))
{
// For pawn and king moves we need to verify also direction
- if ( (pt != PAWN && pt != KING)
+ if ( (pt != PAWN && pt != KING)
|| !squares_aligned(from, to, king_square(~sideToMove)))
return true;
}
// the captured pawn.
if (is_enpassant(m))
{
- Square capsq = make_square(file_of(to), rank_of(from));
+ Square capsq = file_of(to) | rank_of(from);
Bitboard b = (pieces() ^ from ^ capsq) | to;
- return (attacks_bb< ROOK>(ksq, b) & pieces( ROOK, QUEEN, us))
- | (attacks_bb<BISHOP>(ksq, b) & pieces(BISHOP, QUEEN, us));
+ return (attacks_bb< ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
+ | (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP));
}
// Castling with check ?
// Copy some fields of old state to our new StateInfo object except the ones
// which are recalculated from scratch anyway, then switch our state pointer
// to point to the new, ready to be updated, state.
- struct ReducedStateInfo {
- Key pawnKey, materialKey;
- Value npMaterial[2];
- int castleRights, rule50, pliesFromNull;
- Score psq_score;
- Square epSquare;
- };
-
memcpy(&newSt, st, sizeof(ReducedStateInfo));
newSt.previous = st;
{
// Set en-passant square, only if moved pawn can be captured
if ( (int(to) ^ int(from)) == 16
- && (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them)))
+ && (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(them, PAWN)))
{
st->epSquare = Square((from + to) / 2);
k ^= zobEp[file_of(st->epSquare)];
if (ci.dcCandidates && (ci.dcCandidates & from))
{
if (pt != ROOK)
- st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(ROOK, QUEEN, us);
+ st->checkersBB |= attacks_from<ROOK>(king_square(them)) & pieces(us, QUEEN, ROOK);
if (pt != BISHOP)
- st->checkersBB |= attacks_from<BISHOP>(king_square(them)) & pieces(BISHOP, QUEEN, us);
+ st->checkersBB |= attacks_from<BISHOP>(king_square(them)) & pieces(us, QUEEN, BISHOP);
}
}
}
PieceType pt = type_of(piece);
PieceType capture = st->capturedType;
- assert(square_empty(from));
+ assert(is_empty(from));
assert(color_of(piece) == us);
assert(capture != KING);
startPosPly = pos.startpos_ply_counter();
for (Square s = SQ_A1; s <= SQ_H8; s++)
- if (!pos.square_empty(s))
+ if (!pos.is_empty(s))
put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
if (pos.can_castle(WHITE_OO))
if ((*step)++, debugPieceCounts)
for (Color c = WHITE; c <= BLACK; c++)
for (PieceType pt = PAWN; pt <= KING; pt++)
- if (pieceCount[c][pt] != popcount<Full>(pieces(pt, c)))
+ if (pieceCount[c][pt] != popcount<Full>(pieces(c, pt)))
return false;
if ((*step)++, debugPieceList)