src/chess/pgn.c

changeset 80
b980a7192b5a
parent 78
ceb9197b3c6d
child 81
82d3b044aa69
equal deleted inserted replaced
79:ffd452cf05ff 80:b980a7192b5a
61 61
62 char tagkey[32]; 62 char tagkey[32];
63 char tagvalue[128]; 63 char tagvalue[128];
64 64
65 /* read tag pairs */ 65 /* read tag pairs */
66 _Bool readmoves = 0; 66 bool readmoves = false;
67 while (!readmoves) { 67 while (!readmoves) {
68 while (isspace(c = fgetc(stream))); 68 while (isspace(c = fgetc(stream)));
69 if (c == '1') { 69 if (c == '1') {
70 readmoves = 1; 70 readmoves = true;
71 break; 71 break;
72 } 72 }
73 if (c != '[') { 73 if (c != '[') {
74 return pgn_error_missing_bracket; 74 return pgn_error_missing_bracket;
75 } 75 }
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

mercurial