X-Git-Url: http://winboard.nl/cgi-bin?p=capablanca.git;a=blobdiff_plain;f=lasker-2.2.3%2Fsrc%2Fmovecheck.c;h=c0dd853effa9629da1f31b236b18ffc5b9119b5b;hp=953298c68a66748e98f7974aef7547e06479f9a5;hb=d047d3cf2718e831b4cb81aba3c4111c041fc22d;hpb=707e46a1e2dba3ef53b97c63520d50f4ecc3996b diff --git a/lasker-2.2.3/src/movecheck.c b/lasker-2.2.3/src/movecheck.c index 953298c..c0dd853 100644 --- a/lasker-2.2.3/src/movecheck.c +++ b/lasker-2.2.3/src/movecheck.c @@ -141,7 +141,7 @@ int InitPieceLoop(board_t b, int *f, int *r, int color) static int legal_pawn_move( struct game_state_t *gs, int ff, int fr, int tf, int tr ) { if (ff == tf) { - if (gs->board[tf][tr] != NOPIECE && !gs->palace) return 0; // [HGM] XQ pawns can capture straight ahead + if (gs->board[tf][tr] != NOPIECE && !gs->palace && gs->promoType != 3) return 0; // [HGM] XQ and Shogi pawns can capture straight ahead if (gs->onMove == WHITE) { if (tr - fr == 1) return 1; if ((fr <= gs->pawnDblStep) && (tr - fr == 2) && gs->board[ff][fr+1]==NOPIECE) return 1; @@ -151,7 +151,7 @@ static int legal_pawn_move( struct game_state_t *gs, int ff, int fr, int tf, int } return 0; } - if (ff != tf) { /* Capture ? */ + if (ff != tf && gs->promoType != 3) { /* Capture ? ([HGM] but not in Shogi) */ if ((ff - tf != 1) && (tf - ff != 1)) return 0; if (gs->onMove == WHITE) { if(gs->palace) return (fr >= gs->ranks/2 && fr == tr); // [HGM] XQ promoted pawns @@ -621,21 +621,23 @@ static void possible_pawn_moves(struct game_state_t * gs, int *posf, int *posr, int *numpos) { if (gs->onMove == WHITE) { - if (gs->board[onf][onr + 1] == NOPIECE || gs->palace) { + if (gs->board[onf][onr + 1] == NOPIECE || gs->palace || gs->promoType == 3) { add_pos(onf, onr + 1, posf, posr, numpos); if ((onr <= gs->pawnDblStep) && (gs->board[onf][onr + 2] == NOPIECE)) add_pos(onf, onr + 2, posf, posr, numpos); } if (onf > 0) { if (gs->board[onf - 1][onr + 1] != NOPIECE && - iscolor(gs->board[onf - 1][onr + 1], BLACK)) + iscolor(gs->board[onf - 1][onr + 1], BLACK) && + !gs->palace && gs->promoType != 3) // no diagonal capture in XQ and Shogi add_pos(onf - 1, onr + 1, posf, posr, numpos); if(gs->palace && onr >= gs->ranks/2 && (gs->board[onf-1][onr] || iscolor(gs->board[onf-1][onr], BLACK))) add_pos(onf - 1, onr, posf, posr, numpos); // XQ promoted pawn } if (onf < gs->files-1) { if (gs->board[onf + 1][onr + 1] != NOPIECE && - iscolor(gs->board[onf + 1][onr + 1], BLACK)) + iscolor(gs->board[onf + 1][onr + 1], BLACK) && + !gs->palace && gs->promoType != 3) // no diagonal capture in XQ and Shogi add_pos(onf + 1, onr + 1, posf, posr, numpos); if(gs->palace && onr >= gs->ranks/2 && (gs->board[onf+1][onr] || iscolor(gs->board[onf+1][onr], BLACK))) add_pos(onf + 1, onr, posf, posr, numpos); // XQ promoted pawn @@ -645,21 +647,23 @@ static void possible_pawn_moves(struct game_state_t * gs, if (gs->ep_possible[0][onf] == 1) add_pos(onf + 1, onr + 1, posf, posr, numpos); } else { - if (gs->board[onf][onr - 1] == NOPIECE || gs->palace) { + if (gs->board[onf][onr - 1] == NOPIECE || gs->palace || gs->promoType == 3) { add_pos(onf, onr - 1, posf, posr, numpos); if ((onr >= gs->ranks - gs->pawnDblStep - 1) && (gs->board[onf][onr - 2] == NOPIECE)) add_pos(onf, onr - 2, posf, posr, numpos); } if (onf > 0) { if (gs->board[onf - 1][onr - 1] != NOPIECE && - iscolor(gs->board[onf - 1][onr - 1], WHITE)) + iscolor(gs->board[onf - 1][onr - 1], WHITE) && + !gs->palace && gs->promoType != 3) // no diagonal capture in XQ and Shogi add_pos(onf - 1, onr - 1, posf, posr, numpos); if(gs->palace && onr < gs->ranks/2 && !iscolor(gs->board[onf-1][onr], BLACK)) add_pos(onf - 1, onr, posf, posr, numpos); // XQ promoted pawn } if (onf < gs->files-1) { if (gs->board[onf + 1][onr - 1] != NOPIECE && - iscolor(gs->board[onf + 1][onr - 1], WHITE)) + iscolor(gs->board[onf + 1][onr - 1], WHITE) && + !gs->palace && gs->promoType != 3) // no diagonal capture in XQ and Shogi add_pos(onf + 1, onr - 1, posf, posr, numpos); if(gs->palace && onr < gs->ranks/2 && !iscolor(gs->board[onf+1][onr], BLACK)) add_pos(onf + 1, onr, posf, posr, numpos); // XQ promoted pawn @@ -1479,6 +1483,38 @@ static int move_calculate(struct game_state_t * gs, struct move_t * mt, int prom // [HGM] castle: generalized castling, fr and tr give from and to file of Rook. sprintf(mt->moveString, mt->toRank > mt->toFile ? "o-o-o" : "o-o"); } else { + if(gs->promoType == 3) { // Shogi-style promotions: not just Pawns, but many pieces can promote + int piece = gs->board[mt->fromFile][mt->fromRank]; + mt->piecePromotionTo = NOPIECE; + if(colorval(piece) == WHITE && mt->fromRank < gs->ranks - gs->ranks/3 + && mt->toRank < gs->ranks - gs->ranks/3 || + colorval(piece) == BLACK && mt->fromRank >= gs->ranks/3 + && mt->toRank >= gs->ranks/3 ) + promote = NOPIECE; // suppress promotion outside zone + if(promote) { // promotion piece determined by original, no matter what was requested + switch(piecetype(piece)) { + case PAWN: + case LANCE: + case KNIGHT: + case SILVER: + promote = GOLD; break; + case BISHOP: + promote = DRAGONHORSE; break; + case ROOK: + promote = DRAGONKING; break; + default: promote = NOPIECE; // not a promotion + } + } else + switch(piecetype(piece)) { // force mandatory promotions + case KNIGHT: + if(mt->toRank == 1 || mt->toRank == gs->files-2) promote = GOLD; + case PAWN: + case LANCE: + if(mt->toRank == 0 || mt->toRank == gs->files-1) promote = GOLD; + default: break; + } + if(promote) mt->piecePromotionTo = promote | (colorval(gs->board[mt->fromFile][mt->fromRank])); + } else if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN) && !gs->palace && // [HGM] XQ: no promotions in xiangqi ((mt->toRank == 0) || (mt->toRank == gs->ranks-1))) { @@ -1820,8 +1856,9 @@ int parse_move(char *mstr, struct game_state_t * gs, struct move_t * mt, int pro mt->fromFile = ALG_CASTLE; } - if (mt->piecePromotionTo != NOPIECE) { + if (mt->piecePromotionTo != NOPIECE) { promote = piecetype(mt->piecePromotionTo); +printf("promotion piece = %d, type = %d",mt->piecePromotionTo, promote); } return move_calculate(gs, mt, promote);