277 str[0] = color == WHITE ? 'w' : 'b'; |
277 str[0] = color == WHITE ? 'w' : 'b'; |
278 |
278 |
279 return 1; |
279 return 1; |
280 } |
280 } |
281 |
281 |
282 static _Bool fen_castling_chkmoved(GameState *gamestate, |
282 static bool fen_castling_chkmoved(GameState *gamestate, |
283 uint8_t row, uint8_t file) { |
283 uint8_t row, uint8_t file) { |
284 |
284 |
285 MoveList *ml = gamestate->movelist; |
285 MoveList *ml = gamestate->movelist; |
286 while (ml) { |
286 while (ml) { |
287 if (ml->move.fromfile == file && ml->move.fromrow == row) { |
287 if (ml->move.fromfile == file && ml->move.fromrow == row) { |
288 return 1; |
288 return true; |
289 } |
289 } |
290 ml = ml->next; |
290 ml = ml->next; |
291 } |
291 } |
292 |
292 |
293 return 0; |
293 return false; |
294 } |
294 } |
295 |
295 |
296 static size_t fen_castling(char *str, GameState *gamestate) { |
296 static size_t fen_castling(char *str, GameState *gamestate) { |
297 _Bool K, Q, k, q; |
297 bool K, Q, k, q; |
298 |
298 |
299 if (fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('e'))) { |
299 if (fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('e'))) { |
300 K = Q = 0; |
300 K = Q = false; |
301 } else { |
301 } else { |
302 K = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('h')); |
302 K = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('h')); |
303 Q = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('a')); |
303 Q = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('a')); |
304 } |
304 } |
305 if (fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('e'))) { |
305 if (fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('e'))) { |
306 k = q = 0; |
306 k = q = false; |
307 } else { |
307 } else { |
308 k = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('h')); |
308 k = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('h')); |
309 q = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('a')); |
309 q = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('a')); |
310 } |
310 } |
311 |
311 |