src/chess/pawn.c

changeset 23
824c9522ce66
parent 19
6a26114297a1
child 47
d726e4b46c33
equal deleted inserted replaced
22:41bbfd4d17a3 23:824c9522ce66
28 */ 28 */
29 29
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(GameState *gamestate, 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 35
36 if (move->torow == (d < 0 ? 7 : 0)) { 36 if (move->torow == (d < 0 ? 7 : 0)) {
37 if (move->promotion) { 37 if (move->promotion) {
38 uint8_t promopiece = move->promotion & PIECE_MASK; 38 uint8_t promopiece = move->promotion & PIECE_MASK;
51 if (move->capture) { 51 if (move->capture) {
52 if (move->fromrow == move->torow + d && ( 52 if (move->fromrow == move->torow + 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 mdst(board,move) 56 return mdst(gamestate->board, move) ||
57 || (board[move->fromrow][move->tofile] & ENPASSANT_THREAT); 57 (gamestate->board[move->fromrow][move->tofile]
58 & ENPASSANT_THREAT);
58 } else { 59 } else {
59 return 0; 60 return 0;
60 } 61 }
61 } else { 62 } else {
62 if (move->fromfile == move->tofile) { 63 if (move->fromfile == move->tofile) {
67 return 0; 68 return 0;
68 } 69 }
69 } 70 }
70 } 71 }
71 72
72 _Bool pawn_isblocked(Board board, Move *move) { 73 _Bool pawn_isblocked(GameState *gamestate, Move *move) {
73 return mdst(board,move) && !move->capture; 74 return mdst(gamestate->board, move) && !move->capture;
74 } 75 }
75 76
76 int pawn_getlocation(Board board, Move *move) { 77 int pawn_getlocation(GameState *gamestate, Move *move) {
77 int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1); 78 int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1);
78 79
79 if (move->fromfile == POS_UNSPECIFIED) { 80 if (move->fromfile == POS_UNSPECIFIED) {
80 move->fromfile = move->tofile; 81 move->fromfile = move->tofile;
81 } 82 }
83 if (move->fromrow > 6) { 84 if (move->fromrow > 6) {
84 return INVALID_POSITION; 85 return INVALID_POSITION;
85 } else { 86 } else {
86 /* advanced first move */ 87 /* advanced first move */
87 if (move->fromrow == (d < 0 ? 2 : 5) && 88 if (move->fromrow == (d < 0 ? 2 : 5) &&
88 msrc(board,move) != move->piece) { 89 msrc(gamestate->board,move) != move->piece) {
89 90
90 move->fromrow += d; 91 move->fromrow += d;
91 if (move->fromrow > 6) { 92 if (move->fromrow > 6) {
92 return INVALID_POSITION; 93 return INVALID_POSITION;
93 } 94 }

mercurial