mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Use legal positions for endgame initialization
During endgame initialization we get the material hash key of each endgame forging and ad-hoc position that in same cases is illegal (leaves teh king under capture). This is not a problem for the material key, but rises an assert when SF is run in debug mode with 'testKingCapture' set in pos_is_ok(). So rewrite the code to always produce legal positions. No functional change.
This commit is contained in:
parent
1f4798a173
commit
d0587f2c7f
1 changed files with 3 additions and 4 deletions
|
@ -82,8 +82,7 @@ namespace {
|
||||||
|
|
||||||
// Get the material key of Position out of the given endgame key code
|
// Get the material key of Position out of the given endgame key code
|
||||||
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
|
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
|
||||||
// and then let a Position object do the work for us. Note that the
|
// and then let a Position object do the work for us.
|
||||||
// FEN string could correspond to an illegal position.
|
|
||||||
Key key(const string& code, Color c) {
|
Key key(const string& code, Color c) {
|
||||||
|
|
||||||
assert(code.length() > 0 && code.length() < 8);
|
assert(code.length() > 0 && code.length() < 8);
|
||||||
|
@ -94,8 +93,8 @@ namespace {
|
||||||
|
|
||||||
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
|
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
|
||||||
|
|
||||||
string fen = sides[0] + char('0' + int(8 - code.length()))
|
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
|
||||||
+ sides[1] + "/8/8/8/8/8/8/8 w - - 0 10";
|
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
|
||||||
|
|
||||||
return Position(fen, false, NULL).material_key();
|
return Position(fen, false, NULL).material_key();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue