No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
if (m == MOVE_NULL)
return "0000";
- if (move_is_castle(m) && !chess960)
+ if (is_castle(m) && !chess960)
to = from + (file_of(to) == FILE_H ? Square(2) : -Square(2));
- if (move_is_promotion(m))
+ if (is_promotion(m))
promotion = char(tolower(piece_type_to_char(promotion_piece_type(m))));
return square_to_string(from) + square_to_string(to) + promotion;
if (m == MOVE_NULL)
return "(null)";
- assert(move_is_ok(m));
+ assert(is_ok(m));
Bitboard attackers;
bool ambiguousMove, ambiguousFile, ambiguousRank;
PieceType pt = type_of(pos.piece_on(from));
string san;
- if (move_is_castle(m))
+ if (is_castle(m))
san = (move_to(m) < move_from(m) ? "O-O-O" : "O-O");
else
{
}
}
- if (pos.move_is_capture(m))
+ if (pos.is_capture(m))
{
if (pt == PAWN)
san += file_to_char(file_of(from));
san += square_to_string(to);
- if (move_is_promotion(m))
+ if (is_promotion(m))
{
san += '=';
san += piece_type_to_char(promotion_piece_type(m));
return Square(m & 0x3F);
}
-inline bool move_is_special(Move m) {
+inline bool is_special(Move m) {
return m & (3 << 14);
}
-inline bool move_is_promotion(Move m) {
+inline bool is_promotion(Move m) {
return (m & (3 << 14)) == (1 << 14);
}
-inline int move_is_ep(Move m) {
+inline int is_enpassant(Move m) {
return (m & (3 << 14)) == (2 << 14);
}
-inline int move_is_castle(Move m) {
+inline int is_castle(Move m) {
return (m & (3 << 14)) == (3 << 14);
}
return Move(to | (from << 6) | (1 << 14) | ((promotion - 2) << 12)) ;
}
-inline Move make_ep_move(Square from, Square to) {
+inline Move make_enpassant_move(Square from, Square to) {
return Move(to | (from << 6) | (2 << 14));
}
return Move(to | (from << 6) | (3 << 14));
}
-inline bool move_is_ok(Move m) {
+inline bool is_ok(Move m) {
return move_from(m) != move_to(m); // Catches also MOVE_NONE
}
while (b1)
{
to = pop_1st_bit(&b1);
- (*mlist++).move = make_ep_move(to, pos.ep_square());
+ (*mlist++).move = make_enpassant_move(to, pos.ep_square());
}
}
return mlist;
phasePtr = MainSearchTable;
}
- ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE);
+ ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
phasePtr += int(ttMove == MOVE_NONE) - 1;
go_next_phase();
}
// Skip TT move if is not a capture or a promotion, this avoids
// qsearch tree explosion due to a possible perpetual check or
// similar rare cases when TT table is full.
- if (ttm != MOVE_NONE && !pos.move_is_capture_or_promotion(ttm))
+ if (ttm != MOVE_NONE && !pos.is_capture_or_promotion(ttm))
ttm = MOVE_NONE;
}
else
ttm = MOVE_NONE;
}
- ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE);
+ ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
phasePtr += int(ttMove == MOVE_NONE) - 1;
go_next_phase();
}
phasePtr = ProbCutTable;
if ( ttm != MOVE_NONE
- && (!pos.move_is_capture(ttm) || pos.see(ttm) <= captureThreshold))
+ && (!pos.is_capture(ttm) || pos.see(ttm) <= captureThreshold))
ttm = MOVE_NONE;
- ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE);
+ ttMove = (ttm && pos.is_pseudo_legal(ttm) ? ttm : MOVE_NONE);
phasePtr += int(ttMove == MOVE_NONE) - 1;
go_next_phase();
}
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
- type_of(pos.piece_on(move_from(m)));
- if (move_is_promotion(m))
+ if (is_promotion(m))
cur->score += piece_value_midgame(Piece(promotion_piece_type(m)));
}
}
m = cur->move;
if ((seeScore = pos.see_sign(m)) < 0)
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
- else if (pos.move_is_capture(m))
+ else if (pos.is_capture(m))
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
- type_of(pos.piece_on(move_from(m))) + History::MaxValue;
else
case PH_KILLERS:
move = (curMove++)->move;
if ( move != MOVE_NONE
- && pos.move_is_pl(move)
+ && pos.is_pseudo_legal(move)
&& move != ttMove
- && !pos.move_is_capture(move))
+ && !pos.is_capture(move))
return move;
break;
bool Position::move_attacks_square(Move m, Square s) const {
- assert(move_is_ok(m));
+ assert(is_ok(m));
assert(square_is_ok(s));
Bitboard occ, xray;
bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
- assert(move_is_ok(m));
+ assert(is_ok(m));
assert(pinned == pinned_pieces());
Color us = side_to_move();
// En passant captures are a tricky special case. Because they are rather
// uncommon, we do it simply by testing whether the king is attacked after
// the move is made.
- if (move_is_ep(m))
+ if (is_enpassant(m))
{
Color them = flip(us);
Square to = move_to(m);
// square is attacked by the opponent. Castling moves are checked
// for legality during move generation.
if (type_of(piece_on(from)) == KING)
- return move_is_castle(m) || !(attackers_to(move_to(m)) & pieces(flip(us)));
+ return is_castle(m) || !(attackers_to(move_to(m)) & pieces(flip(us)));
// A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king.
}
-/// Position::move_is_legal() takes a move and tests whether the move
+/// Position::move_is_legal() takes a random move and tests whether the move
/// is legal. This version is not very fast and should be used only
/// in non time-critical paths.
}
-/// Fast version of Position::move_is_pl() that takes a move and a bitboard
-/// of pinned pieces as input, and tests whether the move is pseudo legal.
+/// Position::is_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::move_is_pl(const Move m) const {
+bool Position::is_pseudo_legal(const Move m) const {
Color us = sideToMove;
Color them = flip(sideToMove);
Piece pc = piece_on(from);
// Use a slower but simpler function for uncommon cases
- if (move_is_special(m))
+ if (is_special(m))
return move_is_legal(m);
// Is not a promotion, so promotion piece must be empty
}
-/// Position::move_gives_check() tests whether a pseudo-legal move is a check
+/// Position::move_gives_check() tests whether a pseudo-legal move gives a check
bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
- assert(move_is_ok(m));
+ assert(is_ok(m));
assert(ci.dcCandidates == discovered_check_candidates());
assert(color_of(piece_on(move_from(m))) == side_to_move());
}
// Can we skip the ugly special cases ?
- if (!move_is_special(m))
+ if (!is_special(m))
return false;
Color us = side_to_move();
Square ksq = king_square(flip(us));
// Promotion with check ?
- if (move_is_promotion(m))
+ if (is_promotion(m))
{
clear_bit(&b, from);
// of direct checks and ordinary discovered check, the only case we
// need to handle is the unusual case of a discovered check through
// the captured pawn.
- if (move_is_ep(m))
+ if (is_enpassant(m))
{
Square capsq = make_square(file_of(to), rank_of(from));
clear_bit(&b, from);
}
// Castling with check ?
- if (move_is_castle(m))
+ if (is_castle(m))
{
Square kfrom, kto, rfrom, rto;
kfrom = from;
void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
- assert(move_is_ok(m));
+ assert(is_ok(m));
assert(&newSt != st);
nodes++;
st->rule50++;
st->pliesFromNull++;
- if (move_is_castle(m))
+ if (is_castle(m))
{
st->key = key;
do_castle_move(m);
Color them = flip(us);
Square from = move_from(m);
Square to = move_to(m);
- bool ep = move_is_ep(m);
- bool pm = move_is_promotion(m);
+ bool ep = is_enpassant(m);
+ bool pm = is_promotion(m);
Piece piece = piece_on(from);
PieceType pt = type_of(piece);
void Position::do_castle_move(Move m) {
- assert(move_is_ok(m));
- assert(move_is_castle(m));
+ assert(is_ok(m));
+ assert(is_castle(m));
Color us = side_to_move();
Color them = flip(us);
void Position::undo_move(Move m) {
- assert(move_is_ok(m));
+ assert(is_ok(m));
sideToMove = flip(sideToMove);
- if (move_is_castle(m))
+ if (is_castle(m))
{
undo_castle_move(m);
return;
Color them = flip(us);
Square from = move_from(m);
Square to = move_to(m);
- bool ep = move_is_ep(m);
- bool pm = move_is_promotion(m);
+ bool ep = is_enpassant(m);
+ bool pm = is_promotion(m);
PieceType pt = type_of(piece_on(to));
void Position::undo_castle_move(Move m) {
- assert(move_is_ok(m));
- assert(move_is_castle(m));
+ assert(is_ok(m));
+ assert(is_castle(m));
// When we have arrived here, some work has already been done by
// Position::undo_move. In particular, the side to move has been switched,
int Position::see_sign(Move m) const {
- assert(move_is_ok(m));
+ assert(is_ok(m));
Square from = move_from(m);
Square to = move_to(m);
PieceType capturedType, pt;
Color stm;
- assert(move_is_ok(m));
+ assert(is_ok(m));
// As castle moves are implemented as capturing the rook, they have
// SEE == RookValueMidgame most of the times (unless the rook is under
// attack).
- if (move_is_castle(m))
+ if (is_castle(m))
return 0;
from = move_from(m);
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
// Properties of moves
- bool pl_move_is_legal(Move m, Bitboard pinned) const;
- bool move_is_pl(const Move m) const;
bool move_gives_check(Move m, const CheckInfo& ci) const;
- bool move_is_capture(Move m) const;
- bool move_is_capture_or_promotion(Move m) const;
- bool move_is_passed_pawn_push(Move m) const;
bool move_attacks_square(Move m, Square s) const;
+ bool pl_move_is_legal(Move m, Bitboard pinned) const;
+ bool is_pseudo_legal(const Move m) const;
+ bool is_capture(Move m) const;
+ bool is_capture_or_promotion(Move m) const;
+ bool is_passed_pawn_push(Move m) const;
// Piece captured with previous moves
PieceType captured_piece_type() const;
return st->npMaterial[c];
}
-inline bool Position::move_is_passed_pawn_push(Move m) const {
+inline bool Position::is_passed_pawn_push(Move m) const {
return board[move_from(m)] == make_piece(sideToMove, PAWN)
&& pawn_is_passed(sideToMove, move_to(m));
return chess960;
}
-inline bool Position::move_is_capture_or_promotion(Move m) const {
+inline bool Position::is_capture_or_promotion(Move m) const {
- assert(move_is_ok(m));
- return move_is_special(m) ? !move_is_castle(m) : !square_is_empty(move_to(m));
+ assert(is_ok(m));
+ return is_special(m) ? !is_castle(m) : !square_is_empty(move_to(m));
}
-inline bool Position::move_is_capture(Move m) const {
+inline bool Position::is_capture(Move m) const {
// Note that castle is coded as "king captures the rook"
- assert(move_is_ok(m));
- return (!square_is_empty(move_to(m)) && !move_is_castle(m)) || move_is_ep(m);
+ assert(is_ok(m));
+ return (!square_is_empty(move_to(m)) && !is_castle(m)) || is_enpassant(m);
}
inline PieceType Position::captured_piece_type() const {
&& type_of(pos.piece_on(move_to(m))) != PAWN
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
- piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
- && !move_is_special(m))
+ && !is_special(m))
{
result += PawnEndgameExtension[PvNode];
*dangerous = true;
if ( value >= beta
&& move
- && !pos.move_is_capture_or_promotion(move)
+ && !pos.is_capture_or_promotion(move)
&& move != ss->killers[0])
{
ss->killers[1] = ss->killers[0];
&& (move = mp.get_next_move()) != MOVE_NONE
&& !thread.cutoff_occurred())
{
- assert(move_is_ok(move));
+ assert(is_ok(move));
if (move == excludedMove)
continue;
// At Root and at first iteration do a PV search on all the moves to score root moves
isPvMove = (PvNode && moveCount <= (RootNode && depth <= ONE_PLY ? MAX_MOVES : 1));
givesCheck = pos.move_gives_check(move, ci);
- captureOrPromotion = pos.move_is_capture_or_promotion(move);
+ captureOrPromotion = pos.is_capture_or_promotion(move);
// Step 12. Decide the new search depth
ext = extension<PvNode>(pos, move, captureOrPromotion, givesCheck, &dangerous);
&& !inCheck
&& !dangerous
&& move != ttMove
- && !move_is_castle(move))
+ && !is_castle(move))
{
// Move count based pruning
if ( moveCount >= futility_move_count(depth)
if ( depth > 3 * ONE_PLY
&& !captureOrPromotion
&& !dangerous
- && !move_is_castle(move)
+ && !is_castle(move)
&& ss->killers[0] != move
&& ss->killers[1] != move
&& (ss->reduction = reduction<PvNode>(depth, moveCount)) != DEPTH_ZERO)
// Update killers and history only for non capture moves that fails high
if ( bestValue >= beta
- && !pos.move_is_capture_or_promotion(move))
+ && !pos.is_capture_or_promotion(move))
{
if (move != ss->killers[0])
{
while ( bestValue < beta
&& (move = mp.get_next_move()) != MOVE_NONE)
{
- assert(move_is_ok(move));
+ assert(is_ok(move));
givesCheck = pos.move_gives_check(move, ci);
&& !givesCheck
&& move != ttMove
&& enoughMaterial
- && !move_is_promotion(move)
- && !pos.move_is_passed_pawn_push(move))
+ && !is_promotion(move)
+ && !pos.is_passed_pawn_push(move))
{
futilityValue = futilityBase
+ piece_value_endgame(pos.piece_on(move_to(move)))
- + (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
+ + (is_enpassant(move) ? PawnValueEndgame : VALUE_ZERO);
if (futilityValue < beta)
{
evasionPrunable = !PvNode
&& inCheck
&& bestValue > VALUE_MATED_IN_PLY_MAX
- && !pos.move_is_capture(move)
+ && !pos.is_capture(move)
&& !pos.can_castle(pos.side_to_move());
// Don't search moves with negative SEE values
if ( !PvNode
&& (!inCheck || evasionPrunable)
&& move != ttMove
- && !move_is_promotion(move)
+ && !is_promotion(move)
&& pos.see_sign(move) < 0)
continue;
&& !inCheck
&& givesCheck
&& move != ttMove
- && !pos.move_is_capture_or_promotion(move)
+ && !pos.is_capture_or_promotion(move)
&& ss->eval + PawnValueMidgame / 4 < beta
&& !check_is_dangerous(pos, move, futilityBase, beta, &bestValue))
{
Piece p1, p2;
Square ksq;
- assert(move_is_ok(m1));
- assert(move_is_ok(m2));
+ assert(is_ok(m1));
+ assert(is_ok(m2));
// Case 1: The moving piece is the same in both moves
f2 = move_from(m2);
bool connected_threat(const Position& pos, Move m, Move threat) {
- assert(move_is_ok(m));
- assert(move_is_ok(threat));
- assert(!pos.move_is_capture_or_promotion(m));
- assert(!pos.move_is_passed_pawn_push(m));
+ assert(is_ok(m));
+ assert(is_ok(threat));
+ assert(!pos.is_capture_or_promotion(m));
+ assert(!pos.is_passed_pawn_push(m));
Square mfrom, mto, tfrom, tto;
// Case 2: If the threatened piece has value less than or equal to the
// value of the threatening piece, don't prune moves which defend it.
- if ( pos.move_is_capture(threat)
+ if ( pos.is_capture(threat)
&& ( piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
|| type_of(pos.piece_on(tfrom)) == KING)
&& pos.move_attacks_square(m, tto))
&& before != VALUE_NONE
&& after != VALUE_NONE
&& pos.captured_piece_type() == PIECE_TYPE_NONE
- && !move_is_special(m))
+ && !is_special(m))
H.update_gain(pos.piece_on(move_to(m)), move_to(m), -(before + after));
}
int ply = 1;
Move m = pv[0];
- assert(m != MOVE_NONE && pos.move_is_pl(m));
+ assert(m != MOVE_NONE && pos.is_pseudo_legal(m));
pv.clear();
pv.push_back(m);
while ( (tte = TT.probe(pos.get_key())) != NULL
&& tte->move() != MOVE_NONE
- && pos.move_is_pl(tte->move())
+ && pos.is_pseudo_legal(tte->move())
&& pos.pl_move_is_legal(tte->move(), pos.pinned_pieces())
&& ply < PLY_MAX
&& (!pos.is_draw<false>() || ply < 2))
Value v, m = VALUE_NONE;
int ply = 0;
- assert(pv[0] != MOVE_NONE && pos.move_is_pl(pv[0]));
+ assert(pv[0] != MOVE_NONE && pos.is_pseudo_legal(pv[0]));
do {
k = pos.get_key();