mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 17:19:36 +00:00
Small code reformat in TranspositionTable::extract_pv()
In particular don't use an array of StateInfo, this avoids a possible overflow and is in any case redundant. Also pass as argument the pv[] array size to avoid a second possible overflow on this one. Fix suggested by Joona. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
32dfaa56b0
commit
60bc30275d
3 changed files with 18 additions and 19 deletions
|
@ -947,7 +947,7 @@ namespace {
|
||||||
// Update PV
|
// Update PV
|
||||||
rml.set_move_score(i, value);
|
rml.set_move_score(i, value);
|
||||||
update_pv(ss, 0);
|
update_pv(ss, 0);
|
||||||
TT.extract_pv(pos, ss[0].pv);
|
TT.extract_pv(pos, ss[0].pv, PLY_MAX);
|
||||||
rml.set_move_pv(i, ss[0].pv);
|
rml.set_move_pv(i, ss[0].pv);
|
||||||
|
|
||||||
if (MultiPV == 1)
|
if (MultiPV == 1)
|
||||||
|
|
33
src/tt.cpp
33
src/tt.cpp
|
@ -220,27 +220,26 @@ void TranspositionTable::insert_pv(const Position& pos, Move pv[]) {
|
||||||
/// will often get single-move PVs when the search stops while failing high,
|
/// 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.
|
/// and a single-move PV means that we don't have a ponder move.
|
||||||
|
|
||||||
void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
void TranspositionTable::extract_pv(const Position& pos, Move pv[], int pvSize) {
|
||||||
|
|
||||||
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;
|
const TTEntry* tte;
|
||||||
for (stop = false, tte = retrieve(p.get_key());
|
StateInfo st;
|
||||||
tte && tte->move() != MOVE_NONE && !stop;
|
Position p(pos);
|
||||||
tte = retrieve(p.get_key()), ply++)
|
int ply = 0;
|
||||||
|
|
||||||
|
// Update position to the end of current PV
|
||||||
|
while (pv[ply] != MOVE_NONE)
|
||||||
|
p.do_move(pv[ply++], st);
|
||||||
|
|
||||||
|
// Try to add moves from TT until possible
|
||||||
|
while ( (tte = retrieve(p.get_key())) != NULL
|
||||||
|
&& tte->move() != MOVE_NONE
|
||||||
|
&& move_is_legal(p, tte->move())
|
||||||
|
&& (!p.is_draw() || ply < 2)
|
||||||
|
&& ply < pvSize)
|
||||||
{
|
{
|
||||||
if (!move_is_legal(p, tte->move()))
|
|
||||||
break;
|
|
||||||
pv[ply] = tte->move();
|
pv[ply] = tte->move();
|
||||||
p.do_move(pv[ply], st[ply]);
|
p.do_move(pv[ply++], st);
|
||||||
for (int j = 0; j < ply; j++)
|
|
||||||
if (st[j].key == p.get_key()) stop = true;
|
|
||||||
}
|
}
|
||||||
pv[ply] = MOVE_NONE;
|
pv[ply] = MOVE_NONE;
|
||||||
}
|
}
|
||||||
|
|
2
src/tt.h
2
src/tt.h
|
@ -102,7 +102,7 @@ public:
|
||||||
void prefetch(const Key posKey) const;
|
void prefetch(const Key posKey) const;
|
||||||
void new_search();
|
void new_search();
|
||||||
void insert_pv(const Position& pos, Move pv[]);
|
void insert_pv(const Position& pos, Move pv[]);
|
||||||
void extract_pv(const Position& pos, Move pv[]);
|
void extract_pv(const Position& pos, Move pv[], int pvSize);
|
||||||
int full() const;
|
int full() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue