Rename some variables for more clarity.

No functional change.

Resolves #131
This commit is contained in:
hxim
2014-12-08 07:53:33 +08:00
committed by Gary Linscott
parent ba1464751d
commit fbb53524ef
14 changed files with 161 additions and 161 deletions
+14 -14
View File
@@ -24,15 +24,15 @@
#include "bitcount.h" #include "bitcount.h"
#include "rkiss.h" #include "rkiss.h"
Bitboard RMasks[SQUARE_NB]; Bitboard RookMasks[SQUARE_NB];
Bitboard RMagics[SQUARE_NB]; Bitboard RookMagics[SQUARE_NB];
Bitboard* RAttacks[SQUARE_NB]; Bitboard* RookAttacks[SQUARE_NB];
unsigned RShifts[SQUARE_NB]; unsigned RookShifts[SQUARE_NB];
Bitboard BMasks[SQUARE_NB]; Bitboard BishopMasks[SQUARE_NB];
Bitboard BMagics[SQUARE_NB]; Bitboard BishopMagics[SQUARE_NB];
Bitboard* BAttacks[SQUARE_NB]; Bitboard* BishopAttacks[SQUARE_NB];
unsigned BShifts[SQUARE_NB]; unsigned BishopShifts[SQUARE_NB];
Bitboard SquareBB[SQUARE_NB]; Bitboard SquareBB[SQUARE_NB];
Bitboard FileBB[FILE_NB]; Bitboard FileBB[FILE_NB];
@@ -58,8 +58,8 @@ namespace {
int MS1BTable[256]; int MS1BTable[256];
Square BSFTable[SQUARE_NB]; Square BSFTable[SQUARE_NB];
Bitboard RTable[0x19000]; // Storage space for rook attacks Bitboard RookTable[0x19000]; // Storage space for rook attacks
Bitboard BTable[0x1480]; // Storage space for bishop attacks Bitboard BishopTable[0x1480]; // Storage space for bishop attacks
typedef unsigned (Fn)(Square, Bitboard); typedef unsigned (Fn)(Square, Bitboard);
@@ -195,11 +195,11 @@ void Bitboards::init() {
StepAttacksBB[make_piece(c, pt)][s] |= to; StepAttacksBB[make_piece(c, pt)][s] |= to;
} }
Square RDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W }; Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W };
Square BDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW }; Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW };
init_magics(RTable, RAttacks, RMagics, RMasks, RShifts, RDeltas, magic_index<ROOK>); init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
init_magics(BTable, BAttacks, BMagics, BMasks, BShifts, BDeltas, magic_index<BISHOP>); init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1) for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
{ {
+22 -22
View File
@@ -57,15 +57,15 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5);
const Bitboard Rank7BB = Rank1BB << (8 * 6); const Bitboard Rank7BB = Rank1BB << (8 * 6);
const Bitboard Rank8BB = Rank1BB << (8 * 7); const Bitboard Rank8BB = Rank1BB << (8 * 7);
extern Bitboard RMasks[SQUARE_NB]; extern Bitboard RookMasks[SQUARE_NB];
extern Bitboard RMagics[SQUARE_NB]; extern Bitboard RookMagics[SQUARE_NB];
extern Bitboard* RAttacks[SQUARE_NB]; extern Bitboard* RookAttacks[SQUARE_NB];
extern unsigned RShifts[SQUARE_NB]; extern unsigned RookShifts[SQUARE_NB];
extern Bitboard BMasks[SQUARE_NB]; extern Bitboard BishopMasks[SQUARE_NB];
extern Bitboard BMagics[SQUARE_NB]; extern Bitboard BishopMagics[SQUARE_NB];
extern Bitboard* BAttacks[SQUARE_NB]; extern Bitboard* BishopAttacks[SQUARE_NB];
extern unsigned BShifts[SQUARE_NB]; extern unsigned BishopShifts[SQUARE_NB];
extern Bitboard SquareBB[SQUARE_NB]; extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard FileBB[FILE_NB]; extern Bitboard FileBB[FILE_NB];
@@ -230,35 +230,35 @@ inline bool aligned(Square s1, Square s2, Square s3) {
/// a square and a bitboard of occupied squares as input, and returns a bitboard /// 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. /// representing all squares attacked by Pt (bishop or rook) on the given square.
template<PieceType Pt> 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 Masks = Pt == ROOK ? RookMasks : BishopMasks;
Bitboard* const Magics = Pt == ROOK ? RMagics : BMagics; Bitboard* const Magics = Pt == ROOK ? RookMagics : BishopMagics;
unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts; unsigned* const Shifts = Pt == ROOK ? RookShifts : BishopShifts;
if (HasPext) if (HasPext)
return unsigned(_pext_u64(occ, Masks[s])); return unsigned(_pext_u64(occupied, Masks[s]));
if (Is64Bit) 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 lo = unsigned(occupied) & unsigned(Masks[s]);
unsigned hi = unsigned(occ >> 32) & unsigned(Masks[s] >> 32); unsigned hi = unsigned(occupied >> 32) & unsigned(Masks[s] >> 32);
return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s]; return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
} }
template<PieceType Pt> template<PieceType Pt>
inline Bitboard attacks_bb(Square s, Bitboard occ) { inline Bitboard attacks_bb(Square s, Bitboard occupied) {
return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index<Pt>(s, occ)]; 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)) switch (type_of(pc))
{ {
case BISHOP: return attacks_bb<BISHOP>(s, occ); case BISHOP: return attacks_bb<BISHOP>(s, occupied);
case ROOK : return attacks_bb<ROOK>(s, occ); case ROOK : return attacks_bb<ROOK>(s, occupied);
case QUEEN : return attacks_bb<BISHOP>(s, occ) | attacks_bb<ROOK>(s, occ); case QUEEN : return attacks_bb<BISHOP>(s, occupied) | attacks_bb<ROOK>(s, occupied);
default : return StepAttacksBB[pc][s]; default : return StepAttacksBB[pc][s];
} }
} }
+2 -2
View File
@@ -60,8 +60,8 @@ namespace {
const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 }; const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
#ifndef NDEBUG #ifndef NDEBUG
bool verify_material(const Position& pos, Color c, Value npm, int 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) == num_pawns; return pos.non_pawn_material(c) == npm && pos.count<PAWN>(c) == pawnsCnt;
} }
#endif #endif
+1 -1
View File
@@ -46,7 +46,7 @@ namespace Time {
template<class Entry, int Size> template<class Entry, int Size>
struct HashTable { struct HashTable {
HashTable() : table(Size, Entry()) {} 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: private:
std::vector<Entry> table; std::vector<Entry> table;
+56 -56
View File
@@ -25,12 +25,12 @@
namespace { namespace {
template<CastlingRight Cr, bool Checks, bool Chess960> 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); static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr)) 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 // After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess. // as they would be in standard chess.
@@ -46,27 +46,27 @@ namespace {
for (Square s = kto; s != kfrom; s += K) for (Square s = kto; s != kfrom; s += K)
if (pos.attackers_to(s) & enemies) if (pos.attackers_to(s) & enemies)
return mlist; return moveList;
// Because we generate only legal castling moves we need to verify that // Because we generate only legal castling moves we need to verify that
// when moving the castling rook we do not discover some hidden checker. // 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. // 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))) if (Chess960 && (attacks_bb<ROOK>(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN)))
return mlist; return moveList;
Move m = make<CASTLING>(kfrom, rfrom); Move m = make<CASTLING>(kfrom, rfrom);
if (Checks && !pos.gives_check(m, *ci)) 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> 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 target, const CheckInfo* ci) {
Bitboard b = shift_bb<Delta>(pawnsOn7) & target; Bitboard b = shift_bb<Delta>(pawnsOn7) & target;
@@ -76,29 +76,29 @@ namespace {
Square to = pop_lsb(&b); Square to = pop_lsb(&b);
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) 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) if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
{ {
(mlist++)->move = make<PROMOTION>(to - Delta, to, ROOK); (moveList++)->move = make<PROMOTION>(to - Delta, to, ROOK);
(mlist++)->move = make<PROMOTION>(to - Delta, to, BISHOP); (moveList++)->move = make<PROMOTION>(to - Delta, to, BISHOP);
(mlist++)->move = make<PROMOTION>(to - Delta, to, KNIGHT); (moveList++)->move = make<PROMOTION>(to - Delta, to, KNIGHT);
} }
// Knight promotion is the only promotion that can give a direct check // Knight promotion is the only promotion that can give a direct check
// that's not already included in the queen promotion. // that's not already included in the queen promotion.
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq)) 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 else
(void)ci; // Silence a warning under MSVC (void)ci; // Silence a warning under MSVC
} }
return mlist; return moveList;
} }
template<Color Us, GenType Type> 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) { Bitboard target, const CheckInfo* ci) {
// Compute our parametrized parameters at compile time, named according to // Compute our parametrized parameters at compile time, named according to
@@ -155,13 +155,13 @@ namespace {
while (b1) while (b1)
{ {
Square to = pop_lsb(&b1); Square to = pop_lsb(&b1);
(mlist++)->move = make_move(to - Up, to); (moveList++)->move = make_move(to - Up, to);
} }
while (b2) while (b2)
{ {
Square to = pop_lsb(&b2); Square to = pop_lsb(&b2);
(mlist++)->move = make_move(to - Up - Up, to); (moveList++)->move = make_move(to - Up - Up, to);
} }
} }
@@ -174,9 +174,9 @@ namespace {
if (Type == EVASIONS) if (Type == EVASIONS)
emptySquares &= target; emptySquares &= target;
mlist = generate_promotions<Type, Right>(mlist, pawnsOn7, enemies, ci); moveList = generate_promotions<Type, Right>(moveList, pawnsOn7, enemies, ci);
mlist = generate_promotions<Type, Left >(mlist, pawnsOn7, enemies, ci); moveList = generate_promotions<Type, Left >(moveList, pawnsOn7, enemies, ci);
mlist = generate_promotions<Type, Up>(mlist, pawnsOn7, emptySquares, ci); moveList = generate_promotions<Type, Up>(moveList, pawnsOn7, emptySquares, ci);
} }
// Standard and en-passant captures // Standard and en-passant captures
@@ -188,13 +188,13 @@ namespace {
while (b1) while (b1)
{ {
Square to = pop_lsb(&b1); Square to = pop_lsb(&b1);
(mlist++)->move = make_move(to - Right, to); (moveList++)->move = make_move(to - Right, to);
} }
while (b2) while (b2)
{ {
Square to = pop_lsb(&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) if (pos.ep_square() != SQ_NONE)
@@ -205,23 +205,23 @@ namespace {
// is the double pushed pawn and so is in the target. Otherwise this // is the double pushed pawn and so is in the target. Otherwise this
// is a discovery check and we are forced to do otherwise. // is a discovery check and we are forced to do otherwise.
if (Type == EVASIONS && !(target & (pos.ep_square() - Up))) if (Type == EVASIONS && !(target & (pos.ep_square() - Up)))
return mlist; return moveList;
b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them); b1 = pawnsNotOn7 & pos.attacks_from<PAWN>(pos.ep_square(), Them);
assert(b1); assert(b1);
while (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 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) { Bitboard target, const CheckInfo* ci) {
assert(Pt != KING && Pt != PAWN); assert(Pt != KING && Pt != PAWN);
@@ -246,48 +246,48 @@ namespace {
b &= ci->checkSq[Pt]; b &= ci->checkSq[Pt];
while (b) 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 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 CheckInfo* ci = NULL) {
const bool Checks = Type == QUIET_CHECKS; const bool Checks = Type == QUIET_CHECKS;
mlist = generate_pawn_moves<Us, Type>(pos, mlist, target, ci); moveList = generate_pawn_moves<Us, Type>(pos, moveList, target, ci);
mlist = generate_moves<KNIGHT, Checks>(pos, mlist, Us, target, ci); moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target, ci);
mlist = generate_moves<BISHOP, Checks>(pos, mlist, Us, target, ci); moveList = generate_moves<BISHOP, Checks>(pos, moveList, Us, target, ci);
mlist = generate_moves< ROOK, Checks>(pos, mlist, Us, target, ci); moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci);
mlist = generate_moves< QUEEN, Checks>(pos, mlist, Us, target, ci); moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci);
if (Type != QUIET_CHECKS && Type != EVASIONS) if (Type != QUIET_CHECKS && Type != EVASIONS)
{ {
Square ksq = pos.king_square(Us); Square ksq = pos.king_square(Us);
Bitboard b = pos.attacks_from<KING>(ksq) & target; Bitboard b = pos.attacks_from<KING>(ksq) & target;
while (b) 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 (Type != CAPTURES && Type != EVASIONS && pos.can_castle(Us))
{ {
if (pos.is_chess960()) if (pos.is_chess960())
{ {
mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, mlist, Us, ci); moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, mlist, Us, ci); moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, true>(pos, moveList, Us, ci);
} }
else else
{ {
mlist = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, mlist, Us, ci); moveList = generate_castling<MakeCastling<Us, KING_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
mlist = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, mlist, Us, ci); moveList = generate_castling<MakeCastling<Us, QUEEN_SIDE>::right, Checks, false>(pos, moveList, Us, ci);
} }
} }
return mlist; return moveList;
} }
@@ -304,7 +304,7 @@ namespace {
/// non-captures. Returns a pointer to the end of the move list. /// non-captures. Returns a pointer to the end of the move list.
template<GenType Type> 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(Type == CAPTURES || Type == QUIETS || Type == NON_EVASIONS);
assert(!pos.checkers()); assert(!pos.checkers());
@@ -315,8 +315,8 @@ ExtMove* generate(const Position& pos, ExtMove* mlist) {
: Type == QUIETS ? ~pos.pieces() : Type == QUIETS ? ~pos.pieces()
: Type == NON_EVASIONS ? ~pos.pieces(us) : 0; : Type == NON_EVASIONS ? ~pos.pieces(us) : 0;
return us == WHITE ? generate_all<WHITE, Type>(pos, mlist, target) return us == WHITE ? generate_all<WHITE, Type>(pos, moveList, target)
: generate_all<BLACK, Type>(pos, mlist, target); : generate_all<BLACK, Type>(pos, moveList, target);
} }
// Explicit template instantiations // Explicit template instantiations
@@ -328,7 +328,7 @@ template ExtMove* generate<NON_EVASIONS>(const Position&, ExtMove*);
/// generate<QUIET_CHECKS> generates all pseudo-legal non-captures and knight /// 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. /// underpromotions that give check. Returns a pointer to the end of the move list.
template<> template<>
ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* mlist) { ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
assert(!pos.checkers()); assert(!pos.checkers());
@@ -350,18 +350,18 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* mlist) {
b &= ~PseudoAttacks[QUEEN][ci.ksq]; b &= ~PseudoAttacks[QUEEN][ci.ksq];
while (b) 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) return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci)
: generate_all<BLACK, QUIET_CHECKS>(pos, mlist, ~pos.pieces(), &ci); : generate_all<BLACK, QUIET_CHECKS>(pos, moveList, ~pos.pieces(), &ci);
} }
/// generate<EVASIONS> generates all pseudo-legal check evasions when the side /// 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. /// to move is in check. Returns a pointer to the end of the move list.
template<> template<>
ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) { ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
assert(pos.checkers()); assert(pos.checkers());
@@ -382,31 +382,31 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) {
// Generate evasions for king, capture and non capture moves // Generate evasions for king, capture and non capture moves
Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks; Bitboard b = pos.attacks_from<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
while (b) while (b)
(mlist++)->move = make_move(ksq, pop_lsb(&b)); (moveList++)->move = make_move(ksq, pop_lsb(&b));
if (more_than_one(pos.checkers())) 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 // Generate blocking evasions or captures of the checking piece
Square checksq = lsb(pos.checkers()); Square checksq = lsb(pos.checkers());
Bitboard target = between_bb(checksq, ksq) | checksq; Bitboard target = between_bb(checksq, ksq) | checksq;
return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, mlist, target) return us == WHITE ? generate_all<WHITE, EVASIONS>(pos, moveList, target)
: generate_all<BLACK, EVASIONS>(pos, mlist, target); : generate_all<BLACK, EVASIONS>(pos, moveList, target);
} }
/// generate<LEGAL> generates all the legal moves in the given position /// generate<LEGAL> generates all the legal moves in the given position
template<> 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()); Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
Square ksq = pos.king_square(pos.side_to_move()); Square ksq = pos.king_square(pos.side_to_move());
end = pos.checkers() ? generate<EVASIONS>(pos, mlist) end = pos.checkers() ? generate<EVASIONS>(pos, moveList)
: generate<NON_EVASIONS>(pos, mlist); : generate<NON_EVASIONS>(pos, moveList);
while (cur != end) while (cur != end)
if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT) if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT)
&& !pos.legal(cur->move, pinned)) && !pos.legal(cur->move, pinned))
+5 -5
View File
@@ -34,24 +34,24 @@ enum GenType {
class Position; class Position;
template<GenType> 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 /// 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. /// in handy to use this class instead of the low level generate() function.
template<GenType T> template<GenType T>
struct MoveList { 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; } void operator++() { ++cur; }
Move operator*() const { return cur->move; } 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 { 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; return false;
} }
private: private:
ExtMove mlist[MAX_MOVES]; ExtMove moveList[MAX_MOVES];
ExtMove *cur, *last; ExtMove *cur, *last;
}; };
+1 -1
View File
@@ -51,7 +51,7 @@ namespace {
// Unary predicate used by std::partition to split positive values from remaining // 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. // 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. // 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 // It's faster than sorting all the moves in advance when there are few
+4 -4
View File
@@ -268,14 +268,14 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) {
kingSquares[Us] = ksq; kingSquares[Us] = ksq;
castlingRights[Us] = pos.can_castle(Us); castlingRights[Us] = pos.can_castle(Us);
minKPdistance[Us] = 0; minKingPawnDistance[Us] = 0;
Bitboard pawns = pos.pieces(Us, PAWN); Bitboard pawns = pos.pieces(Us, PAWN);
if (pawns) if (pawns)
while (!(DistanceRingsBB[ksq][minKPdistance[Us]++] & pawns)) {} while (!(DistanceRingsBB[ksq][minKingPawnDistance[Us]++] & pawns)) {}
if (relative_rank(Us, ksq) > RANK_4) 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); Value bonus = shelter_storm<Us>(pos, ksq);
@@ -286,7 +286,7 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) {
if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right)) if (pos.can_castle(MakeCastling<Us, QUEEN_SIDE>::right))
bonus = std::max(bonus, shelter_storm<Us>(pos, relative_square(Us, SQ_C1))); 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 // Explicit template instantiation
+1 -1
View File
@@ -70,7 +70,7 @@ struct Entry {
Bitboard pawnAttacks[COLOR_NB]; Bitboard pawnAttacks[COLOR_NB];
Square kingSquares[COLOR_NB]; Square kingSquares[COLOR_NB];
Score kingSafety[COLOR_NB]; Score kingSafety[COLOR_NB];
int minKPdistance[COLOR_NB]; int minKingPawnDistance[COLOR_NB];
int castlingRights[COLOR_NB]; int castlingRights[COLOR_NB];
int semiopenFiles[COLOR_NB]; int semiopenFiles[COLOR_NB];
int pawnSpan[COLOR_NB]; int pawnSpan[COLOR_NB];
+21 -21
View File
@@ -147,13 +147,13 @@ void Position::init() {
for (File f = FILE_A; f <= FILE_H; ++f) for (File f = FILE_A; f <= FILE_H; ++f)
Zobrist::enpassant[f] = rk.rand<Key>(); 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) while (b)
{ {
Key k = Zobrist::castling[1ULL << pop_lsb(&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>();
} }
} }
@@ -363,7 +363,7 @@ void Position::set_castling_right(Color c, Square rfrom) {
void Position::set_state(StateInfo* si) const { void Position::set_state(StateInfo* si) const {
si->key = si->pawnKey = si->materialKey = 0; 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->psq = SCORE_ZERO;
si->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove); si->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
@@ -397,7 +397,7 @@ void Position::set_state(StateInfo* si) const {
for (Color c = WHITE; c <= BLACK; ++c) for (Color c = WHITE; c <= BLACK; ++c)
for (PieceType pt = KNIGHT; pt <= QUEEN; ++pt) 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];
} }
@@ -456,7 +456,7 @@ const string Position::fen() const {
Phase Position::game_phase() const { 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)); npm = std::max(EndgameLimit, std::min(npm, MidgameLimit));
@@ -492,16 +492,16 @@ Bitboard Position::check_blockers(Color c, Color kingColor) const {
/// Position::attackers_to() computes a bitboard of all pieces which attack a /// 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)) return (attacks_from<PAWN>(s, BLACK) & pieces(WHITE, PAWN))
| (attacks_from<PAWN>(s, WHITE) & pieces(BLACK, PAWN)) | (attacks_from<PAWN>(s, WHITE) & pieces(BLACK, PAWN))
| (attacks_from<KNIGHT>(s) & pieces(KNIGHT)) | (attacks_from<KNIGHT>(s) & pieces(KNIGHT))
| (attacks_bb<ROOK>(s, occ) & pieces(ROOK, QUEEN)) | (attacks_bb<ROOK>(s, occupied) & pieces(ROOK, QUEEN))
| (attacks_bb<BISHOP>(s, occ) & pieces(BISHOP, QUEEN)) | (attacks_bb<BISHOP>(s, occupied) & pieces(BISHOP, QUEEN))
| (attacks_from<KING>(s) & pieces(KING)); | (attacks_from<KING>(s) & pieces(KING));
} }
@@ -526,15 +526,15 @@ bool Position::legal(Move m, Bitboard pinned) const {
Square ksq = king_square(us); Square ksq = king_square(us);
Square to = to_sq(m); Square to = to_sq(m);
Square capsq = to - pawn_push(us); Square capsq = to - pawn_push(us);
Bitboard occ = (pieces() ^ from ^ capsq) | to; Bitboard occupied = (pieces() ^ from ^ capsq) | to;
assert(to == ep_square()); assert(to == ep_square());
assert(moved_piece(m) == make_piece(us, PAWN)); assert(moved_piece(m) == make_piece(us, PAWN));
assert(piece_on(capsq) == make_piece(~us, PAWN)); assert(piece_on(capsq) == make_piece(~us, PAWN));
assert(piece_on(to) == NO_PIECE); assert(piece_on(to) == NO_PIECE);
return !(attacks_bb< ROOK>(ksq, occ) & pieces(~us, QUEEN, ROOK)) return !(attacks_bb< ROOK>(ksq, occupied) & pieces(~us, QUEEN, ROOK))
&& !(attacks_bb<BISHOP>(ksq, occ) & pieces(~us, QUEEN, BISHOP)); && !(attacks_bb<BISHOP>(ksq, occupied) & pieces(~us, QUEEN, BISHOP));
} }
// If the moving piece is a king, check whether the destination // If the moving piece is a king, check whether the destination
@@ -767,7 +767,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->pawnKey ^= Zobrist::psq[them][PAWN][capsq]; st->pawnKey ^= Zobrist::psq[them][PAWN][capsq];
} }
else else
st->npMaterial[them] -= PieceValue[MG][captured]; st->nonPawnMaterial[them] -= PieceValue[MG][captured];
// Update board and piece lists // Update board and piece lists
remove_piece(capsq, them, captured); remove_piece(capsq, them, captured);
@@ -837,7 +837,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->psq += psq[us][promotion][to] - psq[us][PAWN][to]; st->psq += psq[us][promotion][to] - psq[us][PAWN][to];
// Update material // Update material
st->npMaterial[us] += PieceValue[MG][promotion]; st->nonPawnMaterial[us] += PieceValue[MG][promotion];
} }
// Update pawn hash key and prefetch access to pawnsTable // Update pawn hash key and prefetch access to pawnsTable
@@ -1234,8 +1234,8 @@ bool Position::pos_is_ok(int* step) const {
if ( st->key != si.key if ( st->key != si.key
|| st->pawnKey != si.pawnKey || st->pawnKey != si.pawnKey
|| st->materialKey != si.materialKey || st->materialKey != si.materialKey
|| st->npMaterial[WHITE] != si.npMaterial[WHITE] || st->nonPawnMaterial[WHITE] != si.nonPawnMaterial[WHITE]
|| st->npMaterial[BLACK] != si.npMaterial[BLACK] || st->nonPawnMaterial[BLACK] != si.nonPawnMaterial[BLACK]
|| st->psq != si.psq || st->psq != si.psq
|| st->checkersBB != si.checkersBB) || st->checkersBB != si.checkersBB)
return false; return false;
+5 -5
View File
@@ -50,7 +50,7 @@ struct CheckInfo {
struct StateInfo { struct StateInfo {
Key pawnKey, materialKey; Key pawnKey, materialKey;
Value npMaterial[COLOR_NB]; Value nonPawnMaterial[COLOR_NB];
int castlingRights, rule50, pliesFromNull; int castlingRights, rule50, pliesFromNull;
Score psq; Score psq;
Square epSquare; Square epSquare;
@@ -78,8 +78,8 @@ class Position {
public: public:
Position() {} Position() {}
Position(const Position& pos, Thread* t) { *this = pos; thisThread = t; } Position(const Position& pos, Thread* th) { *this = pos; thisThread = th; }
Position(const std::string& f, bool c960, Thread* t) { set(f, c960, t); } Position(const std::string& f, bool c960, Thread* th) { set(f, c960, th); }
Position& operator=(const Position&); Position& operator=(const Position&);
static void init(); static void init();
@@ -114,7 +114,7 @@ public:
// Attacks to/from a given square // Attacks to/from a given square
Bitboard attackers_to(Square s) const; 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; Bitboard attacks_from(Piece pc, Square s) const;
template<PieceType> Bitboard attacks_from(Square s) const; template<PieceType> Bitboard attacks_from(Square s) const;
template<PieceType> Bitboard attacks_from(Square s, Color c) const; template<PieceType> Bitboard attacks_from(Square s, Color c) const;
@@ -346,7 +346,7 @@ inline Score Position::psq_score() const {
} }
inline Value Position::non_pawn_material(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 { inline int Position::game_ply() const {
+20 -20
View File
@@ -195,9 +195,9 @@ void Search::think() {
TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move()); TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move());
int cf = Options["Contempt"] * PawnValueEg / 100; // From centipawns int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf); DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(contempt);
DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf); DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(contempt);
TB::Hits = 0; TB::Hits = 0;
TB::RootInTB = false; TB::RootInTB = false;
@@ -324,7 +324,7 @@ namespace {
// Save the last iteration's scores before first PV line is searched and // 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. // all the move scores except the (new) PV are set to -VALUE_INFINITE.
for (size_t i = 0; i < RootMoves.size(); ++i) 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 // MultiPV loop. We perform a full root search for each PV line
for (PVIdx = 0; PVIdx < std::min(multiPV, RootMoves.size()) && !Signals.stop; ++PVIdx) for (PVIdx = 0; PVIdx < std::min(multiPV, RootMoves.size()) && !Signals.stop; ++PVIdx)
@@ -333,8 +333,8 @@ namespace {
if (depth >= 5 * ONE_PLY) if (depth >= 5 * ONE_PLY)
{ {
delta = Value(16); delta = Value(16);
alpha = std::max(RootMoves[PVIdx].prevScore - delta,-VALUE_INFINITE); alpha = std::max(RootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
beta = std::min(RootMoves[PVIdx].prevScore + 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 // Start with a small aspiration window and, in the case of a fail
@@ -461,7 +461,7 @@ namespace {
SplitPoint* splitPoint; SplitPoint* splitPoint;
Key posKey; Key posKey;
Move ttMove, move, excludedMove, bestMove; Move ttMove, move, excludedMove, bestMove;
Depth ext, newDepth, predictedDepth; Depth extension, newDepth, predictedDepth;
Value bestValue, value, ttValue, eval, nullValue, futilityValue; Value bestValue, value, ttValue, eval, nullValue, futilityValue;
bool inCheck, givesCheck, singularExtensionNode, improving; bool inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, dangerous, doFullDepthSearch; bool captureOrPromotion, dangerous, doFullDepthSearch;
@@ -789,7 +789,7 @@ moves_loop: // When in check and at SpNode search starts from here
if (PvNode) if (PvNode)
(ss+1)->pv = NULL; (ss+1)->pv = NULL;
ext = DEPTH_ZERO; extension = DEPTH_ZERO;
captureOrPromotion = pos.capture_or_promotion(move); captureOrPromotion = pos.capture_or_promotion(move);
givesCheck = type_of(move) == NORMAL && !ci.dcCandidates givesCheck = type_of(move) == NORMAL && !ci.dcCandidates
@@ -802,7 +802,7 @@ moves_loop: // When in check and at SpNode search starts from here
// Step 12. Extend checks // Step 12. Extend checks
if (givesCheck && pos.see_sign(move) >= VALUE_ZERO) 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 // 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 // (alpha-s, beta-s), and just one fails high on (alpha, beta), then that move
@@ -811,7 +811,7 @@ moves_loop: // When in check and at SpNode search starts from here
// ttValue minus a margin then we extend the ttMove. // ttValue minus a margin then we extend the ttMove.
if ( singularExtensionNode if ( singularExtensionNode
&& move == ttMove && move == ttMove
&& !ext && !extension
&& pos.legal(move, ci.pinned)) && pos.legal(move, ci.pinned))
{ {
Value rBeta = ttValue - 2 * depth / ONE_PLY; Value rBeta = ttValue - 2 * depth / ONE_PLY;
@@ -822,11 +822,11 @@ moves_loop: // When in check and at SpNode search starts from here
ss->excludedMove = MOVE_NONE; ss->excludedMove = MOVE_NONE;
if (value < rBeta) if (value < rBeta)
ext = ONE_PLY; extension = ONE_PLY;
} }
// Update the current move (this must be done after singular extension search) // 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) // Step 13. Pruning at shallow depth (exclude PV nodes)
if ( !PvNode if ( !PvNode
@@ -1386,7 +1386,7 @@ moves_loop: // When in check and at SpNode search starts from here
// RootMoves are already sorted by score in descending order // RootMoves are already sorted by score in descending order
int variance = std::min(RootMoves[0].score - RootMoves[candidates - 1].score, PawnValueMg); int variance = std::min(RootMoves[0].score - RootMoves[candidates - 1].score, PawnValueMg);
int weakness = 120 - 2 * level; int weakness = 120 - 2 * level;
int max_s = -VALUE_INFINITE; int maxScore = -VALUE_INFINITE;
best = MOVE_NONE; best = MOVE_NONE;
// Choose best move. For each move score we add two terms both dependent on // Choose best move. For each move score we add two terms both dependent on
@@ -1394,19 +1394,19 @@ moves_loop: // When in check and at SpNode search starts from here
// then we choose the move with the resulting highest score. // then we choose the move with the resulting highest score.
for (size_t i = 0; i < candidates; ++i) 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 // 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; break;
// This is our magic formula // This is our magic formula
s += ( weakness * int(RootMoves[0].score - s) score += ( weakness * int(RootMoves[0].score - score)
+ variance * (rk.rand<unsigned>() % weakness)) / 128; + variance * (rk.rand<unsigned>() % weakness)) / 128;
if (s > max_s) if (score > maxScore)
{ {
max_s = s; maxScore = score;
best = RootMoves[i].pv[0]; best = RootMoves[i].pv[0];
} }
} }
@@ -1437,7 +1437,7 @@ moves_loop: // When in check and at SpNode search starts from here
continue; continue;
Depth d = updated ? depth : depth - ONE_PLY; 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; bool tb = TB::RootInTB && abs(v) < VALUE_MATE - MAX_PLY;
v = tb ? TB::Score : v; v = tb ? TB::Score : v;
+2 -2
View File
@@ -56,7 +56,7 @@ struct Stack {
/// all non-pv moves. /// all non-pv moves.
struct RootMove { 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 RootMove& m) const { return score > m.score; } // Ascending sort
bool operator==(const Move& m) const { return pv[0] == m; } bool operator==(const Move& m) const { return pv[0] == m; }
@@ -64,7 +64,7 @@ struct RootMove {
void insert_pv_in_tt(Position& pos); void insert_pv_in_tt(Position& pos);
Value score; Value score;
Value prevScore; Value previousScore;
std::vector<Move> pv; std::vector<Move> pv;
}; };
+7 -7
View File
@@ -69,12 +69,12 @@ void ThreadBase::notify_one() {
} }
// 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(); mutex.lock();
while (!b) sleepCondition.wait(mutex); while (!condition) sleepCondition.wait(mutex);
mutex.unlock(); mutex.unlock();
} }
@@ -341,10 +341,10 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
void ThreadPool::wait_for_think_finished() { void ThreadPool::wait_for_think_finished() {
MainThread* t = main(); MainThread* th = main();
t->mutex.lock(); th->mutex.lock();
while (t->thinking) sleepCondition.wait(t->mutex); while (th->thinking) sleepCondition.wait(th->mutex);
t->mutex.unlock(); th->mutex.unlock();
} }