Fix castling through check
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 11 Feb 2018 11:14:28 +0000 (12:14 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 11 Feb 2018 11:14:28 +0000 (12:14 +0100)
Castling through check, like walking into check, is supposed to be  tested
through early move generation in the reply node. But this early generation
was triggered by testing whether the 'to-piece' was a King, while the way
castling is implemented promotes the King to a Rook. This way castling
escaped the test. Now early move generation is done based on the from-piece.

dropper.c

index a2d9e3d..766bfa2 100644 (file)
--- a/dropper.c
+++ b/dropper.c
@@ -1119,7 +1119,7 @@ Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction,
     int curEval, anaEval, score;
 
     // legality
-    int earlyGen = (ff->toPiece == stm+31); // King was moved
+    int earlyGen = (ff->fromPiece == stm+31); // King was moved
     if(ply > 90) { if(DEBUG) Dump("maxply"); ff->depth = 0; return -ff->newEval+150; }
     f.xking = location[stm+31]; // opponent King, as stm not yet toggled
     if(!earlyGen && ff->mutation > 0) { // if other piece was moved (not dropped!), abort with +INF score if it was pinned