mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Use a circular buffer to keep track of setup states
This fixes a regression on real games due to the fact that we have some mismatches: history[st->gamePly - i] != stp->key when st->gamePly - i == 0,this is due to a nasty bug I have introduced when using std::vector<> as StateInfo backup. The point is that StateInfo keeps inside a pointer to the previous StateInfo in a kind of linked list. But when std::vector<> is resized reallocates a larger chunk of memory and moves the data there so these pointers became stale. This patch fixes the issue. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
03ad183384
commit
5f7eb20090
1 changed files with 8 additions and 6 deletions
14
src/uci.cpp
14
src/uci.cpp
|
@ -38,8 +38,9 @@ namespace {
|
||||||
const string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
const string StartPositionFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
|
|
||||||
// Keep track of position keys along the setup moves (from start position to the
|
// Keep track of position keys along the setup moves (from start position to the
|
||||||
// position just before to start searching). This is needed by draw detection.
|
// position just before to start searching). This is needed by draw detection
|
||||||
std::vector<StateInfo> SetupState(200, StateInfo());
|
// where, due to 50 moves rule, we need to ckeck at most 100 plies back.
|
||||||
|
StateInfo StateRingBuf[102], *SetupState = StateRingBuf;
|
||||||
|
|
||||||
// UCIParser is a class for parsing UCI input. The class
|
// UCIParser is a class for parsing UCI input. The class
|
||||||
// is actually a string stream built on a given input string.
|
// is actually a string stream built on a given input string.
|
||||||
|
@ -144,13 +145,14 @@ namespace {
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
|
|
||||||
SetupState.clear();
|
|
||||||
|
|
||||||
// Parse move list (if any)
|
// Parse move list (if any)
|
||||||
while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
|
while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
SetupState.push_back(StateInfo());
|
pos.do_move(m, *SetupState);
|
||||||
pos.do_move(m, SetupState.back());
|
|
||||||
|
// Increment pointer to StateRingBuf circular buffer
|
||||||
|
if (++SetupState - StateRingBuf >= 102)
|
||||||
|
SetupState = StateRingBuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue