Skip to content

Commit

Permalink
Fix insufficient material for atomic
Browse files Browse the repository at this point in the history
Closes #352.
  • Loading branch information
ianfab committed Sep 7, 2021
1 parent 802d492 commit 732a687
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/apiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,15 @@ inline bool has_insufficient_material(Color c, const Position& pos) {
// Other win rules
if ( pos.captures_to_hand()
|| pos.count_in_hand(c, ALL_PIECES)
|| pos.extinction_value() != VALUE_NONE
|| (pos.extinction_value() != VALUE_NONE && !pos.extinction_pseudo_royal())
|| (pos.capture_the_flag_piece() && pos.count(c, pos.capture_the_flag_piece())))
return false;

// Restricted pieces
Bitboard restricted = pos.pieces(~c, KING);
// Atomic kings can not help checkmating
if (pos.extinction_pseudo_royal() && pos.blast_on_capture() && pos.extinction_piece_types().find(COMMONER) != pos.extinction_piece_types().end())
restricted |= pos.pieces(c, COMMONER);
for (PieceType pt : pos.piece_types())
if (pt == KING || !(pos.board_bb(c, pt) & pos.board_bb(~c, KING)))
restricted |= pos.pieces(c, pt);
Expand Down
6 changes: 6 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Position {
bool extinction_single_piece() const;
int extinction_piece_count() const;
int extinction_opponent_piece_count() const;
bool extinction_pseudo_royal() const;
PieceType capture_the_flag_piece() const;
Bitboard capture_the_flag(Color c) const;
bool flag_move() const;
Expand Down Expand Up @@ -867,6 +868,11 @@ inline int Position::extinction_opponent_piece_count() const {
return var->extinctionOpponentPieceCount;
}

inline bool Position::extinction_pseudo_royal() const {
assert(var != nullptr);
return var->extinctionPseudoRoyal;
}

inline PieceType Position::capture_the_flag_piece() const {
assert(var != nullptr);
return var->flagPiece;
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
},
"atomic": {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1": (False, False), # startpos
"8/8/8/8/3K4/3k4/8/8 b - - 0 1": (True, True), # K vs K
"k7/p7/8/8/8/8/8/K7 w - - 0 1": (True, False), # K vs KP
"k7/q7/8/8/8/8/8/K7 w - - 0 1": (True, False), # K vs KQ
},
"3check": {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 3+3 0 1": (False, False), # startpos
Expand Down

0 comments on commit 732a687

Please sign in to comment.