| 30 #include "rules.h" |
30 #include "rules.h" |
| 31 #include "king.h" |
31 #include "king.h" |
| 32 |
32 |
| 33 #include <string.h> |
33 #include <string.h> |
| 34 |
34 |
| 35 static bool king_castling_chkmoved(GameState *gamestate, Row row, File file) { |
35 static bool king_castling_chkmoved( |
| |
36 const GameState *gamestate, Row row, File file) { |
| |
37 |
| 36 for (unsigned i = 0; i < gamestate->movecount; i++) { |
38 for (unsigned i = 0; i < gamestate->movecount; i++) { |
| 37 if (gamestate->moves[i].fromfile == file |
39 if (gamestate->moves[i].fromfile == file |
| 38 && gamestate->moves[i].fromrow == row) { |
40 && gamestate->moves[i].fromrow == row) { |
| 39 return true; |
41 return true; |
| 40 } |
42 } |
| 41 } |
43 } |
| 42 |
44 |
| 43 return false; |
45 return false; |
| 44 } |
46 } |
| 45 |
47 |
| 46 bool king_chkrules(GameState *gamestate, Move* move) { |
48 bool king_chkrules(const GameState *gamestate, const Move* move) { |
| 47 if (abs(move->torow - move->fromrow) <= 1 && |
49 if (abs(move->torow - move->fromrow) <= 1 && |
| 48 abs(move->tofile - move->fromfile) <= 1) { |
50 abs(move->tofile - move->fromfile) <= 1) { |
| 49 return true; |
51 return true; |
| 50 } else { |
52 } else { |
| 51 /* castling */ |
53 /* castling */ |
| 77 blocked |= gamestate->board[move->torow][fileidx('b')]; |
79 blocked |= gamestate->board[move->torow][fileidx('b')]; |
| 78 } |
80 } |
| 79 uint8_t midfile = (move->tofile+move->fromfile)/2; |
81 uint8_t midfile = (move->tofile+move->fromfile)/2; |
| 80 bool incheck = false; |
82 bool incheck = false; |
| 81 if (gamestate->movecount > 0) { |
83 if (gamestate->movecount > 0) { |
| 82 incheck = gamestate->moves[gamestate->movecount-1].check; |
84 incheck = is_check_position(gamestate); |
| 83 } |
85 } |
| 84 blocked |= incheck || gamestate->board[move->torow][midfile] || |
86 blocked |= incheck || gamestate->board[move->torow][midfile] || |
| 85 is_covered(gamestate, move->torow, midfile, opponent_color); |
87 is_covered(gamestate, move->torow, midfile, opponent_color); |
| 86 } |
88 } |
| 87 |
89 |