Skip to content

Commit d0587f2

Browse files
committed
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.
1 parent 1f4798a commit d0587f2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/endgame.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ namespace {
8282

8383
// Get the material key of Position out of the given endgame key code
8484
// like "KBPKN". The trick here is to first forge an ad-hoc FEN string
85-
// and then let a Position object do the work for us. Note that the
86-
// FEN string could correspond to an illegal position.
85+
// and then let a Position object do the work for us.
8786
Key key(const string& code, Color c) {
8887

8988
assert(code.length() > 0 && code.length() < 8);
@@ -94,8 +93,8 @@ namespace {
9493

9594
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
9695

97-
string fen = sides[0] + char('0' + int(8 - code.length()))
98-
+ sides[1] + "/8/8/8/8/8/8/8 w - - 0 10";
96+
string fen = sides[0] + char(8 - sides[0].length() + '0') + "/8/8/8/8/8/8/"
97+
+ sides[1] + char(8 - sides[1].length() + '0') + " w - - 0 10";
9998

10099
return Position(fen, false, NULL).material_key();
101100
}

0 commit comments

Comments
 (0)