The test for virginity of the rook would also match opponent castlings!
for (i = g->numHalfMoves-1; i >= 0; i--) {
if (g->moveList[i].fromFile == mt->fromFile && g->moveList[i].fromRank == mt->fromRank ||
g->moveList[i].toFile == mt->fromFile && g->moveList[i].toRank == mt->fromRank ||
- g->moveList[i].fromFile == ALG_CASTLE && (gs->onMove == WHITE ? 0 : gs->ranks-1) == mt->fromRank &&
+ g->moveList[i].fromFile == ALG_CASTLE && (i&1 ? gs->ranks-1 : 0) == mt->fromRank &&
(g->moveList[i].fromRank == mt->fromFile || gs->files>>1 == mt->fromFile )) return MOVE_ILLEGAL;
}
mt->piecePromotionTo = promote; // gating OK