src/chess/rules.c

changeset 151
f1b6a0388d85
parent 147
7e3f2d462bb6
equal deleted inserted replaced
150:7d57a252948e 151:f1b6a0388d85
356 if ((mdst(gamestate->board, move) & COLOR_MASK) 356 if ((mdst(gamestate->board, move) & COLOR_MASK)
357 == (move->piece & COLOR_MASK)) { 357 == (move->piece & COLOR_MASK)) {
358 return RULES_VIOLATED; 358 return RULES_VIOLATED;
359 } 359 }
360 360
361 /* must capture, if and only if destination is occupied */ 361 /* must capture, if and only if destination is occupied... */
362 if ((mdst(gamestate->board, move) == 0 && move->capture) || 362 if ((mdst(gamestate->board, move) == 0 && move->capture) ||
363 (mdst(gamestate->board, move) != 0 && !move->capture)) { 363 (mdst(gamestate->board, move) != 0 && !move->capture)) {
364 return INVALID_MOVE_SYNTAX; 364 /* ... or the capture happens en passant */
365 if (!move->capture || (move->piece & PIECE_MASK) != PAWN ||
366 !(gamestate->board[move->fromrow][move->tofile]
367 & ENPASSANT_THREAT)) {
368 return INVALID_MOVE_SYNTAX;
369 }
365 } 370 }
366 371
367 /* validate individual rules */ 372 /* validate individual rules */
368 bool chkrules; 373 bool chkrules;
369 switch (move->piece & PIECE_MASK) { 374 switch (move->piece & PIECE_MASK) {

mercurial