src/chess/pawn.c

changeset 195
27d02ccb0cef
parent 194
619f07c95894
equal deleted inserted replaced
194:619f07c95894 195:27d02ccb0cef
51 if (move->capture) { 51 if (move->capture) {
52 if (move->fromrank == move->torank + d && ( 52 if (move->fromrank == move->torank + d && (
53 move->fromfile == move->tofile + 1 || 53 move->fromfile == move->tofile + 1 ||
54 move->fromfile == move->tofile - 1)) { 54 move->fromfile == move->tofile - 1)) {
55 55
56 return piece_at(gamestate, move->torank, move->tofile) || 56 return piece_at(gamestate, move->tofile, move->torank) ||
57 enpassant_threat_exists(gamestate, move->fromrank, move->tofile); 57 enpassant_threat_exists(gamestate,
58 move->tofile, move->fromrank);
58 } else { 59 } else {
59 return false; 60 return false;
60 } 61 }
61 } else { 62 } else {
62 if (move->fromfile == move->tofile) { 63 if (move->fromfile == move->tofile) {
70 } 71 }
71 72
72 bool pawn_isblocked(const GameState *gamestate, const Move *move) { 73 bool pawn_isblocked(const GameState *gamestate, const Move *move) {
73 if (move->torank == move->fromrank + 1 74 if (move->torank == move->fromrank + 1
74 || move->torank == move->fromrank - 1) { 75 || move->torank == move->fromrank - 1) {
75 return piece_at(gamestate, move->torank, move->tofile) 76 return piece_at(gamestate, move->tofile, move->torank)
76 && !move->capture; 77 && !move->capture;
77 } else { 78 } else {
78 return piece_at(gamestate, move->torank, move->tofile) || 79 return piece_at(gamestate, move->tofile, move->torank) ||
79 gamestate->board[(move->fromrank + move->torank) / 2][move->tofile]; 80 gamestate->board[(move->fromrank + move->torank) / 2][move->tofile];
80 } 81 }
81 } 82 }
82 83
83 size_t pawn_moves(const GameState *gamestate, 84 size_t pawn_moves(const GameState *gamestate,
84 Color c, Rank r, File f, Move *moves) { 85 Color c, File f, Rank r, Move *moves) {
85 (void) gamestate; /* no (theoretical) move depends on the game state */ 86 (void) gamestate; /* no (theoretical) move depends on the game state */
86 size_t count = 0; 87 size_t count = 0;
87 int rankdelta = c == WHITE ? 1 : -1; 88 int rankdelta = c == WHITE ? 1 : -1;
88 int promotionrank = c == WHITE ? 7 : 0; 89 int promotionrank = c == WHITE ? 7 : 0;
89 int startrank = c == WHITE ? 1 : 6; 90 int startrank = c == WHITE ? 1 : 6;

mercurial