X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=lasker-2.2.3%2Fsrc%2Fmovecheck.c;h=30405fa0635d7f1f40f40f0fd7012f6daa1a07e7;hb=d5de5c406540b053c30e9732ae6c7b93c594bf27;hp=1f6d69b57d6e58354c12b8d00e2f58831279cecb;hpb=b0878c4bb13c5ba03f6defe11f903fa07247b718;p=capablanca.git diff --git a/lasker-2.2.3/src/movecheck.c b/lasker-2.2.3/src/movecheck.c index 1f6d69b..30405fa 100644 --- a/lasker-2.2.3/src/movecheck.c +++ b/lasker-2.2.3/src/movecheck.c @@ -218,7 +218,7 @@ static int legal_honorablehorse_move(struct game_state_t * gs, int ff, int fr, i dx = ff - tf; dy = fr - tr; - if (dy == gs->onMove == WHITE ? 2 : -2) { + if (dy == (gs->onMove == WHITE ? -2 : 2)) { if (abs(dx) == 1) return 1; } @@ -1510,7 +1510,7 @@ static int move_calculate(struct game_state_t * gs, struct move_t * mt, int prom switch(piecetype(piece)) { case PAWN: case LANCE: - case KNIGHT: + case HONORABLEHORSE: case SILVER: promote = GOLD; break; case BISHOP: @@ -1521,7 +1521,7 @@ static int move_calculate(struct game_state_t * gs, struct move_t * mt, int prom } } else switch(piecetype(piece)) { // force mandatory promotions - case KNIGHT: + case HONORABLEHORSE: if(mt->toRank == 1 || mt->toRank == gs->files-2) promote = GOLD; case PAWN: case LANCE: @@ -1532,11 +1532,19 @@ static int move_calculate(struct game_state_t * gs, struct move_t * mt, int prom } 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))) { + ((mt->toRank < gs->promoZone) || (mt->toRank >= gs->ranks - gs->promoZone))) { + int stm = colorval(gs->board[mt->fromFile][mt->fromRank]); + if(!promote && (mt->toRank == 0 || mt->toRank == gs->ranks-1)) { // promotion obligatory, but not specified + if(gs->promoType != 2) promote = QUEEN; else { // choose a default + for(promote=KING-1; promote>PAWN; promote--) if(gs->holding[stm == BLACK][promote-1]) break; + if(promote == PAWN) return MOVE_ILLEGAL; // nothing available + } + } // if not obligatory, we defer unless promoton was explicitly specified! if(!gs->pawnDblStep && promote == PRINCESS) promote = MAN2; if(!gs->pawnDblStep && promote != FERZ2 && promote != MAN2) promote = FERZ; // [HGM] kludge to recognize shatranj - mt->piecePromotionTo = promote | - (colorval(gs->board[mt->fromFile][mt->fromRank])); + // non-promotion can still be an option for deeper promotion zones + mt->piecePromotionTo = promote ? (promote | stm) : NOPIECE; + if(promote && gs->promoType == 2 && !gs->holding[stm == BLACK][promote-1]) return MOVE_ILLEGAL; // unavailable piece specified } else { mt->piecePromotionTo = NOPIECE; } @@ -1569,7 +1577,7 @@ static int move_calculate(struct game_state_t * gs, struct move_t * mt, int prom sprintf(mt->algString, alg_unparse(gs, mt)); fakeMove = *gs; - /* Calculates enPassant also */ + /* Calculates enPassant also */ execute_move(&fakeMove, mt, 0); /* Does making this move leave ME in check? */ @@ -1585,6 +1593,7 @@ int legal_andcheck_move(struct game_state_t * gs, int tFile, int tRank) { struct move_t mt; + if (!legal_move(gs, fFile, fRank, tFile, tRank)) return 0; mt.color = gs->onMove; @@ -1593,7 +1602,7 @@ int legal_andcheck_move(struct game_state_t * gs, mt.toFile = tFile; mt.toRank = tRank; /* This should take into account a pawn promoting to another piece */ - if (move_calculate(gs, &mt, QUEEN) == MOVE_OK) + if (move_calculate(gs, &mt, NOPIECE) == MOVE_OK) return 1; else return 0; @@ -1628,7 +1637,7 @@ int in_check(struct game_state_t * gs) } for (InitPieceLoop(gs->board, &f, &r, gs->onMove); NextPieceLoop(gs->board, &f, &r, gs->onMove, gs->files, gs->ranks);) { - if (legal_move(gs, f, r, kf, kr)) { /* In Check? */ + if (legal_move(gs, f, r, kf, kr)) { /* In Check? */ return 1; } } @@ -1767,10 +1776,8 @@ int has_legal_move(struct game_state_t * gs) if(game_globals.garray[gs->gameNum].link < 0) { // we have no partner, so we must have something to drop now for(i=QUEEN; i>=PAWN; i--) - if(gs->holding[gs->onMove==WHITE ? 0 : 1][i-1]) break; - if(i > PAWN) return 1; // we have a non-Pawn to drop - // We have a Pawn, but check if it legal to drop it - if(i == PAWN && r != 0 && r != gs->ranks-1) return 1; // [HGM] todo: for Shogi there are extra conditions on Pawn drops! + if (legal_andcheck_move(gs, ALG_DROP, i, f, r)) return 1; + return 0; } return 1; } @@ -1873,7 +1880,6 @@ int parse_move(char *mstr, struct game_state_t * gs, struct move_t * mt, int pro if (mt->piecePromotionTo != NOPIECE) { promote = piecetype(mt->piecePromotionTo); -printf("promotion piece = %d, type = %d",mt->piecePromotionTo, promote); } return move_calculate(gs, mt, promote); @@ -1946,7 +1952,7 @@ int execute_move(struct game_state_t * gs, struct move_t * mt, int check_game_st for (i = 0; i < gs->files; i++) { gs->ep_possible[0][i] = 0; gs->ep_possible[1][i] = 0; - } + } /* Added by Sparky 3/16/95 From soso@Viktoria.drp.fmph.uniba.sk Thu Mar 16 13:08:51 1995 @@ -2060,7 +2066,8 @@ int execute_move(struct game_state_t * gs, struct move_t * mt, int check_game_st return MOVE_NOMATERIAL; } else { gs->onMove = CToggle(gs->onMove); - } + } + return MOVE_OK; }