src/chess/rules.c

changeset 185
c0acc89d6c01
parent 182
04c65336777f
child 186
8230904458a7
equal deleted inserted replaced
184:93c81539b702 185:c0acc89d6c01
643 return INVALID_MOVE_SYNTAX; 643 return INVALID_MOVE_SYNTAX;
644 } 644 }
645 645
646 /* must move */ 646 /* must move */
647 if (move->fromfile == move->tofile && move->fromrow == move->torow) { 647 if (move->fromfile == move->tofile && move->fromrow == move->torow) {
648 return INVALID_MOVE_SYNTAX; 648 return RULES_VIOLATED;
649 } 649 }
650 650
651 /* does piece exist */ 651 /* does piece exist */
652 if (piece_at(gamestate, msrc(move)) != move->piece) { 652 if (piece_at(gamestate, msrc(move)) != move->piece) {
653 return PIECE_NOT_FOUND; 653 return PIECE_NOT_FOUND;
665 if (!((piece_at_dst == 0) ^ move->capture)) { 665 if (!((piece_at_dst == 0) ^ move->capture)) {
666 /* ... or the capture happens en passant */ 666 /* ... or the capture happens en passant */
667 if (!move->capture || piece_type(move->piece) != PAWN || 667 if (!move->capture || piece_type(move->piece) != PAWN ||
668 !enpassant_threat_exists(gamestate, 668 !enpassant_threat_exists(gamestate,
669 move->fromrow, move->tofile)) { 669 move->fromrow, move->tofile)) {
670 return INVALID_MOVE_SYNTAX; 670 return RULES_VIOLATED;
671 } 671 }
672 } 672 }
673 673
674 /* validate individual rules */ 674 /* validate individual rules */
675 bool chkrules; 675 bool chkrules;

mercurial