src/rules/pawn.c

changeset 18
6008840b859e
parent 16
a298c6637c30
equal deleted inserted replaced
17:2aed5418e142 18:6008840b859e
30 #include "pawn.h" 30 #include "pawn.h"
31 #include "rules.h" 31 #include "rules.h"
32 32
33 _Bool pawn_chkrules(Board board, Move *move) { 33 _Bool pawn_chkrules(Board board, Move *move) {
34 int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1); 34 int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1);
35
36 if (move->torow == (d < 0 ? 7 : 0)) {
37 if (move->promotion) {
38 uint8_t promopiece = move->promotion & PIECE_MASK;
39 if (!promopiece || promopiece == PAWN || promopiece == KING) {
40 return FALSE;
41 }
42 } else {
43 return FALSE;
44 }
45 } else {
46 if (move->promotion) {
47 return FALSE;
48 }
49 }
50
35 if (move->capture) { 51 if (move->capture) {
36 if (move->fromrow == move->torow + d && ( 52 if (move->fromrow == move->torow + d && (
37 move->fromfile == move->tofile + 1 || 53 move->fromfile == move->tofile + 1 ||
38 move->fromfile == move->tofile - 1)) { 54 move->fromfile == move->tofile - 1)) {
39 55

mercurial