From aad8650ae84e7bf92ff33197c5b1fe44971ea5f0 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Mon, 6 Feb 2017 18:57:05 +0100 Subject: [PATCH] Beef up pseudo-legality checking The routine PseudoLegal, used test killer moves for legality, now checks if the move is a non-capture, if a dropped piece has the right color, and accepts Pawn moves (including double-pushes). Castlings are still rejected. --- dropper.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dropper.c b/dropper.c index 14a7148..adcd956 100644 --- a/dropper.c +++ b/dropper.c @@ -741,22 +741,28 @@ int 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 } -- 1.7.0.4