| 28 */ |
28 */ |
| 29 |
29 |
| 30 #include "rules.h" |
30 #include "rules.h" |
| 31 #include "rook.h" |
31 #include "rook.h" |
| 32 |
32 |
| 33 _Bool rook_chkrules(Move *move) { |
33 bool rook_chkrules(Move *move) { |
| 34 return move->torow == move->fromrow || move->tofile == move->fromfile; |
34 return move->torow == move->fromrow || move->tofile == move->fromfile; |
| 35 } |
35 } |
| 36 |
36 |
| 37 _Bool rook_isblocked(GameState *gamestate, Move *move) { |
37 bool rook_isblocked(GameState *gamestate, Move *move) { |
| 38 |
38 |
| 39 if (move->torow == move->fromrow) { |
39 if (move->torow == move->fromrow) { |
| 40 int d = move->tofile > move->fromfile ? 1 : -1; |
40 int d = move->tofile > move->fromfile ? 1 : -1; |
| 41 uint8_t f = move->fromfile; |
41 uint8_t f = move->fromfile; |
| 42 while (f != move->tofile-d) { |
42 while (f != move->tofile-d) { |
| 43 f += d; |
43 f += d; |
| 44 if (gamestate->board[move->fromrow][f]) { |
44 if (gamestate->board[move->fromrow][f]) { |
| 45 return 1; |
45 return true; |
| 46 } |
46 } |
| 47 } |
47 } |
| 48 } else { |
48 } else { |
| 49 int d = move->torow > move->fromrow ? 1 : -1; |
49 int d = move->torow > move->fromrow ? 1 : -1; |
| 50 uint8_t r = move->fromrow; |
50 uint8_t r = move->fromrow; |
| 51 while (r != move->torow - d) { |
51 while (r != move->torow - d) { |
| 52 r += d; |
52 r += d; |
| 53 if (gamestate->board[r][move->fromfile]) { |
53 if (gamestate->board[r][move->fromfile]) { |
| 54 return 1; |
54 return true; |
| 55 } |
55 } |
| 56 } |
56 } |
| 57 } |
57 } |
| 58 |
58 |
| 59 return 0; |
59 return false; |
| 60 } |
60 } |