X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=88bbdee9706d05cc9d2445c21cb83f78064d811e;hb=17d5e197ff197599a155a56cf2adaca266774a48;hp=dbc8f41d47604b336834385fc7e1820003ab7ea7;hpb=3808a80498c0347b4ad4c52c4c1d7e93bcf57c1f;p=xboard.git diff --git a/moves.c b/moves.c index dbc8f41..88bbdee 100644 --- a/moves.c +++ b/moves.c @@ -385,7 +385,7 @@ MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle for(dir=0, bit=1; dir<8; dir++, bit += bit) { // loop over directions int i = expo, j = skip, hop = mode, vx, vy, loop = 0; if(!(bit & dirSet)) continue; // does not move in this direction - if(dy != 1) j = 0; // + if(dy != 1 || mode & 1024) j = 0; // vx = dx*rot[dir][0] + dy*rot[dir][1]; // rotate step vector vy = dx*rot[dir][2] + dy*rot[dir][3]; if(tx < 0) x = f, y = r; // start square @@ -433,17 +433,19 @@ MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle if(mode & 1024) { // castling i = 2; // kludge to elongate move indefinitely if(occup == 4) continue; // skip empty squares - if((x == BOARD_LEFT || vx < 0 && board[y][x-1] == DarkSquare) && board[y][x] == initialPosition[y][x]) { // reached initial corner piece + if((x == BOARD_LEFT + skip || x > BOARD_LEFT + skip && vx < 0 && board[y][x-1-skip] == DarkSquare) + && board[y][x] == initialPosition[y][x]) { // reached initial corner piece if(pc != WhiteKing && pc != BlackKing) { // non-royal castling (to be entered as two-leg move via 'Rook') - if(killX < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); - legNr <<= 1; cb(board, flags, NormalMove, r, f, y, f - expo, cl); legNr >>= 1; + if(killX < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); if(killX < f) + legNr <<= 1, cb(board, flags, NormalMove, r, f, y, f - expo, cl), legNr >>= 1; } else cb(board, flags, mine == 1 ? WhiteQueenSideCastle : BlackQueenSideCastle, r, f, y, f - expo, cl); } - if((x == BOARD_RGHT-1 || vx > 0 && board[y][x+1] == DarkSquare) && board[y][x] == initialPosition[y][x]) { + if((x == BOARD_RGHT-1-skip || x < BOARD_RGHT-1-skip && vx > 0 && board[y][x+1+skip] == DarkSquare) + && board[y][x] == initialPosition[y][x]) { if(pc != WhiteKing && pc != BlackKing) { - if(killX < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); - legNr <<= 1; cb(board, flags, NormalMove, r, f, y, f + expo, cl); legNr >>= 1; + if(killX < 0) cb(board, flags, FirstLeg, r, f, y, x, cl); if(killX > f) + legNr <<= 1, cb(board, flags, NormalMove, r, f, y, f + expo, cl), legNr >>= 1; } else cb(board, flags, mine == 1 ? WhiteKingSideCastle : BlackKingSideCastle, r, f, y, f + expo, cl); } @@ -1698,7 +1700,7 @@ CheckTest (Board board, int flags, int rf, int ff, int rt, int ft, int enPassant board[rf][ft] = captured; board[rt][ft] = EmptySquare; } else { - if(saveKill >= 0) board[killY][killX] = trampled, killX = saveKill; + if(saveKill >= 0) board[killY][killX = saveKill] = trampled; board[rt][ft] = captured; } board[EP_STATUS] = ep; @@ -1821,6 +1823,7 @@ LegalityTest (Board board, int flags, int rf, int ff, int rt, int ft, int promoC /* [HGM] Shogi promotions. '=' means defer */ if(rf != DROP_RANK && cl.kind == NormalMove) { ChessSquare piece = board[rf][ff]; + int zone = BOARD_HEIGHT/3 + (BOARD_HEIGHT == 8); if(promoChar == PieceToChar(BlackQueen)) promoChar = NULLCHAR; /* [HGM] Kludge */ if(promoChar == 'd' && (piece == WhiteRook || piece == BlackRook) || @@ -1832,7 +1835,7 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo return CharToPiece(promoChar) == EmptySquare ? ImpossibleMove : IllegalMove; else if(flags & F_WHITE_ON_MOVE) { if( (int) piece < (int) WhiteWazir && - (rf >= BOARD_HEIGHT - BOARD_HEIGHT/3 || rt >= BOARD_HEIGHT - BOARD_HEIGHT/3) ) { + (rf >= BOARD_HEIGHT - zone || rt >= BOARD_HEIGHT - zone) ) { if( (piece == WhitePawn || piece == WhiteQueen) && rt > BOARD_HEIGHT-2 || piece == WhiteKnight && rt > BOARD_HEIGHT-3) /* promotion mandatory */ cl.kind = promoChar == '=' ? IllegalMove : WhitePromotion; @@ -1840,7 +1843,7 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo cl.kind = promoChar == '+' ? WhitePromotion : WhiteNonPromotion; } else cl.kind = promoChar == '+' ? IllegalMove : NormalMove; } else { - if( (int) piece < (int) BlackWazir && (rf < BOARD_HEIGHT/3 || rt < BOARD_HEIGHT/3) ) { + if( (int) piece < (int) BlackWazir && (rf < zone || rt < zone) ) { if( (piece == BlackPawn || piece == BlackQueen) && rt < 1 || piece == BlackKnight && rt < 2 ) /* promotion obligatory */ cl.kind = promoChar == '=' ? IllegalMove : BlackPromotion; @@ -2077,6 +2080,7 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure) /* [HGM] Shogi promotions. On input, '=' means defer, '+' promote. Afterwards, c is set to '+' for promotions, NULL other */ if(closure->rfIn != DROP_RANK && closure->kind == NormalMove) { ChessSquare piece = closure->piece; + int zone = BOARD_HEIGHT/3 + (BOARD_HEIGHT == 8); if (c == 'd' && (piece == WhiteRook || piece == BlackRook) || c == 'h' && (piece == WhiteBishop || piece == BlackBishop) || c == 'g' && (piece <= WhiteFerz || piece <= BlackFerz && piece >= BlackPawn) ) @@ -2084,7 +2088,7 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure) if(c != NULLCHAR && c != '+' && c != '=') closure->kind = IllegalMove; // otherwise specifying a piece is illegal else if(flags & F_WHITE_ON_MOVE) { if( (int) piece < (int) WhiteWazir && - (closure->rf >= BOARD_HEIGHT-(BOARD_HEIGHT/3) || closure->rt >= BOARD_HEIGHT-(BOARD_HEIGHT/3)) ) { + (closure->rf >= BOARD_HEIGHT-zone || closure->rt >= BOARD_HEIGHT-zone) ) { if( (piece == WhitePawn || piece == WhiteQueen) && closure->rt > BOARD_HEIGHT-2 || piece == WhiteKnight && closure->rt > BOARD_HEIGHT-3) /* promotion mandatory */ closure->kind = c == '=' ? IllegalMove : WhitePromotion; @@ -2092,7 +2096,7 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure) closure->kind = c == '+' ? WhitePromotion : WhiteNonPromotion; } else closure->kind = c == '+' ? IllegalMove : NormalMove; } else { - if( (int) piece < (int) BlackWazir && (closure->rf < BOARD_HEIGHT/3 || closure->rt < BOARD_HEIGHT/3) ) { + if( (int) piece < (int) BlackWazir && (closure->rf < zone || closure->rt < zone) ) { if( (piece == BlackPawn || piece == BlackQueen) && closure->rt < 1 || piece == BlackKnight && closure->rt < 2 ) /* promotion obligatory */ closure->kind = c == '=' ? IllegalMove : BlackPromotion;