git.haldean.org grandmaster / c5879ba
send board history along with game state haldean 6 months ago
1 changed file(s) with 59 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
145145 }
146146
147147 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;
150154 int rank;
151155 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;
164156 char piece_name[3];
165157
166 board_root = json_object();
167158 board_array = json_array();
168159
169160 for (rank = 0; rank < 8; rank++)
187178 }
188179 json_array_append_new(board_array, rank_array);
189180 }
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);
190204
191205 json_set(board_root, "board", board_array);
192206
248262 move_to_json(const struct move *move)
249263 {
250264 json_t *root;
251 json_t *temp;
265 json_t *t1;
266 json_t *t2;
267 const struct move *m;
252268
253269 root = json_object();
254270
255271 if (move->algebraic != NULL)
256272 {
257 temp = json_string(move->algebraic);
273 t1 = json_string(move->algebraic);
258274 }
259275 else
260276 {
261 temp = json_null();
262 }
263 json_set(root, "algebraic", temp);
277 t1 = json_null();
278 }
279 json_set(root, "algebraic", t1);
264280
265281 if (move->post_board != NULL)
266282 {
267 temp = board_to_json(move->post_board, move);
283 t1 = board_to_json(move->post_board, move);
268284 }
269285 else
270286 {
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);
284309
285310 return root;
286311 }