PseudoLegal (int stm, int move)
{ // used for testing killers, so we can assume the move must be pseudo-legal for the stm in some position
int match, from = move >> 8 & 0xFF, to = move & 255;
- signed char piece = board[from];
- to = toDecode[to];
+ signed char piece = board[from], mover = move >> 16 & 0xFF;
+ to = toDecode[to]; // could be double-push or castling, though
+ if(board[to]) return 0;
if(piece < 0) { // drop
if(piece == -1) return 0; // type not in hand
piece = dropType[from] - 1;
+ if(!(piece & stm)) return 0; // piece has wrong color
if((piece & ~COLOR) == 0 && pawnCount[sqr2file[to]] & maxBulk[stm]) return 0; // Pawn drop would over-crowd file
return (board[to] == 0); // otherwise drop is legal on empty square (assumes drop location always legal for piece type)
}
if(!(piece & stm)) return 0; // piece has wrong color
+ if(piece == stm) { /// Pawn
+ if(stm == WHITE) return board[from+22] == 0 && (to - from == 22 || zoneTab[from] & 0x80 && to - from == 44 && board[to] == 0);
+ return board[from-22] == 0 && (to - from == -22 || zoneTab[from] & 0x80 && to - from == -44 && board[to] == 0);
+ }
match = pieceCode[piece] & captCode[to - from];
if(!match) return 0; // not aligned
if(match & C_DISTANT) { // distant alignment
int step = deltaVec[to - from];
while(board[to -= step] == 0) {} // ray scan towards mover
return (from == to); // legal if it reaches mover
- }
+ } else if((move & 255) > specials) return 0; // must be castling, as Pawns were already taken care of. Forbid for now.
return 1; // must be leaper alignment, which guarantees hit
}