savegame.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* This file contains the history-mechanism for CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of CHESS.
  4. CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. CHESS, but only under the conditions described in the
  12. CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. #include <stdio.h>
  18. #include "algdefs.h"
  19. #include "fixeddefs.h"
  20. #include "crucialdefs.h"
  21. #include "externmap.h"
  22. #include "bitmacs.h"
  23. #include "movelist.h"
  24. FILE *hisf;
  25. char *histmp = "gameXXXXXX";
  26. extern int ngamemvs;
  27. extern struct gmlist game[MAXGAME];
  28. extern char *sqchar[];
  29. zero_game()
  30. {
  31. int i;
  32. for (i = 0; i < MAXGAME; i++)
  33. game[i].depth = -1;
  34. }
  35. write_game()
  36. {
  37. int i;
  38. if (ngamemvs == -1)
  39. {
  40. printf("Sorry, game not played yet.\n");
  41. return;
  42. }
  43. unlink(histmp);
  44. mktemp(histmp);
  45. unlink(histmp);
  46. hisf = fopen(histmp,"w");
  47. if (hisf == NULL)
  48. {
  49. fprintf(stderr, "cannot open game temp file %s\n",histmp);
  50. return;
  51. }
  52. fprintf(hisf," White Black Depth Nodes Score Cpu Rate\n");
  53. for (i = 0; i <= ngamemvs; i++)
  54. {
  55. if (i % 2 == 0)
  56. fprintf(hisf,"%d. ",(i/2)+1);
  57. else
  58. fprintf(hisf," ");
  59. fprintf(hisf,"%s%s",sqchar[game[i].move.from],
  60. sqchar[game[i].move.to]);
  61. if (i % 2 == 0)
  62. fprintf(hisf," ");
  63. if (i % 2 != 0)
  64. fprintf(hisf,"\t %2d %6d %6d %6.2f %.0f\n",
  65. game[i].depth,
  66. game[i].nodes,
  67. game[i].score,
  68. game[i].cpu,
  69. game[i].rate);
  70. }
  71. fclose(hisf);
  72. }
  73. list_game()
  74. {
  75. register i;
  76. char lastchar;
  77. if (ngamemvs == -1)
  78. {
  79. printf("Sorry, game not played yet.\n");
  80. return;
  81. }
  82. printf(" White Black Depth Nodes Score Cpu Rate\n");
  83. for (i = 0; i <= ngamemvs; i++)
  84. {
  85. if (i % 2 == 0)
  86. printf("%d. ",(i/2)+1);
  87. else
  88. putchar(' ');
  89. printf("%s%s",sqchar[game[i].move.from],
  90. sqchar[game[i].move.to]);
  91. if (i % 2 == 0)
  92. {
  93. putchar(' ');
  94. lastchar = ' ';
  95. }
  96. if (i % 2 != 0)
  97. {
  98. printf("\t %2d %6d %6d %6.2f %.0f\n",
  99. game[i].depth,
  100. game[i].nodes,
  101. game[i].score,
  102. game[i].cpu,
  103. game[i].rate);
  104. lastchar = '\n';
  105. }
  106. }
  107. if (lastchar != '\n') putchar('\n');
  108. }