send board history along with game state
haldean
3 years ago
145 | 145 | } |
146 | 146 | |
147 | 147 | json_t * |
148 | board_to_json(const struct board *board, const struct move *move) | |
149 | { | |
148 | board_map_to_json(const struct board *board) | |
149 | { | |
150 | json_t *board_array; | |
151 | json_t *rank_array; | |
152 | json_t *temp; | |
153 | const struct piece *p; | |
150 | 154 | int rank; |
151 | 155 | int file; |
152 | int i; | |
153 | const struct position *a; | |
154 | const struct piece *p; | |
155 | char *pgn; | |
156 | char *fen; | |
157 | json_t *board_root; | |
158 | json_t *board_array; | |
159 | json_t *map_array; | |
160 | json_t *rank_array; | |
161 | json_t *access_array; | |
162 | json_t *available_castles; | |
163 | json_t *temp; | |
164 | 156 | char piece_name[3]; |
165 | 157 | |
166 | board_root = json_object(); | |
167 | 158 | board_array = json_array(); |
168 | 159 | |
169 | 160 | for (rank = 0; rank < 8; rank++) |
187 | 178 | } |
188 | 179 | json_array_append_new(board_array, rank_array); |
189 | 180 | } |
181 | ||
182 | return board_array; | |
183 | } | |
184 | ||
185 | json_t * | |
186 | board_to_json(const struct board *board, const struct move *move) | |
187 | { | |
188 | const struct position *a; | |
189 | char *pgn; | |
190 | char *fen; | |
191 | json_t *access_array; | |
192 | json_t *available_castles; | |
193 | json_t *board_array; | |
194 | json_t *board_root; | |
195 | json_t *map_array; | |
196 | json_t *rank_array; | |
197 | json_t *temp; | |
198 | int rank; | |
199 | int file; | |
200 | int i; | |
201 | ||
202 | board_root = json_object(); | |
203 | board_array = board_map_to_json(board); | |
190 | 204 | |
191 | 205 | json_set(board_root, "board", board_array); |
192 | 206 | |
248 | 262 | move_to_json(const struct move *move) |
249 | 263 | { |
250 | 264 | json_t *root; |
251 | json_t *temp; | |
265 | json_t *t1; | |
266 | json_t *t2; | |
267 | const struct move *m; | |
252 | 268 | |
253 | 269 | root = json_object(); |
254 | 270 | |
255 | 271 | if (move->algebraic != NULL) |
256 | 272 | { |
257 | temp = json_string(move->algebraic); | |
273 | t1 = json_string(move->algebraic); | |
258 | 274 | } |
259 | 275 | else |
260 | 276 | { |
261 | temp = json_null(); | |
262 | } | |
263 | json_set(root, "algebraic", temp); | |
277 | t1 = json_null(); | |
278 | } | |
279 | json_set(root, "algebraic", t1); | |
264 | 280 | |
265 | 281 | if (move->post_board != NULL) |
266 | 282 | { |
267 | temp = board_to_json(move->post_board, move); | |
283 | t1 = board_to_json(move->post_board, move); | |
268 | 284 | } |
269 | 285 | else |
270 | 286 | { |
271 | temp = json_null(); | |
272 | } | |
273 | json_set(root, "board", temp); | |
274 | ||
275 | temp = json_integer(move->start.rank); | |
276 | json_set(root, "start_rank", temp); | |
277 | temp = json_integer(move->start.file); | |
278 | json_set(root, "start_file", temp); | |
279 | ||
280 | temp = json_integer(move->end.rank); | |
281 | json_set(root, "end_rank", temp); | |
282 | temp = json_integer(move->end.file); | |
283 | json_set(root, "end_file", temp); | |
287 | t1 = json_null(); | |
288 | } | |
289 | json_set(root, "board", t1); | |
290 | ||
291 | t1 = json_integer(move->start.rank); | |
292 | json_set(root, "start_rank", t1); | |
293 | t1 = json_integer(move->start.file); | |
294 | json_set(root, "start_file", t1); | |
295 | ||
296 | t1 = json_integer(move->end.rank); | |
297 | json_set(root, "end_rank", t1); | |
298 | t1 = json_integer(move->end.file); | |
299 | json_set(root, "end_file", t1); | |
300 | ||
301 | t1 = json_array(); | |
302 | m = move->parent; | |
303 | for (m = move->parent; m != NULL; m = m->parent) | |
304 | { | |
305 | t2 = board_map_to_json(m->post_board); | |
306 | json_array_append_new(t1, t2); | |
307 | } | |
308 | json_set(root, "history", t1); | |
284 | 309 | |
285 | 310 | return root; |
286 | 311 | } |