} // namespace
-/// operator<<(Position) returns an ASCII representation of the position
+// operator<<(Position) returns an ASCII representation of the position
std::ostream& operator<<(std::ostream& os, const Position& pos) {
}
-// Implements Marcel van Kervinck's cuckoo algorithm to detect repetition of positions
-// for 3-fold repetition draws. The algorithm uses two hash tables with Zobrist hashes to
-// allow fast detection of recurring positions. For details see:
+// Implements Marcel van Kervinck's cuckoo algorithm to detect repetition of positions
+// for 3-fold repetition draws. The algorithm uses two hash tables with Zobrist hashes
+// to allow fast detection of recurring positions. For details see:
// http://web.archive.org/web/20201107002606/https://marcelk.net/2013-04-06/paper/upcoming-rep-v2.pdf
// First and second hash functions for indexing the cuckoo tables
Move cuckooMove[8192];
-/// Position::init() initializes at startup the various arrays used to compute hash keys
+// Position::init() initializes at startup the various arrays used to compute hash keys
void Position::init() {
}
-/// Position::set() initializes the position object with the given FEN string.
-/// This function is not very robust - make sure that input FENs are correct,
-/// this is assumed to be the responsibility of the GUI.
+// Position::set() initializes the position object with the given FEN string.
+// This function is not very robust - make sure that input FENs are correct,
+// this is assumed to be the responsibility of the GUI.
Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Thread* th) {
/*
4) En passant target square (in algebraic notation). If there's no en passant
target square, this is "-". If a pawn has just made a 2-square move, this
- is the position "behind" the pawn. Following X-FEN standard, this is recorded only
- if there is a pawn in position to make an en passant capture, and if there really
- is a pawn that might have advanced two squares.
+ is the position "behind" the pawn. Following X-FEN standard, this is recorded
+ only if there is a pawn in position to make an en passant capture, and if
+ there really is a pawn that might have advanced two squares.
5) Halfmove clock. This is the number of halfmoves since the last pawn advance
or capture. This is used to determine if a draw can be claimed under the
}
-/// Position::set_castling_right() is a helper function used to set castling
-/// rights given the corresponding color and the rook starting square.
+// Position::set_castling_right() is a helper function used to set castling
+// rights given the corresponding color and the rook starting square.
void Position::set_castling_right(Color c, Square rfrom) {
}
-/// Position::set_check_info() sets king attacks to detect if a move gives check
+// Position::set_check_info() sets king attacks to detect if a move gives check
void Position::set_check_info() const {
}
-/// Position::set_state() computes the hash keys of the position, and other
-/// data that once computed is updated incrementally as moves are made.
-/// The function is only used when a new position is set up
+// Position::set_state() computes the hash keys of the position, and other
+// data that once computed is updated incrementally as moves are made.
+// The function is only used when a new position is set up
void Position::set_state() const {
}
-/// Position::set() is an overload to initialize the position object with
-/// the given endgame code string like "KBPKN". It is mainly a helper to
-/// get the material key out of an endgame code.
+// Position::set() is an overload to initialize the position object with
+// the given endgame code string like "KBPKN". It is mainly a helper to
+// get the material key out of an endgame code.
Position& Position::set(const string& code, Color c, StateInfo* si) {
}
-/// Position::fen() returns a FEN representation of the position. In case of
-/// Chess960 the Shredder-FEN notation is used. This is mainly a debugging function.
+// Position::fen() returns a FEN representation of the position. In case of
+// Chess960 the Shredder-FEN notation is used. This is mainly a debugging function.
string Position::fen() const {
return ss.str();
}
-/// update_slider_blockers() calculates st->blockersForKing[c] and st->pinners[~c],
-/// which store respectively the pieces preventing king of color c from being in check
-/// and the slider pieces of color ~c pinning pieces of color c to the king.
+// update_slider_blockers() calculates st->blockersForKing[c] and st->pinners[~c],
+// which store respectively the pieces preventing king of color c from being in check
+// and the slider pieces of color ~c pinning pieces of color c to the king.
void Position::update_slider_blockers(Color c) const {
Square ksq = square<KING>(c);
}
-/// Position::attackers_to() computes a bitboard of all pieces which attack a
-/// given square. Slider attacks use the occupied bitboard to indicate occupancy.
+// Position::attackers_to() computes a bitboard of all pieces which attack a
+// given square. Slider attacks use the occupied bitboard to indicate occupancy.
Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
}
-/// Position::legal() tests whether a pseudo-legal move is legal
+// Position::legal() tests whether a pseudo-legal move is legal
bool Position::legal(Move m) const {
if (attackers_to(s) & pieces(~us))
return false;
- // In case of Chess960, verify if the Rook blocks some checks
+ // In case of Chess960, verify if the Rook blocks some checks.
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
return !chess960 || !(blockers_for_king(us) & to_sq(m));
}
}
-/// Position::pseudo_legal() takes a random move and tests whether the move is
-/// pseudo-legal. It is used to validate moves from TT that can be corrupted
-/// due to SMP concurrent access or hash position key aliasing.
+// Position::pseudo_legal() takes a random move and tests whether the move is
+// pseudo-legal. It is used to validate moves from TT that can be corrupted
+// due to SMP concurrent access or hash position key aliasing.
bool Position::pseudo_legal(const Move m) const {
return false;
if ( !(pawn_attacks_bb(us, from) & pieces(~us) & to) // Not a capture
- && !((from + pawn_push(us) == to) && empty(to)) // Not a single push
- && !( (from + 2 * pawn_push(us) == to) // Not a double push
+ && !((from + pawn_push(us) == to) && empty(to)) // Not a single push
+ && !( (from + 2 * pawn_push(us) == to) // Not a double push
&& (relative_rank(us, from) == RANK_2)
&& empty(to)
&& empty(to - pawn_push(us))))
}
-/// Position::gives_check() tests whether a pseudo-legal move gives a check
+// Position::gives_check() tests whether a pseudo-legal move gives a check
bool Position::gives_check(Move m) const {
}
-/// Position::do_move() makes a move, and saves all information necessary
-/// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
-/// moves should be filtered out before this function is called.
+// Position::do_move() makes a move, and saves all information necessary
+// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
+// moves should be filtered out before this function is called.
void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
}
-/// Position::undo_move() unmakes a move. When it returns, the position should
-/// be restored to exactly the same state as before the move was made.
+// Position::undo_move() unmakes a move. When it returns, the position should
+// be restored to exactly the same state as before the move was made.
void Position::undo_move(Move m) {
}
-/// Position::do_castling() is a helper used to do/undo a castling move. This
-/// is a bit tricky in Chess960 where from/to squares can overlap.
+// Position::do_castling() is a helper used to do/undo a castling move. This
+// is a bit tricky in Chess960 where from/to squares can overlap.
template<bool Do>
void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Square& rto) {
// Remove both pieces first since squares could overlap in Chess960
remove_piece(Do ? from : to);
remove_piece(Do ? rfrom : rto);
- board[Do ? from : to] = board[Do ? rfrom : rto] = NO_PIECE; // Since remove_piece doesn't do this for us
+ board[Do ? from : to] = board[Do ? rfrom : rto] = NO_PIECE; // remove_piece does not do this for us
put_piece(make_piece(us, KING), Do ? to : from);
put_piece(make_piece(us, ROOK), Do ? rto : rfrom);
}
-/// Position::do_null_move() is used to do a "null move": it flips
-/// the side to move without executing any move on the board.
+// Position::do_null_move() is used to do a "null move": it flips
+// the side to move without executing any move on the board.
void Position::do_null_move(StateInfo& newSt) {
}
-/// Position::undo_null_move() must be used to undo a "null move"
+// Position::undo_null_move() must be used to undo a "null move"
void Position::undo_null_move() {
}
-/// Position::key_after() computes the new hash key after the given move. Needed
-/// for speculative prefetch. It doesn't recognize special moves like castling,
-/// en passant and promotions.
+// Position::key_after() computes the new hash key after the given move. Needed
+// for speculative prefetch. It doesn't recognize special moves like castling,
+// en passant and promotions.
Key Position::key_after(Move m) const {
}
-/// Position::see_ge (Static Exchange Evaluation Greater or Equal) tests if the
-/// SEE value of move is greater or equal to the given threshold. We'll use an
-/// algorithm similar to alpha-beta pruning with a null window.
+// Position::see_ge (Static Exchange Evaluation Greater or Equal) tests if the
+// SEE value of move is greater or equal to the given threshold. We'll use an
+// algorithm similar to alpha-beta pruning with a null window.
-bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
+bool Position::see_ge(Move m, Value threshold) const {
assert(is_ok(m));
return true;
assert(color_of(piece_on(from)) == sideToMove);
- occupied = pieces() ^ from ^ to; // xoring to is important for pinned piece logic
+ Bitboard occupied = pieces() ^ from ^ to; // xoring to is important for pinned piece logic
Color stm = sideToMove;
Bitboard attackers = attackers_to(to, occupied);
Bitboard stmAttackers, bb;
// the bitboard 'attackers' any X-ray attackers behind it.
if ((bb = stmAttackers & pieces(PAWN)))
{
- occupied ^= least_significant_square_bb(bb);
if ((swap = PawnValue - swap) < res)
break;
+ occupied ^= least_significant_square_bb(bb);
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
else if ((bb = stmAttackers & pieces(KNIGHT)))
{
- occupied ^= least_significant_square_bb(bb);
if ((swap = KnightValue - swap) < res)
break;
+ occupied ^= least_significant_square_bb(bb);
}
else if ((bb = stmAttackers & pieces(BISHOP)))
{
- occupied ^= least_significant_square_bb(bb);
if ((swap = BishopValue - swap) < res)
break;
+ occupied ^= least_significant_square_bb(bb);
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
}
else if ((bb = stmAttackers & pieces(ROOK)))
{
- occupied ^= least_significant_square_bb(bb);
if ((swap = RookValue - swap) < res)
break;
+ occupied ^= least_significant_square_bb(bb);
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
}
else if ((bb = stmAttackers & pieces(QUEEN)))
{
- occupied ^= least_significant_square_bb(bb);
if ((swap = QueenValue - swap) < res)
break;
+ occupied ^= least_significant_square_bb(bb);
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))
| (attacks_bb<ROOK >(to, occupied) & pieces(ROOK , QUEEN));
return bool(res);
}
-bool Position::see_ge(Move m, Value threshold) const {
- Bitboard occupied;
- return see_ge(m, occupied, threshold);
-}
-
-
-/// Position::is_draw() tests whether the position is drawn by 50-move rule
-/// or by repetition. It does not detect stalemates.
+// Position::is_draw() tests whether the position is drawn by 50-move rule
+// or by repetition. It does not detect stalemates.
bool Position::is_draw(int ply) const {
}
-/// Position::has_game_cycle() tests if the position has a move which draws by repetition,
-/// or an earlier position has a move that directly reaches the current position.
+// Position::has_game_cycle() tests if the position has a move which draws by repetition,
+// or an earlier position has a move that directly reaches the current position.
bool Position::has_game_cycle(int ply) const {
}
-/// Position::flip() flips position with the white and black sides reversed. This
-/// is only useful for debugging e.g. for finding evaluation symmetry bugs.
+// Position::flip() flips position with the white and black sides reversed. This
+// is only useful for debugging e.g. for finding evaluation symmetry bugs.
void Position::flip() {
}
-/// Position::pos_is_ok() performs some consistency checks for the
-/// position object and raise an assert if something wrong is detected.
-/// This is meant to be helpful when debugging.
+// Position::pos_is_ok() performs some consistency checks for the
+// position object and raise an assert if something wrong is detected.
+// This is meant to be helpful when debugging.
bool Position::pos_is_ok() const {