Skip to content

Commit

Permalink
Fix custom king insufficient material
Browse files Browse the repository at this point in the history
Closes #686.
  • Loading branch information
ianfab committed Aug 20, 2023
1 parent 865efff commit ac35f89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/apiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
if ((pos.pieces(c) & unbound) && (popcount(pos.pieces() ^ restricted) >= 2 || pos.stalemate_value() != VALUE_DRAW || pos.check_counting() || pos.makpong()))
return false;

// Non-draw stalemate with lone custom king
if ( pos.stalemate_value() != VALUE_DRAW && pos.king_type() != KING
&& pos.pieces(c, KING) && (pos.board_bb(c, KING) & pos.board_bb(~c, KING)))
return false;

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
firstRankPawnDrops = true
promotionZonePawnDrops = true
immobilityIllegal = true
[wazirking:chess]
fers = q
king = k:W
startFen = 7k/5Kq1/8/8/8/8/8/8 w - - 0 1
stalemateValue = loss
nFoldValue = loss
"""

sf.load_variant_config(ini_text)
Expand Down Expand Up @@ -193,6 +200,9 @@
"10/5k4/10/10/10/10/10/10/5KC3/10 w - - 0 1": (False, True), # KC vs K
"10/5k4/10/10/10/10/10/10/5K4/10 w - - 0 1": (True, True), # K vs K
},
"wazirking": {
"7k/6K1/8/8/8/8/8/8 b - - 0 1": (False, False), # K vs K
},
}

invalid_variant_positions = {
Expand Down

0 comments on commit ac35f89

Please sign in to comment.