From: Marco Costalba Date: Mon, 3 Oct 2011 08:56:49 +0000 (+0100) Subject: Shrink names of move helpers X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=3141490374182551ed26f39ba4e3efb59589f057 Shrink names of move helpers No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/move.cpp b/src/move.cpp index 2a74aef1..b019110b 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -44,10 +44,10 @@ const string move_to_uci(Move m, bool chess960) { 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; @@ -80,7 +80,7 @@ const string move_to_san(Position& pos, Move m) { if (m == MOVE_NULL) return "(null)"; - assert(move_is_ok(m)); + assert(is_ok(m)); Bitboard attackers; bool ambiguousMove, ambiguousFile, ambiguousRank; @@ -89,7 +89,7 @@ const string move_to_san(Position& pos, Move m) { 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 { @@ -127,7 +127,7 @@ const string move_to_san(Position& pos, Move m) { } } - if (pos.move_is_capture(m)) + if (pos.is_capture(m)) { if (pt == PAWN) san += file_to_char(file_of(from)); @@ -137,7 +137,7 @@ const string move_to_san(Position& pos, Move m) { san += square_to_string(to); - if (move_is_promotion(m)) + if (is_promotion(m)) { san += '='; san += piece_type_to_char(promotion_piece_type(m)); diff --git a/src/move.h b/src/move.h index 443dc206..99e0c44d 100644 --- a/src/move.h +++ b/src/move.h @@ -82,19 +82,19 @@ inline Square move_to(Move 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); } @@ -110,7 +110,7 @@ inline Move make_promotion_move(Square from, Square to, PieceType promotion) { 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)); } @@ -118,7 +118,7 @@ inline Move make_castle_move(Square from, Square to) { 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 } diff --git a/src/movegen.cpp b/src/movegen.cpp index 501704ba..eb390cd1 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -489,7 +489,7 @@ namespace { 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; diff --git a/src/movepick.cpp b/src/movepick.cpp index 6bfe1457..88b4fe9c 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -96,7 +96,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, 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(); } @@ -117,7 +117,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, S // 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 @@ -127,7 +127,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, S 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(); } @@ -142,10 +142,10 @@ MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType 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(); } @@ -254,7 +254,7 @@ void MovePicker::score_captures() { 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))); } } @@ -289,7 +289,7 @@ void MovePicker::score_evasions() { 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 @@ -347,9 +347,9 @@ Move MovePicker::get_next_move() { 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; diff --git a/src/position.cpp b/src/position.cpp index 80fa16dd..b9acc645 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -458,7 +458,7 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) { 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; @@ -486,7 +486,7 @@ bool Position::move_attacks_square(Move m, Square s) const { 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(); @@ -498,7 +498,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { // 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); @@ -523,7 +523,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { // 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. @@ -533,7 +533,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { } -/// 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. @@ -547,10 +547,11 @@ bool Position::move_is_legal(const Move m) const { } -/// 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); @@ -559,7 +560,7 @@ bool Position::move_is_pl(const Move m) const { 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 @@ -670,11 +671,11 @@ bool Position::move_is_pl(const Move m) const { } -/// 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()); @@ -696,7 +697,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { } // Can we skip the ugly special cases ? - if (!move_is_special(m)) + if (!is_special(m)) return false; Color us = side_to_move(); @@ -704,7 +705,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { Square ksq = king_square(flip(us)); // Promotion with check ? - if (move_is_promotion(m)) + if (is_promotion(m)) { clear_bit(&b, from); @@ -727,7 +728,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { // 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); @@ -738,7 +739,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { } // Castling with check ? - if (move_is_castle(m)) + if (is_castle(m)) { Square kfrom, kto, rfrom, rto; kfrom = from; @@ -775,7 +776,7 @@ void Position::do_move(Move m, StateInfo& newSt) { 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++; @@ -805,7 +806,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->rule50++; st->pliesFromNull++; - if (move_is_castle(m)) + if (is_castle(m)) { st->key = key; do_castle_move(m); @@ -816,8 +817,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI 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); @@ -1044,8 +1045,8 @@ void Position::do_capture_move(Key& key, PieceType capture, Color them, Square t 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); @@ -1142,11 +1143,11 @@ void Position::do_castle_move(Move m) { 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; @@ -1156,8 +1157,8 @@ void Position::undo_move(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); PieceType pt = type_of(piece_on(to)); @@ -1245,8 +1246,8 @@ void Position::undo_move(Move m) { 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, @@ -1375,7 +1376,7 @@ void Position::undo_null_move() { 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); @@ -1397,12 +1398,12 @@ int Position::see(Move m) const { 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); diff --git a/src/position.h b/src/position.h index 8f253901..60f7f58f 100644 --- a/src/position.h +++ b/src/position.h @@ -148,13 +148,13 @@ public: template 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; @@ -415,7 +415,7 @@ inline Value Position::non_pawn_material(Color c) 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)); @@ -440,17 +440,17 @@ inline bool Position::is_chess960() const { 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 { diff --git a/src/search.cpp b/src/search.cpp index eea091d4..b22e82fe 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -289,7 +289,7 @@ namespace { && 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; @@ -783,7 +783,7 @@ namespace { 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]; @@ -972,7 +972,7 @@ split_point_start: // At split points actual search starts from here && (move = mp.get_next_move()) != MOVE_NONE && !thread.cutoff_occurred()) { - assert(move_is_ok(move)); + assert(is_ok(move)); if (move == excludedMove) continue; @@ -1013,7 +1013,7 @@ split_point_start: // At split points actual search starts from here // 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(pos, move, captureOrPromotion, givesCheck, &dangerous); @@ -1053,7 +1053,7 @@ split_point_start: // At split points actual search starts from here && !inCheck && !dangerous && move != ttMove - && !move_is_castle(move)) + && !is_castle(move)) { // Move count based pruning if ( moveCount >= futility_move_count(depth) @@ -1127,7 +1127,7 @@ split_point_start: // At split points actual search starts from here 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(depth, moveCount)) != DEPTH_ZERO) @@ -1252,7 +1252,7 @@ split_point_start: // At split points actual search starts from here // 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]) { @@ -1372,7 +1372,7 @@ split_point_start: // At split points actual search starts from here 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); @@ -1382,12 +1382,12 @@ split_point_start: // At split points actual search starts from here && !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) { @@ -1408,14 +1408,14 @@ split_point_start: // At split points actual search starts from here 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; @@ -1424,7 +1424,7 @@ split_point_start: // At split points actual search starts from here && !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)) { @@ -1548,8 +1548,8 @@ split_point_start: // At split points actual search starts from here 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); @@ -1624,10 +1624,10 @@ split_point_start: // At split points actual search starts from here 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; @@ -1642,7 +1642,7 @@ split_point_start: // At split points actual search starts from here // 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)) @@ -1722,7 +1722,7 @@ split_point_start: // At split points actual search starts from here && 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)); } @@ -2083,7 +2083,7 @@ split_point_start: // At split points actual search starts from here 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); @@ -2091,7 +2091,7 @@ split_point_start: // At split points actual search starts from here 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() || ply < 2)) @@ -2117,7 +2117,7 @@ split_point_start: // At split points actual search starts from here 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();