| 43 return bishop_isblocked(gamestate, move); |
43 return bishop_isblocked(gamestate, move); |
| 44 } |
44 } |
| 45 } |
45 } |
| 46 |
46 |
| 47 size_t queen_moves(const GameState *gamestate, |
47 size_t queen_moves(const GameState *gamestate, |
| 48 Color c, Row r, File f, Move *moves) { |
48 Color c, Rank r, File f, Move *moves) { |
| 49 |
49 |
| 50 size_t count = 0; |
50 size_t count = 0; |
| 51 const int directions[8][2] = { |
51 const int directions[8][2] = { |
| 52 { 1, 0}, |
52 { 1, 0}, |
| 53 {-1, 0}, |
53 {-1, 0}, |
| 58 {-1, 1}, |
58 {-1, 1}, |
| 59 {-1, -1} |
59 {-1, -1} |
| 60 }; |
60 }; |
| 61 |
61 |
| 62 for (size_t i = 0 ; i < 8 ; i++) { |
62 for (size_t i = 0 ; i < 8 ; i++) { |
| 63 int row = r + directions[i][0]; |
63 Rank rank = r + directions[i][0]; |
| 64 int file = f + directions[i][1]; |
64 File file = f + directions[i][1]; |
| 65 |
65 |
| 66 while (isidx(row) && isidx(file)) { |
66 while (isidx(rank) && isidx(file)) { |
| 67 moves[count] = (Move){0}; |
67 moves[count] = (Move){0}; |
| 68 moves[count].piece = mkpiece(QUEEN, c); |
68 moves[count].piece = mkpiece(QUEEN, c); |
| 69 moves[count].fromrow = r; |
69 moves[count].fromrank = r; |
| 70 moves[count].fromfile = f; |
70 moves[count].fromfile = f; |
| 71 moves[count].torow = row; |
71 moves[count].torank = rank; |
| 72 moves[count].tofile = file; |
72 moves[count].tofile = file; |
| 73 moves[count].capture = piece_at(gamestate, row, file) != 0; |
73 moves[count].capture = piece_at(gamestate, rank, file) != 0; |
| 74 count++; |
74 count++; |
| 75 |
75 |
| 76 row += directions[i][0]; |
76 rank += directions[i][0]; |
| 77 file += directions[i][1]; |
77 file += directions[i][1]; |
| 78 } |
78 } |
| 79 } |
79 } |
| 80 |
80 |
| 81 return count; |
81 return count; |