No functional change.
Resolves #131
#include "bitcount.h"
#include "rkiss.h"
-Bitboard RMasks[SQUARE_NB];
-Bitboard RMagics[SQUARE_NB];
-Bitboard* RAttacks[SQUARE_NB];
-unsigned RShifts[SQUARE_NB];
+Bitboard RookMasks[SQUARE_NB];
+Bitboard RookMagics[SQUARE_NB];
+Bitboard* RookAttacks[SQUARE_NB];
+unsigned RookShifts[SQUARE_NB];
-Bitboard BMasks[SQUARE_NB];
-Bitboard BMagics[SQUARE_NB];
-Bitboard* BAttacks[SQUARE_NB];
-unsigned BShifts[SQUARE_NB];
+Bitboard BishopMasks[SQUARE_NB];
+Bitboard BishopMagics[SQUARE_NB];
+Bitboard* BishopAttacks[SQUARE_NB];
+unsigned BishopShifts[SQUARE_NB];
Bitboard SquareBB[SQUARE_NB];
Bitboard FileBB[FILE_NB];
int MS1BTable[256];
Square BSFTable[SQUARE_NB];
- Bitboard RTable[0x19000]; // Storage space for rook attacks
- Bitboard BTable[0x1480]; // Storage space for bishop attacks
+ Bitboard RookTable[0x19000]; // Storage space for rook attacks
+ Bitboard BishopTable[0x1480]; // Storage space for bishop attacks
typedef unsigned (Fn)(Square, Bitboard);
StepAttacksBB[make_piece(c, pt)][s] |= to;
}
- Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
- Square BDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
+ Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
+ Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
- init_magics(RTable, RAttacks, RMagics, RMasks, RShifts, RDeltas, magic_index<ROOK>);
- init_magics(BTable, BAttacks, BMagics, BMasks, BShifts, BDeltas, magic_index<BISHOP>);
+ init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
+ init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
{
const Bitboard Rank7BB = Rank1BB << (8 * 6);
const Bitboard Rank8BB = Rank1BB << (8 * 7);
-extern Bitboard RMasks[SQUARE_NB];
-extern Bitboard RMagics[SQUARE_NB];
-extern Bitboard* RAttacks[SQUARE_NB];
-extern unsigned RShifts[SQUARE_NB];
+extern Bitboard RookMasks[SQUARE_NB];
+extern Bitboard RookMagics[SQUARE_NB];
+extern Bitboard* RookAttacks[SQUARE_NB];
+extern unsigned RookShifts[SQUARE_NB];
-extern Bitboard BMasks[SQUARE_NB];
-extern Bitboard BMagics[SQUARE_NB];
-extern Bitboard* BAttacks[SQUARE_NB];
-extern unsigned BShifts[SQUARE_NB];
+extern Bitboard BishopMasks[SQUARE_NB];
+extern Bitboard BishopMagics[SQUARE_NB];
+extern Bitboard* BishopAttacks[SQUARE_NB];
+extern unsigned BishopShifts[SQUARE_NB];
extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard FileBB[FILE_NB];
/// a square and a bitboard of occupied squares as input, and returns a bitboard
/// representing all squares attacked by Pt (bishop or rook) on the given square.
template<PieceType Pt>
-FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) {
+FORCE_INLINE unsigned magic_index(Square s, Bitboard occupied) {
- Bitboard* const Masks = Pt == ROOK ? RMasks : BMasks;
- Bitboard* const Magics = Pt == ROOK ? RMagics : BMagics;
- unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts;
+ Bitboard* const Masks = Pt == ROOK ? RookMasks : BishopMasks;
+ Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
+ unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts;
if (HasPext)
- return unsigned(_pext_u64(occ, Masks[s]));
+ return unsigned(_pext_u64(occupied, Masks[s]));
if (Is64Bit)
- return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]);
+ return unsigned(((occupied & Masks[s]) * Magics[s]) >> Shifts[s]);
- unsigned lo = unsigned(occ) & unsigned(Masks[s]);
- unsigned hi = unsigned(occ >> 32) & unsigned(Masks[s] >> 32);
+ unsigned lo = unsigned(occupied) & unsigned(Masks[s]);
+ unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32);
return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
}
template<PieceType Pt>
-inline Bitboard attacks_bb(Square s, Bitboard occ) {
- return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index<Pt>(s, occ)];
+inline Bitboard attacks_bb(Square s, Bitboard occupied) {
+ return (Pt == ROOK ? RookAttacks : BishopAttacks)[s][magic_index<Pt>(s, occupied)];
}
-inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occ) {
+inline Bitboard attacks_bb(Piece pc, Square s, Bitboard occupied) {
switch (type_of(pc))
{
- case BISHOP: return attacks_bb<BISHOP>(s, occ);
- case ROOK : return attacks_bb<ROOK>(s, occ);
- case QUEEN : return attacks_bb<BISHOP>(s, occ) | attacks_bb<ROOK>(s, occ);
+ case BISHOP: return attacks_bb<BISHOP>(s, occupied);
+ case ROOK : return attacks_bb<ROOK>(s, occupied);
+ case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
default : return StepAttacksBB[pc][s];
}
}
const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
#ifndef NDEBUG
- bool verify_material(const Position& pos, Color c, Value npm, int num_pawns) {
- return pos.non_pawn_material(c) == npm && pos.count<PAWN>(c) == num_pawns;
+ bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
+ return pos.non_pawn_material(c) == npm && pos.count<PAWN>(c) == pawnsCnt;
}
#endif
template<class Entry, int Size>
struct HashTable {
HashTable() : table(Size, Entry()) {}
- Entry* operator[](Key k) { return &table[(uint32_t)k & (Size - 1)]; }
+ Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
private:
std::vector<Entry> table;
namespace {
template<CastlingRight Cr, bool Checks, bool Chess960>
- ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) {
+ ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) {
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
- return mlist;
+ return moveList;
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
for (Square s = kto; s != kfrom; s += K)
if (pos.attackers_to(s) & enemies)
- return mlist;
+ return moveList;
// Because we generate only legal castling moves we need to verify that
// when moving the castling rook we do not discover some hidden checker.
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN)))
- return mlist;
+ return moveList;
Move m = make<CASTLING>(kfrom, rfrom);
if (Checks && !pos.gives_check(m, *ci))
- return mlist;
+ return moveList;
- (mlist++)->move = m;
+ (moveList++)->move = m;
- return mlist;
+ return moveList;
}
template<GenType Type, Square Delta>
- inline ExtMove* generate_promotions(ExtMove* mlist, Bitboard pawnsOn7,
+ inline ExtMove* generate_promotions(ExtMove* moveList, Bitboard pawnsOn7,
Bitboard target, const CheckInfo* ci) {
Bitboard b = shift_bb<Delta>(pawnsOn7) & target;
Square to = pop_lsb(&b);
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
- (mlist++)->move = make<PROMOTION>(to - Delta, to, QUEEN);
+ (moveList++)->move = make<PROMOTION>(to - Delta, to, QUEEN);
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
{
- (mlist++)->move = make<PROMOTION>(to - Delta, to, ROOK);
- (mlist++)->move = make<PROMOTION>(to - Delta, to, BISHOP);
- (mlist++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
+ (moveList++)->move = make<PROMOTION>(to - Delta, to, ROOK);
+ (moveList++)->move = make<PROMOTION>(to - Delta, to, BISHOP);
+ (moveList++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
}
// Knight promotion is the only promotion that can give a direct check
// that's not already included in the queen promotion.
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
- (mlist++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
+ (moveList++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
else
(void)ci; // Silence a warning under MSVC
}
- return mlist;
+ return moveList;
}
template<Color Us, GenType Type>
- ExtMove* generate_pawn_moves(const Position& pos, ExtMove* mlist,
+ ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList,
Bitboard target, const CheckInfo* ci) {
// Compute our parametrized parameters at compile time, named according to
while (b1)
{
Square to = pop_lsb(&b1);
- (mlist++)->move = make_move(to - Up, to);
+ (moveList++)->move = make_move(to - Up, to);
}
while (b2)
{
Square to = pop_lsb(&b2);
- (mlist++)->move = make_move(to - Up - Up, to);
+ (moveList++)->move = make_move(to - Up - Up, to);
}
}
if (Type == EVASIONS)
emptySquares &= target;
- mlist = generate_promotions<Type, Right>(mlist, pawnsOn7, enemies, ci);
- mlist = generate_promotions<Type, Left >(mlist, pawnsOn7, enemies, ci);
- mlist = generate_promotions<Type, Up>(mlist, pawnsOn7, emptySquares, ci);
+ moveList = generate_promotions<Type, Right>(moveList, pawnsOn7, enemies, ci);
+ moveList = generate_promotions<Type, Left >(moveList, pawnsOn7, enemies, ci);
+ moveList = generate_promotions<Type, Up>(moveList, pawnsOn7, emptySquares, ci);
}
// Standard and en-passant captures
while (b1)
{
Square to = pop_lsb(&b1);
- (mlist++)->move = make_move(to - Right, to);
+ (moveList++)->move = make_move(to - Right, to);
}
while (b2)
{
Square to = pop_lsb(&b2);
- (mlist++)->move = make_move(to - Left, to);
+ (moveList++)->move = make_move(to - Left, to);
}
if (pos.ep_square() != SQ_NONE)
// is the double pushed pawn and so is in the target. Otherwise this
// is a discovery check and we are forced to do otherwise.
if (Type == EVASIONS && !(target & (pos.ep_square() - Up)))
- return mlist;
+ return moveList;
b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them);
assert(b1);
while (b1)
- (mlist++)->move = make<ENPASSANT>(pop_lsb(&b1), pos.ep_square());
+ (moveList++)->move = make<ENPASSANT>(pop_lsb(&b1), pos.ep_square());
}
}
- return mlist;
+ return moveList;
}
template<PieceType Pt, bool Checks> FORCE_INLINE
- ExtMove* generate_moves(const Position& pos, ExtMove* mlist, Color us,
+ ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us,
Bitboard target, const CheckInfo* ci) {
assert(Pt != KING && Pt != PAWN);
b &= ci->checkSq[Pt];
while (b)
- (mlist++)->move = make_move(from, pop_lsb(&b));
+ (moveList++)->move = make_move(from, pop_lsb(&b));
}
- return mlist;
+ return moveList;
}
template<Color Us, GenType Type> FORCE_INLINE
- ExtMove* generate_all(const Position& pos, ExtMove* mlist, Bitboard target,
+ ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target,
const CheckInfo* ci = NULL) {
const bool Checks = Type == QUIET_CHECKS;
- mlist = generate_pawn_moves<Us, Type>(pos, mlist, target, ci);
- mlist = generate_moves<KNIGHT, Checks>(pos, mlist, Us, target, ci);
- mlist = generate_moves<BISHOP, Checks>(pos, mlist, Us, target, ci);
- mlist = generate_moves< ROOK, Checks>(pos, mlist, Us, target, ci);
- mlist = generate_moves< QUEEN, Checks>(pos, mlist, Us, target, ci);
+ moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
+ moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
+ moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
if (Type != QUIET_CHECKS && Type != EVASIONS)
{
Square ksq = pos.king_square(Us);
Bitboard b = pos.attacks_from<KING>(ksq) & target;
while (b)
- (mlist++)->move = make_move(ksq, pop_lsb(&b));
+ (moveList++)->move = make_move(ksq, pop_lsb(&b));
}
if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us))
{
if (pos.is_chess960())
{
- mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
- mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, mlist, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
}
else
{
- mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
- mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, mlist, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
+ moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
}
}
- return mlist;
+ return moveList;
}
/// non-captures. Returns a pointer to the end of the move list.
template<GenType Type>
-ExtMove* generate(const Position& pos, ExtMove* mlist) {
+ExtMove* generate(const Position& pos, ExtMove* moveList) {
assert(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
assert(!pos.checkers());
: Type == QUIETS ? ~pos.pieces()
: Type == NON_EVASIONS ? ~pos.pieces(us) : 0;
- return us == WHITE ? generate_all<WHITE, Type>(pos, mlist, target)
- : generate_all<BLACK, Type>(pos, mlist, target);
+ return us == WHITE ? generate_all<WHITE, Type>(pos, moveList, target)
+ : generate_all<BLACK, Type>(pos, moveList, target);
}
// Explicit template instantiations
/// generate<QUIET_CHECKS> generates all pseudo-legal non-captures and knight
/// underpromotions that give check. Returns a pointer to the end of the move list.
template<>
-ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* mlist) {
+ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
assert(!pos.checkers());
b &= ~PseudoAttacks[QUEEN][ci.ksq];
while (b)
- (mlist++)->move = make_move(from, pop_lsb(&b));
+ (moveList++)->move = make_move(from, pop_lsb(&b));
}
- return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, mlist, ~pos.pieces(), &ci)
- : generate_all<BLACK, QUIET_CHECKS>(pos, mlist, ~pos.pieces(), &ci);
+ return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci)
+ : generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci);
}
/// generate<EVASIONS> generates all pseudo-legal check evasions when the side
/// to move is in check. Returns a pointer to the end of the move list.
template<>
-ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) {
+ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
assert(pos.checkers());
// Generate evasions for king, capture and non capture moves
Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
while (b)
- (mlist++)->move = make_move(ksq, pop_lsb(&b));
+ (moveList++)->move = make_move(ksq, pop_lsb(&b));
if (more_than_one(pos.checkers()))
- return mlist; // Double check, only a king move can save the day
+ return moveList; // Double check, only a king move can save the day
// Generate blocking evasions or captures of the checking piece
Square checksq = lsb(pos.checkers());
Bitboard target = between_bb(checksq, ksq) | checksq;
- return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, mlist, target)
- : generate_all<BLACK, EVASIONS>(pos, mlist, target);
+ return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, moveList, target)
+ : generate_all<BLACK, EVASIONS>(pos, moveList, target);
}
/// generate<LEGAL> generates all the legal moves in the given position
template<>
-ExtMove* generate<LEGAL>(const Position& pos, ExtMove* mlist) {
+ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
- ExtMove *end, *cur = mlist;
+ ExtMove *end, *cur = moveList;
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
Square ksq = pos.king_square(pos.side_to_move());
- end = pos.checkers() ? generate<EVASIONS>(pos, mlist)
- : generate<NON_EVASIONS>(pos, mlist);
+ end = pos.checkers() ? generate<EVASIONS>(pos, moveList)
+ : generate<NON_EVASIONS>(pos, moveList);
while (cur != end)
if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT)
&& !pos.legal(cur->move, pinned))
class Position;
template<GenType>
-ExtMove* generate(const Position& pos, ExtMove* mlist);
+ExtMove* generate(const Position& pos, ExtMove* moveList);
/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
/// in handy to use this class instead of the low level generate() function.
template<GenType T>
struct MoveList {
- explicit MoveList(const Position& pos) : cur(mlist), last(generate<T>(pos, mlist)) { last->move = MOVE_NONE; }
+ explicit MoveList(const Position& pos) : cur(moveList), last(generate<T>(pos, moveList)) { last->move = MOVE_NONE; }
void operator++() { ++cur; }
Move operator*() const { return cur->move; }
- size_t size() const { return last - mlist; }
+ size_t size() const { return last - moveList; }
bool contains(Move m) const {
- for (const ExtMove* it(mlist); it != last; ++it) if (it->move == m) return true;
+ for (const ExtMove* it(moveList); it != last; ++it) if (it->move == m) return true;
return false;
}
private:
- ExtMove mlist[MAX_MOVES];
+ ExtMove moveList[MAX_MOVES];
ExtMove *cur, *last;
};
// Unary predicate used by std::partition to split positive values from remaining
// ones so as to sort the two sets separately, with the second sort delayed.
- inline bool has_positive_value(const ExtMove& ms) { return ms.value > 0; }
+ inline bool has_positive_value(const ExtMove& move) { return move.value > 0; }
// Picks the best move in the range (begin, end) and moves it to the front.
// It's faster than sorting all the moves in advance when there are few
kingSquares[Us] = ksq;
castlingRights[Us] = pos.can_castle(Us);
- minKPdistance[Us] = 0;
+ minKingPawnDistance[Us] = 0;
Bitboard pawns = pos.pieces(Us, PAWN);
if (pawns)
- while (!(DistanceRingsBB[ksq][minKPdistance[Us]++] & pawns)) {}
+ while (!(DistanceRingsBB[ksq][minKingPawnDistance[Us]++] & pawns)) {}
if (relative_rank(Us, ksq) > RANK_4)
- return make_score(0, -16 * minKPdistance[Us]);
+ return make_score(0, -16 * minKingPawnDistance[Us]);
Value bonus = shelter_storm<Us>(pos, ksq);
if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1)));
- return make_score(bonus, -16 * minKPdistance[Us]);
+ return make_score(bonus, -16 * minKingPawnDistance[Us]);
}
// Explicit template instantiation
Bitboard pawnAttacks[COLOR_NB];
Square kingSquares[COLOR_NB];
Score kingSafety[COLOR_NB];
- int minKPdistance[COLOR_NB];
+ int minKingPawnDistance[COLOR_NB];
int castlingRights[COLOR_NB];
int semiopenFiles[COLOR_NB];
int pawnSpan[COLOR_NB];
for (File f = FILE_A; f <= FILE_H; ++f)
Zobrist::enpassant[f] = rk.rand<Key>();
- for (int cf = NO_CASTLING; cf <= ANY_CASTLING; ++cf)
+ for (int cr = NO_CASTLING; cr <= ANY_CASTLING; ++cr)
{
- Bitboard b = cf;
+ Bitboard b = cr;
while (b)
{
Key k = Zobrist::castling[1ULL << pop_lsb(&b)];
- Zobrist::castling[cf] ^= k ? k : rk.rand<Key>();
+ Zobrist::castling[cr] ^= k ? k : rk.rand<Key>();
}
}
void Position::set_state(StateInfo* si) const {
si->key = si->pawnKey = si->materialKey = 0;
- si->npMaterial[WHITE] = si->npMaterial[BLACK] = VALUE_ZERO;
+ si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO;
si->psq = SCORE_ZERO;
si->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
for (Color c = WHITE; c <= BLACK; ++c)
for (PieceType pt = KNIGHT; pt <= QUEEN; ++pt)
- si->npMaterial[c] += pieceCount[c][pt] * PieceValue[MG][pt];
+ si->nonPawnMaterial[c] += pieceCount[c][pt] * PieceValue[MG][pt];
}
Phase Position::game_phase() const {
- Value npm = st->npMaterial[WHITE] + st->npMaterial[BLACK];
+ Value npm = st->nonPawnMaterial[WHITE] + st->nonPawnMaterial[BLACK];
npm = std::max(EndgameLimit, std::min(npm, MidgameLimit));
/// Position::attackers_to() computes a bitboard of all pieces which attack a
-/// given square. Slider attacks use the occ bitboard to indicate occupancy.
+/// given square. Slider attacks use the occupied bitboard to indicate occupancy.
-Bitboard Position::attackers_to(Square s, Bitboard occ) const {
+Bitboard Position::attackers_to(Square s, Bitboard occupied) const {
- 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))
- | (attacks_from<KING>(s) & pieces(KING));
+ 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, occupied) & pieces(ROOK, QUEEN))
+ | (attacks_bb<BISHOP>(s, occupied) & pieces(BISHOP, QUEEN))
+ | (attacks_from<KING>(s) & pieces(KING));
}
Square ksq = king_square(us);
Square to = to_sq(m);
Square capsq = to - pawn_push(us);
- Bitboard occ = (pieces() ^ from ^ capsq) | to;
+ Bitboard occupied = (pieces() ^ from ^ capsq) | to;
assert(to == ep_square());
assert(moved_piece(m) == make_piece(us, PAWN));
assert(piece_on(capsq) == make_piece(~us, PAWN));
assert(piece_on(to) == NO_PIECE);
- return !(attacks_bb< ROOK>(ksq, occ) & pieces(~us, QUEEN, ROOK))
- && !(attacks_bb<BISHOP>(ksq, occ) & pieces(~us, QUEEN, BISHOP));
+ return !(attacks_bb< ROOK>(ksq, occupied) & pieces(~us, QUEEN, ROOK))
+ && !(attacks_bb<BISHOP>(ksq, occupied) & pieces(~us, QUEEN, BISHOP));
}
// If the moving piece is a king, check whether the destination
st->pawnKey ^= Zobrist::psq[them][PAWN][capsq];
}
else
- st->npMaterial[them] -= PieceValue[MG][captured];
+ st->nonPawnMaterial[them] -= PieceValue[MG][captured];
// Update board and piece lists
remove_piece(capsq, them, captured);
st->psq += psq[us][promotion][to] - psq[us][PAWN][to];
// Update material
- st->npMaterial[us] += PieceValue[MG][promotion];
+ st->nonPawnMaterial[us] += PieceValue[MG][promotion];
}
// Update pawn hash key and prefetch access to pawnsTable
if ( st->key != si.key
|| st->pawnKey != si.pawnKey
|| st->materialKey != si.materialKey
- || st->npMaterial[WHITE] != si.npMaterial[WHITE]
- || st->npMaterial[BLACK] != si.npMaterial[BLACK]
+ || st->nonPawnMaterial[WHITE] != si.nonPawnMaterial[WHITE]
+ || st->nonPawnMaterial[BLACK] != si.nonPawnMaterial[BLACK]
|| st->psq != si.psq
|| st->checkersBB != si.checkersBB)
return false;
struct StateInfo {
Key pawnKey, materialKey;
- Value npMaterial[COLOR_NB];
+ Value nonPawnMaterial[COLOR_NB];
int castlingRights, rule50, pliesFromNull;
Score psq;
Square epSquare;
public:
Position() {}
- Position(const Position& pos, Thread* t) { *this = pos; thisThread = t; }
- Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); }
+ Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; }
+ Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); }
Position& operator=(const Position&);
static void init();
// Attacks to/from a given square
Bitboard attackers_to(Square s) const;
- Bitboard attackers_to(Square s, Bitboard occ) const;
+ Bitboard attackers_to(Square s, Bitboard occupied) const;
Bitboard attacks_from(Piece pc, Square s) const;
template<PieceType> Bitboard attacks_from(Square s) const;
template<PieceType> Bitboard attacks_from(Square s, Color c) const;
}
inline Value Position::non_pawn_material(Color c) const {
- return st->npMaterial[c];
+ return st->nonPawnMaterial[c];
}
inline int Position::game_ply() const {
TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move());
- int cf = Options["Contempt"] * PawnValueEg / 100; // From centipawns
- DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf);
- DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf);
+ int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
+ DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt);
+ DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt);
TB::Hits = 0;
TB::RootInTB = false;
// Save the last iteration's scores before first PV line is searched and
// all the move scores except the (new) PV are set to -VALUE_INFINITE.
for (size_t i = 0; i < RootMoves.size(); ++i)
- RootMoves[i].prevScore = RootMoves[i].score;
+ RootMoves[i].previousScore = RootMoves[i].score;
// MultiPV loop. We perform a full root search for each PV line
for (PVIdx = 0; PVIdx < std::min(multiPV, RootMoves.size()) && !Signals.stop; ++PVIdx)
if (depth >= 5 * ONE_PLY)
{
delta = Value(16);
- alpha = std::max(RootMoves[PVIdx].prevScore - delta,-VALUE_INFINITE);
- beta = std::min(RootMoves[PVIdx].prevScore + delta, VALUE_INFINITE);
+ alpha = std::max(RootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
+ beta = std::min(RootMoves[PVIdx].previousScore + delta, VALUE_INFINITE);
}
// Start with a small aspiration window and, in the case of a fail
SplitPoint* splitPoint;
Key posKey;
Move ttMove, move, excludedMove, bestMove;
- Depth ext, newDepth, predictedDepth;
+ Depth extension, newDepth, predictedDepth;
Value bestValue, value, ttValue, eval, nullValue, futilityValue;
bool inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, dangerous, doFullDepthSearch;
if (PvNode)
(ss+1)->pv = NULL;
- ext = DEPTH_ZERO;
+ extension = DEPTH_ZERO;
captureOrPromotion = pos.capture_or_promotion(move);
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
// Step 12. Extend checks
if (givesCheck && pos.see_sign(move) >= VALUE_ZERO)
- ext = ONE_PLY;
+ extension = ONE_PLY;
// Singular extension search. If all moves but one fail low on a search of
// (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move
// ttValue minus a margin then we extend the ttMove.
if ( singularExtensionNode
&& move == ttMove
- && !ext
+ && !extension
&& pos.legal(move, ci.pinned))
{
Value rBeta = ttValue - 2 * depth / ONE_PLY;
ss->excludedMove = MOVE_NONE;
if (value < rBeta)
- ext = ONE_PLY;
+ extension = ONE_PLY;
}
// Update the current move (this must be done after singular extension search)
- newDepth = depth - ONE_PLY + ext;
+ newDepth = depth - ONE_PLY + extension;
// Step 13. Pruning at shallow depth (exclude PV nodes)
if ( !PvNode
// RootMoves are already sorted by score in descending order
int variance = std::min(RootMoves[0].score - RootMoves[candidates - 1].score, PawnValueMg);
int weakness = 120 - 2 * level;
- int max_s = -VALUE_INFINITE;
+ int maxScore = -VALUE_INFINITE;
best = MOVE_NONE;
// Choose best move. For each move score we add two terms both dependent on
// then we choose the move with the resulting highest score.
for (size_t i = 0; i < candidates; ++i)
{
- int s = RootMoves[i].score;
+ int score = RootMoves[i].score;
// Don't allow crazy blunders even at very low skills
- if (i > 0 && RootMoves[i - 1].score > s + 2 * PawnValueMg)
+ if (i > 0 && RootMoves[i - 1].score > score + 2 * PawnValueMg)
break;
// This is our magic formula
- s += ( weakness * int(RootMoves[0].score - s)
- + variance * (rk.rand<unsigned>() % weakness)) / 128;
+ score += ( weakness * int(RootMoves[0].score - score)
+ + variance * (rk.rand<unsigned>() % weakness)) / 128;
- if (s > max_s)
+ if (score > maxScore)
{
- max_s = s;
+ maxScore = score;
best = RootMoves[i].pv[0];
}
}
continue;
Depth d = updated ? depth : depth - ONE_PLY;
- Value v = updated ? RootMoves[i].score : RootMoves[i].prevScore;
+ Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore;
bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
v = tb ? TB::Score : v;
/// all non-pv moves.
struct RootMove {
- RootMove(Move m) : score(-VALUE_INFINITE), prevScore(-VALUE_INFINITE), pv(1, m) {}
+ RootMove(Move m) : score(-VALUE_INFINITE), previousScore(-VALUE_INFINITE), pv(1, m) {}
bool operator<(const RootMove& m) const { return score > m.score; } // Ascending sort
bool operator==(const Move& m) const { return pv[0] == m; }
void insert_pv_in_tt(Position& pos);
Value score;
- Value prevScore;
+ Value previousScore;
std::vector<Move> pv;
};
}
-// wait_for() set the thread to sleep until condition 'b' turns true
+// wait_for() set the thread to sleep until 'condition' turns true
-void ThreadBase::wait_for(volatile const bool& b) {
+void ThreadBase::wait_for(volatile const bool& condition) {
mutex.lock();
- while (!b) sleepCondition.wait(mutex);
+ while (!condition) sleepCondition.wait(mutex);
mutex.unlock();
}
void ThreadPool::wait_for_think_finished() {
- MainThread* t = main();
- t->mutex.lock();
- while (t->thinking) sleepCondition.wait(t->mutex);
- t->mutex.unlock();
+ MainThread* th = main();
+ th->mutex.lock();
+ while (th->thinking) sleepCondition.wait(th->mutex);
+ th->mutex.unlock();
}