| 87 is_covered(gamestate, move->torow, midfile, opponent_color); |
85 is_covered(gamestate, move->torow, midfile, opponent_color); |
| 88 } |
86 } |
| 89 |
87 |
| 90 return blocked; |
88 return blocked; |
| 91 } |
89 } |
| |
90 |
| |
91 size_t king_moves(GameState *gamestate, Color c, Row r, File f, Move *moves) { |
| |
92 |
| |
93 size_t count = 0; |
| |
94 Piece king = mkpiece(KING, c); |
| |
95 |
| |
96 for (int dr = -1 ; dr <= 1 ; dr++) { |
| |
97 for (int df = -1 ; df <= 1 ; df++) { |
| |
98 if (dr == 0 && df == 0) { |
| |
99 continue; |
| |
100 } |
| |
101 |
| |
102 Row torow = r + dr; |
| |
103 File tofile = f + df; |
| |
104 |
| |
105 if (!isidx(torow) || !isidx(tofile)) { |
| |
106 continue; |
| |
107 } |
| |
108 |
| |
109 moves[count] = (Move){0}; |
| |
110 moves[count].piece = king; |
| |
111 moves[count].fromrow = r; |
| |
112 moves[count].fromfile = f; |
| |
113 moves[count].torow = torow; |
| |
114 moves[count].tofile = tofile; |
| |
115 moves[count].capture = piece_at(gamestate, torow, tofile) != 0; |
| |
116 count++; |
| |
117 } |
| |
118 } |
| |
119 |
| |
120 Row homerow = c == WHITE ? 0 : 7; |
| |
121 if (r == homerow && f == fileidx('e')) { |
| |
122 moves[count] = (Move){0}; |
| |
123 moves[count].piece = king; |
| |
124 moves[count].fromrow = r; |
| |
125 moves[count].fromfile = f; |
| |
126 moves[count].torow = r; |
| |
127 moves[count].tofile = fileidx('c'); |
| |
128 count++; |
| |
129 |
| |
130 moves[count] = (Move){0}; |
| |
131 moves[count].piece = king; |
| |
132 moves[count].fromrow = r; |
| |
133 moves[count].fromfile = f; |
| |
134 moves[count].torow = r; |
| |
135 moves[count].tofile = fileidx('g'); |
| |
136 count++; |
| |
137 } |
| |
138 |
| |
139 return count; |
| |
140 } |