+ // Fast stalemate detection with lone king
+ bool is_kxk_stalemate(const Position &pos, const Color c) {
+ if ( pos.side_to_move() == c &&
+ !pos.in_check()) {
+ const Square from = pos.king_square(c);
+ Bitboard b = pos.attacks_from<KING>(from);
+ while (b) {
+ // Assume there are no pinned pieces, as it is a lone king
+ if (pos.pl_move_is_legal(make_move(from, pop_1st_bit(&b)), 0))
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }