bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnubg] File format sgf


From: Øystein Johansen
Subject: Re: [Bug-gnubg] File format sgf
Date: Sun, 05 Jan 2003 14:38:16 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2.1) Gecko/20021130

address@hidden wrote:

Hi folks,

just back from a snowy holiday in denmark. There I had time to check a
few computer go (the japanese game) programs. Go is using the same
ending *.sgf for saving games. Maybe we should think about differnet
endings?

Nice to see you back again!

The Smart Game Format (SGF), is designed to store game records of board games (turn based) for two players. It is therefore the same file format and a good parser algorithm should be able to handle the different games in the file format.
Check the definitions here: http://www.red-bean.com/sgf/

One problem that will arise is that you can't assign the file extension .sgf to a backgammon program, since it might as well be a Go file. This can be solved by writing a sgf launcher program, and then assign the sgf extension to this launcher program. Hey! I've just made one in twenty minutes. It's not tested much and some lines must be added by the end user. I basically reads the sgf file and checks if it's a Backgammon of Go file, then it searches for the SGF_BACKGAMMON_PROGRAM environment variable (or SGF_GO_PROGRAM), and launches the program with the file as an agument.

-Øystein



#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv[])
{

  int nGameType;
  char *szExe, szCommand[256];
  FILE *pf;

  if (argc != 2)
    return 0;                   /* Fail silently */

  if (!(pf = fopen (argv[1], "r")))
    {
      fprintf (stderr, "Can't open file %s\n", argv[1]);
      return -1;
    }

  if ((fscanf (pf, "(;FF[4]GM[%d]", &nGameType)) != 1)
    {
      fprintf (stderr, "Can't find SGF identifier in file %s\n", argv[1]);
      fclose (pf);
      return -1;
    }

  switch (nGameType)
    {
    case 1:
      /* GO */
      szExe = getenv ("SGF_GO_PROGRAM");
      if (!szExe)
        {
          fprintf (stderr, "SGF Program for Go, not specified\n");
          return -1;
        }

      /* Now do whatever it takes to open the file with the Go program */
      
      return 0;
      break;
    case 6:
      /* Backgammon */
      szExe = getenv ("SGF_BACKGAMMON_PROGRAM");
      if (!szExe)
        {
          fprintf (stderr, "SGF Program for Backgammon not specified\n");
          return -1;
        }
      
      /* Now do whatever it takes to open the file with the Go program */

//        chdir (dirname (szExe));
//        sprintf (szCommand, "%s %s", filename (szExe), argv[1]);
//        system(szCommand);
    default:
      return 0;
    }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]