- sideToMove = Color(index % 2);
- blackKingSquare = Square((index / 2) % 64);
- whiteKingSquare = Square((index / 128) % 64);
- pawnSquare = make_square(File(s % 4), Rank(s / 4 + 1));
- }
-
- bool KPKPosition::is_legal() const {
-
- if ( whiteKingSquare == pawnSquare
- || whiteKingSquare == blackKingSquare
- || pawnSquare == blackKingSquare)
- return false;
-
- if (sideToMove == WHITE)
- {
- if ( bit_is_set(wk_attacks(), blackKingSquare)
- || bit_is_set(pawn_attacks(), blackKingSquare))
- return false;
- }
- else if (bit_is_set(bk_attacks(), whiteKingSquare))
- return false;
-
- return true;
- }
-
- bool KPKPosition::is_immediate_draw() const {
-
- if (sideToMove == BLACK)
- {
- Bitboard wka = wk_attacks();
- Bitboard bka = bk_attacks();
-
- // Case 1: Stalemate
- if ((bka & ~(wka | pawn_attacks())) == EmptyBoardBB)
- return true;
-
- // Case 2: King can capture pawn
- if (bit_is_set(bka, pawnSquare) && !bit_is_set(wka, pawnSquare))
- return true;
- }
- else