X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftt.cpp;h=1e98aa24901549c888a3704576b5215619f6a6bf;hp=a0cc7922395cb2a86bba11a1adbd29eacd78f305;hb=339bb8a524a0a6af093b383da9f61b31504be9fe;hpb=a88e762b4ea4a3696ecc0431237f54090a5aa1e2 diff --git a/src/tt.cpp b/src/tt.cpp index a0cc7922..1e98aa24 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008 Marco Costalba + Copyright (C) 2008-2009 Marco Costalba Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include #include +#include "movegen.h" #include "tt.h" @@ -185,6 +186,38 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) { } +/// TranspositionTable::extract_pv() extends a PV by adding moves from the +/// transposition table at the end. This should ensure that the PV is almost +/// always at least two plies long, which is important, because otherwise we +/// will often get single-move PVs when the search stops while failing high, +/// and a single-move PV means that we don't have a ponder move. + +void TranspositionTable::extract_pv(const Position& pos, Move pv[]) { + + int ply; + Position p(pos); + StateInfo st[100]; + + for (ply = 0; pv[ply] != MOVE_NONE; ply++) + p.do_move(pv[ply], st[ply]); + + bool stop; + const TTEntry* tte; + for (stop = false, tte = retrieve(p.get_key()); + tte && tte->move() != MOVE_NONE && !stop; + tte = retrieve(p.get_key()), ply++) + { + if (!move_is_legal(p, tte->move())) + break; + pv[ply] = tte->move(); + p.do_move(pv[ply], st[ply]); + for (int j = 0; j < ply; j++) + if (st[j].key == p.get_key()) stop = true; + } + pv[ply] = MOVE_NONE; +} + + /// TranspositionTable::full() returns the permill of all transposition table /// entries which have received at least one write during the current search. /// It is used to display the "info hashfull ..." information in UCI.