From: H.G. Muller Date: Sun, 10 Oct 2010 19:15:06 +0000 (+0200) Subject: Adapt WinBoard to Shogi implementation on Variant ICS X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=d75e8535ef79d4267faa60491d420b1d5c79a10c;p=xboard.git Adapt WinBoard to Shogi implementation on Variant ICS The Variant ICS does not use the '+P' notation for promoted pieces, neither in the board, nor in SAN, but simply indicates any Gold by 'G', and uses 'H' and 'D' for +B and +R. The Shogi promotion code in LegalityTest() and Disambiguate(), which are used in move Parsing, are adapted to handle this. Deferred promotions sent to the ICS now use an == suffix. --- diff --git a/backend.c b/backend.c index e5ac879..c517305 100644 --- a/backend.c +++ b/backend.c @@ -4684,7 +4684,7 @@ SendMoveToICS(moveType, fromX, fromY, toX, toY, promoChar) break; case WhiteNonPromotion: case BlackNonPromotion: - sprintf(user_move, "%c%c%c%c=\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY); + sprintf(user_move, "%c%c%c%c==\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY); break; case WhitePromotion: case BlackPromotion: diff --git a/moves.c b/moves.c index 1637e88..f2cc28c 100644 --- a/moves.c +++ b/moves.c @@ -1034,8 +1034,12 @@ ChessMove LegalityTest(board, flags, rf, ff, rt, ft, promoChar) ChessSquare piece = board[rf][ff]; if(promoChar == PieceToChar(BlackQueen)) promoChar = NULLCHAR; /* [HGM] Kludge */ - if(promoChar != NULLCHAR && promoChar != '+' && promoChar != '=' && - ToUpper(PieceToChar(PROMOTED piece)) != ToUpper(promoChar) ) + if(promoChar == 'd' && (piece == WhiteRook || piece == BlackRook) || + promoChar == 'h' && (piece == WhiteBishop || piece == BlackBishop) || + promoChar == 'g' && (piece <= WhiteFerz || piece <= BlackFerz && piece >= BlackPawn) ) + promoChar = '+'; // allowed ICS notations +if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promoChar : '-'); + if(promoChar != NULLCHAR && promoChar != '+' && promoChar != '=') cl.kind = IllegalMove; else if(flags & F_WHITE_ON_MOVE) { if( (int) piece < (int) WhiteWazir && @@ -1045,9 +1049,7 @@ ChessMove LegalityTest(board, flags, rf, ff, rt, ft, promoChar) cl.kind = promoChar == '=' ? IllegalMove : WhitePromotion; else /* promotion optional, default is promote */ cl.kind = promoChar == '=' ? WhiteNonPromotion : WhitePromotion; - - } else cl.kind = (promoChar == NULLCHAR || promoChar == 'x' || promoChar == '=') ? - NormalMove : IllegalMove; + } else cl.kind = (promoChar == NULLCHAR || promoChar == '=') ? NormalMove : IllegalMove; } else { if( (int) piece < (int) BlackWazir && (rf < BOARD_HEIGHT/3 || rt < BOARD_HEIGHT/3) ) { if( (piece == BlackPawn || piece == BlackQueen) && rt < 1 || @@ -1230,9 +1232,12 @@ void Disambiguate(board, flags, closure) /* [HGM] Shogi promotions. On input, '=' means defer, NULL promote. Afterwards, c is set to '+' for promotions, NULL other */ if(closure->rfIn != DROP_RANK && closure->kind == NormalMove) { ChessSquare piece = closure->piece; - if(c != NULLCHAR && c != '+' && c != '=' && - ToUpper(PieceToChar(PROMOTED piece)) != ToUpper(c) ) - closure->kind = IllegalMove; // the only allowed cases are '+', '=' and the promoted partner. + if (c == 'd' && (piece == WhiteRook || piece == BlackRook) || + c == 'h' && (piece == WhiteBishop || piece == BlackBishop) || + c == 'g' && (piece <= WhiteFerz || piece <= BlackFerz && piece >= BlackPawn) ) + c = '+'; // allowed ICS notations + if(c != NULLCHAR && c != '+' && c != '=') + closure->kind = IllegalMove; // the only allowed cases are '+', '='. 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)) ) { diff --git a/parser.l b/parser.l index 0e4f898..307c948 100644 --- a/parser.l +++ b/parser.l @@ -236,6 +236,7 @@ extern void CopyBoard P((Board to, Board from)); piece = boards[yyboardindex] [currentMoveString[1] - ONE][currentMoveString[0] - AAA]; + if(PieceToChar(piece) == '+' && appData.icsActive) promoted = 1, yytext[skip3] = PieceToChar(DEMOTED piece); // trust ICS if(promoted) piece = (ChessSquare) (DEMOTED piece); c = PieceToChar(piece); if(c == '~') c = PieceToChar((ChessSquare) (DEMOTED piece));