X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=48310460b196b377852da89d29863df3e4576984;hb=211b194243de81ed013566a30ef754018586c4e1;hp=9700dbf884449b4800275d54afeec930b5527e05;hpb=b52aafe5fc484a170251d4bb5bad039ffbbda4df;p=xboard.git diff --git a/moves.c b/moves.c index 9700dbf..4831046 100644 --- a/moves.c +++ b/moves.c @@ -247,18 +247,25 @@ MovesFromString (Board board, int flags, int f, int r, char *desc, MoveCallback if(*desc == 'c') mode |= his, desc++; if(*desc == 'd') mode |= mine, desc++; if(*desc == 'e') mode |= 8, desc++; + if(!mode) mode = his + 4;// no mode spec, use default = mc + if(*desc == 'p') mode |= 32, desc++; + if(*desc == 'g') mode |= 64, desc++; if(*desc == 'n') jump = 0, desc++; while(*desc == 'j') jump++, desc++; - if(!mode) mode = his + 4;// no mode spec, use default = mc dx = xStep[*p-'A'] - '0'; // step vector of atom dy = yStep[*p-'A'] - '0'; if(isdigit(*++p)) expo = atoi(p++); // read exponent if(expo > 9) p++; // allow double-digit desc = p; // this is start of next move - if(initial && board[r][f] != initialPosition[r][f]) continue; + if(initial && (board[r][f] != initialPosition[r][f] || + r == 0 && board[TOUCHED_W] & 1< 1 && dx == 0 && dy == 0) { // castling indicated by O + number + mode |= 16; dy = 1; + } do { for(dir=0, bit=1; dir<8; dir++, bit += bit) { // loop over directions - int i = expo, vx, vy; + int i = expo, hop = mode, vx, vy; if(!(bit & dirSet)) continue; // does not move in this direction vx = dx*rot[dir][0] + dy*rot[dir][1]; // rotate step vector vy = dx*rot[dir][2] + dy*rot[dir][3]; @@ -271,9 +278,19 @@ MovesFromString (Board board, int flags, int f, int r, char *desc, MoveCallback if(board[y][x] < BlackPawn) occup = 1; else if(board[y][x] < EmptySquare) occup = 2; else occup = 4; + if(hop & 32+64) { if(occup != 4) { if(hop & 64 && i != 1) i = 2; hop &= 31; } continue; } // hopper if(mode & 8 && y == board[EP_RANK] && occup == 4 && board[EP_FILE] == x) { // to e.p. square cb(board, flags, mine == 1 ? WhiteCapturesEnPassant : BlackCapturesEnPassant, r, f, y, x, cl); } + if(mode & 16) { // castling + i = 2; // kludge to elongate move indefinitely + if(occup == 4) continue; // skip empty squares + if(x == BOARD_LEFT && board[y][x] == initialPosition[y][x]) // reached initial corner piece + cb(board, flags, mine == 1 ? WhiteQueenSideCastle : BlackQueenSideCastle, r, f, y, f - expo, cl); + if(x == BOARD_RGHT-1 && board[y][x] == initialPosition[y][x]) + cb(board, flags, mine == 1 ? WhiteKingSideCastle : BlackKingSideCastle, r, f, y, f + expo, cl); + break; + } if(occup & mode) cb(board, flags, NormalMove, r, f, y, x, cl); // allowed, generate if(occup != 4) break; // not valid transit square } while(--i); @@ -1218,6 +1235,7 @@ GenLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure, Ches int ignoreCheck = (flags & F_IGNORE_CHECK) != 0; ChessSquare wKing = WhiteKing, bKing = BlackKing, *castlingRights = board[CASTLING]; int inCheck = !ignoreCheck && CheckTest(board, flags, -1, -1, -1, -1, FALSE); // kludge alert: this would mark pre-existing checkers if status==1 + char *p; cl.cb = callback; cl.cl = closure; @@ -1232,6 +1250,9 @@ GenLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure, Ches wKing = WhiteUnicorn; bKing = BlackUnicorn; } + p = (flags & F_WHITE_ON_MOVE ? pieceDesc[wKing] : pieceDesc[bKing]); + if(p && strchr(p, 'O')) return FALSE; // [HGM] gen: castlings were already generated from string + for (ff = BOARD_WIDTH>>1; ff >= (BOARD_WIDTH-1)>>1; ff-- /*ics wild 1*/) { if ((flags & F_WHITE_ON_MOVE) && (flags & F_WHITE_KCASTLE_OK) &&