home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / writeSGF.c < prev   
Encoding:
C/C++ Source or Header  |  1993-10-07  |  1.5 KB  |  61 lines  |  [TEXT/R*ch]

  1. #include "comment.header"
  2. /* */
  3. #include <stdio.h>
  4. extern int hcap;
  5. extern int pass;
  6. extern int MAXX, MAXY;
  7. extern int blackTerritory, whiteCaptured, whiteTerritory, blackCaptured;
  8.  
  9. #define WHITE 1
  10. #define BLACK 2
  11. extern int lastMove;
  12.  
  13. int saveSmartGoFile(const char *fileName)
  14. {
  15.   FILE *NGoFile;
  16.   int i,j;
  17.   int x,y,color;
  18.  
  19.   if ((NGoFile = fopen(fileName, "w")) == NULL) return 1;
  20.  
  21.   fprintf(NGoFile, "(\n;\nGaMe[1]\nVieW[]\n");
  22.   fprintf(NGoFile, "SiZe[%d]\nKoMi[%3.1f]\nHAndicap[%d]",
  23.         MAXX, (float)0.0, hcap);
  24.   fprintf(NGoFile,"\nComment[ A game between ");
  25.   fprintf(NGoFile,"the computer and a human player.\n\n");
  26.  
  27.   if (pass >= 2) {
  28.     i = (blackTerritory + whiteCaptured - (whiteTerritory + blackCaptured));
  29.     fprintf(NGoFile,"        Result:  %s wins by %8.1f.]\n",
  30.           (i > 0) ? "Black":"White", (float)((i > 0) ? i : -i));
  31.   } else fprintf(NGoFile, "]\n");
  32.  
  33. #ifdef hcapSaveModifications
  34.   if (hcap > 1) {
  35.       int j, x, y;
  36.       fprintf(NGoFile, "AddBlack");
  37.       for (j=0;j<handicapNumber;j++) {
  38.         x = handicapMoves[j][0];
  39.         y = handicapMoves[j][1];
  40.         fprintf(NGoFile,"[%c%c]", 'a'+x, 'a'+y); 
  41.       }
  42.       fprintf(NGoFile, "\n");
  43.   }
  44. #endif
  45.     
  46.   for (i = 0; i < lastMove; i++) {
  47.     getHistory(i, &color, &x, &y);
  48.     if (color == WHITE)      fprintf(NGoFile, ";\nWhite");
  49.     else if (color == BLACK) fprintf(NGoFile, ";\nBlack");
  50.     else continue;
  51.     if (x < 0) fprintf(NGoFile, "[tt]\n");
  52.     else fprintf(NGoFile,"[%c%c]\n",
  53.          y + 'a', x + 'a');
  54.   }
  55.  
  56.   fprintf(NGoFile,")\n\n");
  57.   fclose(NGoFile);
  58.  
  59.   return 0;
  60. }
  61.