mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Better clarify DTZEntry keys
Calrify that DTZ entry is initialized with the same color of the corresponding WDL entry.
This commit is contained in:
parent
875441db2b
commit
79051949ca
1 changed files with 21 additions and 20 deletions
|
@ -107,7 +107,7 @@ struct DTZEntry {
|
||||||
|
|
||||||
enum Flag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8 };
|
enum Flag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8 };
|
||||||
|
|
||||||
DTZEntry(const WDLEntry& wdl, Key keys[]);
|
DTZEntry(const WDLEntry& wdl, Key wdlKeys[]);
|
||||||
~DTZEntry();
|
~DTZEntry();
|
||||||
bool init(const std::string& fname);
|
bool init(const std::string& fname);
|
||||||
template<typename T> void do_init(T& e, uint8_t* data);
|
template<typename T> void do_init(T& e, uint8_t* data);
|
||||||
|
@ -535,12 +535,12 @@ WDLEntry::~WDLEntry()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DTZEntry::DTZEntry(const WDLEntry& wdl, Key keys[])
|
DTZEntry::DTZEntry(const WDLEntry& wdl, Key wdlKeys[])
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(DTZEntry));
|
memset(this, 0, sizeof(DTZEntry));
|
||||||
|
|
||||||
key = keys[WHITE];
|
key = wdlKeys[0];
|
||||||
key2 = keys[BLACK];
|
key2 = wdlKeys[1];
|
||||||
|
|
||||||
assert(key == wdl.key);
|
assert(key == wdl.key);
|
||||||
|
|
||||||
|
@ -1279,33 +1279,34 @@ int probe_dtz_table(const Position& pos, WDLScore wdl, int *success)
|
||||||
Key key = pos.material_key();
|
Key key = pos.material_key();
|
||||||
|
|
||||||
if (DTZTable.front().key != key && DTZTable.front().key2 != key) {
|
if (DTZTable.front().key != key && DTZTable.front().key2 != key) {
|
||||||
// Enforce "Most Recently Used" (MRU) order for DTZ_list
|
|
||||||
|
// Enforce "Most Recently Used" (MRU) order for DTZ list
|
||||||
for (auto it = DTZTable.begin(); it != DTZTable.end(); ++it)
|
for (auto it = DTZTable.begin(); it != DTZTable.end(); ++it)
|
||||||
if (it->key == key) {
|
if (it->key == key) {
|
||||||
// Move to front without deleting the element
|
// Move to front without deleting the element
|
||||||
DTZTable.splice(DTZTable.begin(),DTZTable, it);
|
DTZTable.splice(DTZTable.begin(), DTZTable, it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If still not found, add a new one
|
// If still not found, add a new one
|
||||||
if (DTZTable.front().key != key) {
|
if (DTZTable.front().key != key) {
|
||||||
|
|
||||||
WDLEntry* ptr = WDLHash[key];
|
WDLEntry* wdlEntry = WDLHash[key];
|
||||||
if (!ptr) {
|
if (!wdlEntry) {
|
||||||
*success = 0;
|
*success = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StateInfo st;
|
StateInfo st;
|
||||||
Position p;
|
Position p;
|
||||||
std::string code = file_name(pos, ptr->key != key);
|
std::string wdlCode = file_name(pos, wdlEntry->key != key);
|
||||||
std::string fname = code + ".rtbz";
|
std::string fname = wdlCode + ".rtbz";
|
||||||
code.erase(code.find('v'), 1);
|
wdlCode.erase(wdlCode.find('v'), 1);
|
||||||
|
|
||||||
Key keys[] = { p.set(code, WHITE, &st).material_key(),
|
Key wdlKeys[] = { p.set(wdlCode, WHITE, &st).material_key(),
|
||||||
p.set(code, BLACK, &st).material_key() };
|
p.set(wdlCode, BLACK, &st).material_key() };
|
||||||
|
|
||||||
DTZTable.push_front(DTZEntry(*ptr, keys));
|
DTZTable.push_front(DTZEntry(*wdlEntry, wdlKeys));
|
||||||
|
|
||||||
if (!DTZTable.front().init(fname)) {
|
if (!DTZTable.front().init(fname)) {
|
||||||
// In case file is not found init() fails, but we leave
|
// In case file is not found init() fails, but we leave
|
||||||
|
@ -1324,14 +1325,12 @@ int probe_dtz_table(const Position& pos, WDLScore wdl, int *success)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DTZEntry* ptr = &DTZTable.front();
|
if (!DTZTable.front().baseAddress) {
|
||||||
|
|
||||||
if (!ptr->baseAddress) {
|
|
||||||
*success = 0;
|
*success = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return probe_table(pos, ptr, wdl, success);
|
return probe_table(pos, &DTZTable.front(), wdl, success);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add underpromotion captures to list of captures.
|
// Add underpromotion captures to list of captures.
|
||||||
|
@ -1418,9 +1417,11 @@ int probe_dtz_no_ep(Position& pos, int *success)
|
||||||
|
|
||||||
WDLScore wdl = probe_ab(pos, WDLLoss, WDLWin, success);
|
WDLScore wdl = probe_ab(pos, WDLLoss, WDLWin, success);
|
||||||
|
|
||||||
if (*success == 0) return 0;
|
if (!*success)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (wdl == WDLDraw) return 0;
|
if (wdl == WDLDraw)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (*success == 2)
|
if (*success == 2)
|
||||||
return wdl == WDLWin ? 1 : 101;
|
return wdl == WDLWin ? 1 : 101;
|
||||||
|
|
Loading…
Add table
Reference in a new issue