src/chess/pawn.c

changeset 47
d726e4b46c33
parent 23
824c9522ce66
child 55
54ea19938d57
equal deleted inserted replaced
46:4dcfb4c58b6d 47:d726e4b46c33
69 } 69 }
70 } 70 }
71 } 71 }
72 72
73 _Bool pawn_isblocked(GameState *gamestate, Move *move) { 73 _Bool pawn_isblocked(GameState *gamestate, Move *move) {
74 return mdst(gamestate->board, move) && !move->capture; 74 if (move->torow == move->fromrow + 1 || move->torow == move->fromrow - 1) {
75 return mdst(gamestate->board, move) && !move->capture;
76 } else {
77 return mdst(gamestate->board, move) ||
78 gamestate->board[(move->fromrow+move->torow)/2][move->tofile];
79 }
75 } 80 }
76
77 int pawn_getlocation(GameState *gamestate, Move *move) {
78 int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1);
79
80 if (move->fromfile == POS_UNSPECIFIED) {
81 move->fromfile = move->tofile;
82 }
83 move->fromrow = move->torow + d;
84 if (move->fromrow > 6) {
85 return INVALID_POSITION;
86 } else {
87 /* advanced first move */
88 if (move->fromrow == (d < 0 ? 2 : 5) &&
89 msrc(gamestate->board,move) != move->piece) {
90
91 move->fromrow += d;
92 if (move->fromrow > 6) {
93 return INVALID_POSITION;
94 }
95 }
96 }
97 return VALID_MOVE_SYNTAX;
98 }

mercurial