| 253 const char *pgn_player_name(GameState *gamestate, uint8_t color) { |
253 const char *pgn_player_name(GameState *gamestate, uint8_t color) { |
| 254 const char *name = color == WHITE ? gamestate->wname : gamestate->bname; |
254 const char *name = color == WHITE ? gamestate->wname : gamestate->bname; |
| 255 return name[0] != '\0' ? name : "Anonymous"; |
255 return name[0] != '\0' ? name : "Anonymous"; |
| 256 } |
256 } |
| 257 |
257 |
| 258 void write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo, |
258 void write_pgn(FILE* stream, GameState *gamestate, bool export_comments) { |
| 259 bool export_comments) { |
|
| 260 /* STR tag pairs */ |
259 /* STR tag pairs */ |
| 261 fprintf(stream, "[Event \"%s\"]\n", "terminal-chess game"); |
260 fprintf(stream, "[Event \"%s\"]\n", "terminal-chess game"); |
| 262 fprintf(stream, "[Site \"%s\"]\n", "Somewhere on Earth"); |
261 fprintf(stream, "[Site \"%s\"]\n", "Somewhere on Earth"); |
| 263 fprintf(stream, "[Date \"%s\"]\n", pgn_date(gamestate)); |
262 fprintf(stream, "[Date \"%s\"]\n", pgn_date(gamestate)); |
| 264 fprintf(stream, "[Round \"%s\"]\n", "-"); |
263 fprintf(stream, "[Round \"%s\"]\n", "-"); |
| 325 *(moveblkptr++) = ' '; |
324 *(moveblkptr++) = ' '; |
| 326 continue; |
325 continue; |
| 327 } |
326 } |
| 328 |
327 |
| 329 /* add clock times when the game was under time control */ |
328 /* add clock times when the game was under time control */ |
| 330 if (gameinfo->timecontrol) { |
329 if (gamestate->info.timecontrol) { |
| 331 memcpy(moveblkptr, " {[%clk ", 8); |
330 memcpy(moveblkptr, " {[%clk ", 8); |
| 332 moveblkptr += 8; |
331 moveblkptr += 8; |
| 333 unsigned clkmv = i + 2; /* time for the next move! */ |
332 unsigned clkmv = i + 2; /* time for the next move! */ |
| 334 uint16_t clk = remaining_movetime2(gameinfo, gamestate, clkmv); |
333 uint16_t clk = remaining_movetime2(gamestate, clkmv); |
| 335 snpr = print_clk(clk, moveblkptr, true); |
334 snpr = print_clk(clk, moveblkptr, true); |
| 336 moveblkptr += snpr; |
335 moveblkptr += snpr; |
| 337 *(moveblkptr++) = ']'; |
336 *(moveblkptr++) = ']'; |
| 338 *(moveblkptr++) = '}'; |
337 *(moveblkptr++) = '}'; |
| 339 |
338 |