// Ok, let's start the benchmark !
totalNodes = 0;
- time = get_system_time();
+ time = system_time();
for (size_t i = 0; i < fenList.size(); i++)
{
}
}
- time = get_system_time() - time;
+ time = system_time() - time;
cerr << "\n==============================="
<< "\nTotal time (ms) : " << time
/// Book c'tor. Make random number generation less deterministic, for book moves
Book::Book() : bookSize(0) {
- for (int i = abs(get_system_time() % 10000); i > 0; i--)
+ for (int i = abs(system_time() % 10000); i > 0; i--)
RKiss.rand<unsigned>();
}
fen += string(1, '0' + int(8 - keyCode.length())) + "/8/8/8/8/8/8/8 w - - 0 10";
// Build a Position out of the fen string and get its material key
- return Position(fen, false, 0).get_material_key();
+ return Position(fen, false, 0).material_key();
}
} // namespace
margins[WHITE] = margins[BLACK] = VALUE_ZERO;
// Probe the material hash table
- ei.mi = Threads[pos.thread()].materialTable.get_material_info(pos);
+ ei.mi = Threads[pos.thread()].materialTable.material_info(pos);
score += ei.mi->material_value();
// If we have a specialized evaluation function for the current material
}
// Probe the pawn hash table
- ei.pi = Threads[pos.thread()].pawnTable.get_pawn_info(pos);
+ ei.pi = Threads[pos.thread()].pawnTable.pawn_info(pos);
score += ei.pi->pawns_value();
// Initialize attack and king safety bitboards
MaterialInfoTable::~MaterialInfoTable() { delete funcs; }
-/// MaterialInfoTable::get_material_info() takes a position object as input,
+/// MaterialInfoTable::material_info() takes a position object as input,
/// computes or looks up a MaterialInfo object, and returns a pointer to it.
/// If the material configuration is not already present in the table, it
/// is stored there, so we don't have to recompute everything when the
/// same material configuration occurs again.
-MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) const {
+MaterialInfo* MaterialInfoTable::material_info(const Position& pos) const {
- Key key = pos.get_material_key();
+ Key key = pos.material_key();
MaterialInfo* mi = probe(key);
// If mi->key matches the position's material hash key, it means that we
/// The MaterialInfoTable class represents a pawn hash table. The most important
-/// method is get_material_info, which returns a pointer to a MaterialInfo object.
+/// method is material_info(), which returns a pointer to a MaterialInfo object.
class MaterialInfoTable : public SimpleHash<MaterialInfo, MaterialTableSize> {
public:
~MaterialInfoTable();
void init();
- MaterialInfo* get_material_info(const Position& pos) const;
+ MaterialInfo* material_info(const Position& pos) const;
static Phase game_phase(const Position& pos);
private:
void dbg_after() { dbg_hit_on(true); dbg_hit_cnt0--; }
-/// get_system_time() returns the current system time, measured in milliseconds
+/// system_time() returns the current system time, measured in milliseconds
-int get_system_time() {
+int system_time() {
#if defined(_MSC_VER)
struct _timeb t;
extern const std::string engine_name();
extern const std::string engine_authors();
-extern int get_system_time();
+extern int system_time();
extern int cpu_count();
extern void timed_wait(WaitCondition*, Lock*, int);
extern void prefetch(char* addr);
/// MovePicker::score_captures(), MovePicker::score_noncaptures() and
/// MovePicker::score_evasions() assign a numerical move ordering score
/// to each move in a move list. The moves with highest scores will be
-/// picked first by get_next_move().
+/// picked first by next_move().
void MovePicker::score_captures() {
// Winning and equal captures in the main search are ordered by MVV/LVA.
}
}
-/// MovePicker::get_next_move() is the most important method of the MovePicker
-/// class. It returns a new pseudo legal move every time it is called, until there
+/// MovePicker::next_move() is the most important method of the MovePicker class.
+/// It returns a new pseudo legal move every time it is called, until there
/// are no more moves left. It picks the move with the biggest score from a list
/// of generated moves taking care not to return the tt move if has already been
/// searched previously. Note that this function is not thread safe so should be
/// lock protected by caller when accessed through a shared MovePicker object.
-Move MovePicker::get_next_move() {
+Move MovePicker::next_move() {
Move move;
/// MovePicker is a class which is used to pick one pseudo legal move at a time
/// from the current position. It is initialized with a Position object and a few
/// moves we have reason to believe are good. The most important method is
-/// MovePicker::get_next_move(), which returns a new pseudo legal move each time
+/// MovePicker::next_move(), which returns a new pseudo legal move each time
/// it is called, until there are no moves left, when MOVE_NONE is returned.
/// In order to improve the efficiency of the alpha beta algorithm, MovePicker
/// attempts to return the moves which are most likely to get a cut-off first.
MovePicker(const Position&, Move, Depth, const History&, Search::Stack*, Value);
MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
MovePicker(const Position&, Move, const History&, PieceType parentCapture);
- Move get_next_move();
+ Move next_move();
private:
void score_captures();
}
-/// PawnInfoTable::get_pawn_info() takes a position object as input, computes
+/// PawnInfoTable::pawn_info() takes a position object as input, computes
/// a PawnInfo object, and returns a pointer to it. The result is also stored
/// in an hash table, so we don't have to recompute everything when the same
/// pawn structure occurs again.
-PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
+PawnInfo* PawnInfoTable::pawn_info(const Position& pos) const {
- Key key = pos.get_pawn_key();
+ Key key = pos.pawn_key();
PawnInfo* pi = probe(key);
// If pi->key matches the position's pawn hash key, it means that we
/// PawnInfo is a class which contains various information about a pawn
/// structure. Currently, it only includes a middle game and an end game
/// pawn structure evaluation, and a bitboard of passed pawns. We may want
-/// to add further information in the future. A lookup to the pawn hash table
-/// (performed by calling the get_pawn_info method in a PawnInfoTable object)
-/// returns a pointer to a PawnInfo object.
+/// to add further information in the future. A lookup to the pawn hash
+/// table (performed by calling the pawn_info method in a PawnInfoTable
+/// object) returns a pointer to a PawnInfo object.
class PawnInfo {
/// The PawnInfoTable class represents a pawn hash table. The most important
-/// method is get_pawn_info, which returns a pointer to a PawnInfo object.
+/// method is pawn_info, which returns a pointer to a PawnInfo object.
class PawnInfoTable : public SimpleHash<PawnInfo, PawnTableSize> {
public:
- PawnInfo* get_pawn_info(const Position& pos) const;
+ PawnInfo* pawn_info(const Position& pos) const;
private:
template<Color Us>
assert(&newSt != st);
nodes++;
- Key key = st->key;
+ Key k = st->key;
// Copy some fields of old state to our new StateInfo object except the ones
// which are recalculated from scratch anyway, then switch our state pointer
st = &newSt;
// Update side to move
- key ^= zobSideToMove;
+ k ^= zobSideToMove;
// Increment the 50 moves rule draw counter. Resetting it to zero in the
// case of non-reversible moves is taken care of later.
if (is_castle(m))
{
- st->key = key;
+ st->key = k;
do_castle_move<true>(m);
return;
}
pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
// Update hash keys
- key ^= zobrist[them][capture][capsq];
+ k ^= zobrist[them][capture][capsq];
st->materialKey ^= zobrist[them][capture][pieceCount[them][capture]];
// Update incremental scores
}
// Update hash key
- key ^= zobrist[us][pt][from] ^ zobrist[us][pt][to];
+ k ^= zobrist[us][pt][from] ^ zobrist[us][pt][to];
// Reset en passant square
if (st->epSquare != SQ_NONE)
{
- key ^= zobEp[st->epSquare];
+ k ^= zobEp[st->epSquare];
st->epSquare = SQ_NONE;
}
if ( st->castleRights != CASTLES_NONE
&& (castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
{
- key ^= zobCastle[st->castleRights];
+ k ^= zobCastle[st->castleRights];
st->castleRights &= castleRightsMask[from] & castleRightsMask[to];
- key ^= zobCastle[st->castleRights];
+ k ^= zobCastle[st->castleRights];
}
// Prefetch TT access as soon as we know key is updated
- prefetch((char*)TT.first_entry(key));
+ prefetch((char*)TT.first_entry(k));
// Move the piece
Bitboard move_bb = make_move_bb(from, to);
&& (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them)))
{
st->epSquare = Square((from + to) / 2);
- key ^= zobEp[st->epSquare];
+ k ^= zobEp[st->epSquare];
}
if (is_promotion(m))
pieceList[us][promotion][index[to]] = to;
// Update hash keys
- key ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to];
+ k ^= zobrist[us][PAWN][to] ^ zobrist[us][promotion][to];
st->pawnKey ^= zobrist[us][PAWN][to];
st->materialKey ^= zobrist[us][promotion][pieceCount[us][promotion]++]
^ zobrist[us][PAWN][pieceCount[us][PAWN]];
st->capturedType = capture;
// Update the key with the final value
- st->key = key;
+ st->key = k;
// Update checkers bitboard, piece must be already moved
st->checkersBB = 0;
int see_sign(Move m) const;
// Accessing hash keys
- Key get_key() const;
- Key get_exclusion_key() const;
- Key get_pawn_key() const;
- Key get_material_key() const;
+ Key key() const;
+ Key exclusion_key() const;
+ Key pawn_key() const;
+ Key material_key() const;
// Incremental evaluation
Score value() const;
return !(pieces(PAWN, flip(c)) & passed_pawn_mask(c, s));
}
-inline Key Position::get_key() const {
+inline Key Position::key() const {
return st->key;
}
-inline Key Position::get_exclusion_key() const {
+inline Key Position::exclusion_key() const {
return st->key ^ zobExclusion;
}
-inline Key Position::get_pawn_key() const {
+inline Key Position::pawn_key() const {
return st->pawnKey;
}
-inline Key Position::get_material_key() const {
+inline Key Position::material_key() const {
return st->materialKey;
}
MovePickerExt(const Position& p, Move ttm, Depth d, const History& h, Stack* ss, Value b)
: MovePicker(p, ttm, d, h, ss, b), mp(ss->sp->mp) {}
- Move get_next_move() { return mp->get_next_move(); }
+ Move next_move() { return mp->next_move(); }
MovePicker* mp;
};
// We don't want the score of a partial search to overwrite a previous full search
// TT value, so we use a different position key in case of an excluded move.
excludedMove = ss->excludedMove;
- posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key();
+ posKey = excludedMove ? pos.exclusion_key() : pos.key();
tte = TT.probe(posKey);
ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
MovePicker mp(pos, ttMove, H, pos.captured_piece_type());
CheckInfo ci(pos);
- while ((move = mp.get_next_move()) != MOVE_NONE)
+ while ((move = mp.next_move()) != MOVE_NONE)
if (pos.pl_move_is_legal(move, ci.pinned))
{
pos.do_move(move, st, ci, pos.move_gives_check(move, ci));
// Step 11. Loop through moves
// Loop through all pseudo-legal moves until no moves remain or a beta cutoff occurs
while ( bestValue < beta
- && (move = mp.get_next_move()) != MOVE_NONE
+ && (move = mp.next_move()) != MOVE_NONE
&& !thread.cutoff_occurred())
{
assert(is_ok(move));
// Transposition table lookup. At PV nodes, we don't use the TT for
// pruning, but only for move ordering.
- tte = TT.probe(pos.get_key());
+ tte = TT.probe(pos.key());
ttMove = (tte ? tte->move() : MOVE_NONE);
if (!PvNode && tte && can_return_tt(tte, ttDepth, beta, ss->ply))
if (bestValue >= beta)
{
if (!tte)
- TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), VALUE_TYPE_LOWER, DEPTH_NONE, MOVE_NONE, ss->eval, evalMargin);
+ TT.store(pos.key(), value_to_tt(bestValue, ss->ply), VALUE_TYPE_LOWER, DEPTH_NONE, MOVE_NONE, ss->eval, evalMargin);
return bestValue;
}
// Loop through the moves until no moves remain or a beta cutoff occurs
while ( bestValue < beta
- && (move = mp.get_next_move()) != MOVE_NONE)
+ && (move = mp.next_move()) != MOVE_NONE)
{
assert(is_ok(move));
vt = bestValue <= oldAlpha ? VALUE_TYPE_UPPER
: bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT;
- TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin);
+ TT.store(pos.key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin);
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
static int searchStartTime;
if (reset)
- searchStartTime = get_system_time();
+ searchStartTime = system_time();
- return get_system_time() - searchStartTime;
+ return system_time() - searchStartTime;
}
static RKISS rk;
// PRNG sequence should be not deterministic
- for (int i = abs(get_system_time() % 50); i > 0; i--)
+ for (int i = abs(system_time() % 50); i > 0; i--)
rk.rand<unsigned>();
// RootMoves are already sorted by score in descending order
pv.push_back(m);
pos.do_move(m, *st++);
- while ( (tte = TT.probe(pos.get_key())) != NULL
+ while ( (tte = TT.probe(pos.key())) != NULL
&& tte->move() != MOVE_NONE
&& pos.is_pseudo_legal(tte->move())
&& pos.pl_move_is_legal(tte->move(), pos.pinned_pieces())
assert(pv[ply] != MOVE_NONE && pos.is_pseudo_legal(pv[ply]));
do {
- k = pos.get_key();
+ k = pos.key();
tte = TT.probe(k);
// Don't overwrite existing correct entries
static int lastInfoTime;
int e = elapsed_time();
- if (get_system_time() - lastInfoTime >= 1000 || !lastInfoTime)
+ if (system_time() - lastInfoTime >= 1000 || !lastInfoTime)
{
- lastInfoTime = get_system_time();
+ lastInfoTime = system_time();
dbg_print_mean();
dbg_print_hit_rate();
}
else if (token == "key")
- cout << "key: " << hex << pos.get_key()
- << "\nmaterial key: " << pos.get_material_key()
- << "\npawn key: " << pos.get_pawn_key() << endl;
+ cout << "key: " << hex << pos.key()
+ << "\nmaterial key: " << pos.material_key()
+ << "\npawn key: " << pos.pawn_key() << endl;
else if (token == "uci")
cout << "id name " << engine_name()
if (!(is >> depth))
return;
- time = get_system_time();
+ time = system_time();
int64_t n = Search::perft(pos, depth * ONE_PLY);
- time = get_system_time() - time;
+ time = system_time() - time;
std::cout << "\nNodes " << n
<< "\nTime (ms) " << time