gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] reorientation for gtp.


From: Teun Burgers
Subject: [gnugo-devel] reorientation for gtp.
Date: Tue, 09 Oct 2001 23:00:36 +0200

This patch implements most of what is
needed to reorient in gtp commands.

The only thing missing now is a gtp command
to set the orientation.

- make gtp_loadsgf reorient gamerecords
- make gtp_printvertices orient output
  points back

Teun
Index: engine/gnugo.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.12
diff -u -r1.12 gnugo.h
--- engine/gnugo.h      2001/10/07 20:00:05     1.12
+++ engine/gnugo.h      2001/10/09 20:55:35
@@ -183,6 +183,8 @@
 void gameinfo_print(Gameinfo *ginfo);
 void gameinfo_load_sgfheader(Gameinfo *gameinfo, SGFNode *head);
 void gameinfo_play_move(Gameinfo *ginfo, int i, int j, int color);
+int  gameinfo_play_sgftree_rot(Gameinfo *gameinfo, SGFNode *head,
+                          const char *untilstr, int orientation);
 int  gameinfo_play_sgftree(Gameinfo *gameinfo, SGFNode *head,
                           const char *untilstr);
 
Index: engine/interface.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/interface.c,v
retrieving revision 1.8
diff -u -r1.8 interface.c
--- engine/interface.c  2001/09/24 14:05:44     1.8
+++ engine/interface.c  2001/10/09 20:55:39
@@ -32,6 +32,7 @@
 #include "liberty.h"
 #include "clock.h"
 
+#include <gg_utils.h>
 
 /*
  * Initialize the gnugo engine. This needs to be called 
@@ -537,7 +538,8 @@
  */
 
 int
-gameinfo_play_sgftree(Gameinfo *gameinfo, SGFNode *head, const char *untilstr)
+gameinfo_play_sgftree_rot(Gameinfo *gameinfo, SGFNode *head,
+                         const char *untilstr, int orientation)
 {
   int    bs, handicap;
   float  komi;
@@ -605,6 +607,7 @@
         */
        last_moves[0] = 0;
        last_moves[1] = 0;
+       rotate(i, j, &i, &j, gameinfo->position.boardsize, orientation);
        gnugo_add_stone(&gameinfo->position, i, j, BLACK);
        sgffile_put_stone(i, j, BLACK);
        addstone = 1;
@@ -614,6 +617,7 @@
        get_moveXY(prop, &i, &j, gameinfo->position.boardsize);
        last_moves[0] = 0;
        last_moves[1] = 0;
+       rotate(i, j, &i, &j, gameinfo->position.boardsize, orientation);
        gnugo_add_stone(&gameinfo->position, i, j, WHITE);
        sgffile_put_stone(i, j, WHITE);
        addstone = 1;
@@ -656,6 +660,7 @@
          if (i == untilm && j == untiln)
            return next;
 
+       rotate(i, j, &i, &j, gameinfo->position.boardsize, orientation);
        gnugo_play_move(&gameinfo->position, i, j, next);
        sgffile_move_made(i, j, next, 0);
        next = OTHER_COLOR(next);
@@ -671,6 +676,7 @@
         * the ko.
         */
        get_moveXY(prop, &i, &j, gameinfo->position.boardsize);
+       rotate(i, j, &i, &j, gameinfo->position.boardsize, orientation);
        {
          int move_color;
 
@@ -690,6 +696,12 @@
 
   gameinfo->to_move = next;
   return next;
+}
+
+int
+gameinfo_play_sgftree(Gameinfo *gameinfo, SGFNode *head, const char *untilstr)
+{
+  return gameinfo_play_sgftree_rot(gameinfo, head, untilstr, 0);
 }
 
 
Index: interface/gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gtp.c,v
retrieving revision 1.5
diff -u -r1.5 gtp.c
--- interface/gtp.c     2001/09/06 21:39:52     1.5
+++ interface/gtp.c     2001/10/09 20:55:46
@@ -41,6 +41,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <assert.h>
+#include <gg_utils.h>
 
 #include "gtp.h"
 
@@ -57,6 +58,7 @@
  * unnecessarily inconvenient.
  */
 static int gtp_boardsize = -1;
+static int gtp_orientation = 0;
 
 /* Read filehandle gtp_input linewise and interpret as GTP commands. */
 void
@@ -109,7 +111,6 @@
   }
 }
 
-
 /* Set the board size used in coordinate conversions. */
 void
 gtp_internal_set_boardsize(int size)
@@ -117,6 +118,20 @@
   gtp_boardsize = size;
 }
 
+/* Set the orientation used in coordinate conversions. */
+void
+gtp_internal_set_orientation(int orient)
+{
+  gtp_orientation = orient;
+}
+
+/* Set the orientation used in coordinate conversions. */
+int
+gtp_internal_get_orientation(void)
+{
+  return gtp_orientation;
+}
+
 /*
  * This function works like printf, except that it only understands
  * very few of the standard formats, to be precise %c, %d, %f, %s.
@@ -325,6 +340,7 @@
   if (*i < 0 || *i >= gtp_boardsize || *j < 0 || *j >= gtp_boardsize)
     return 0;
 
+  rotate(*i, *j, i, j, gtp_boardsize, gtp_orientation);
   return n;
 }
 
@@ -381,6 +397,7 @@
 gtp_print_vertices(int n, int movei[], int movej[])
 {
   int k;
+  int ri, rj;
   
   assert(gtp_boardsize > 0);
   
@@ -393,9 +410,10 @@
     else if (movei[k] < 0 || movei[k] >= gtp_boardsize
             || movej[k] < 0 || movej[k] >= gtp_boardsize)
       gtp_printf("??");
-    else
-      gtp_printf("%c%d", 'A' + movej[k] + (movej[k] >= 8),
-                gtp_boardsize - movei[k]);
+    else {
+      inv_rotate(movei[k], movej[k], &ri, &rj, gtp_boardsize, gtp_orientation);
+      gtp_printf("%c%d", 'A' + rj + (rj >= 8), gtp_boardsize - ri);
+    }
   }
 }
 
Index: interface/gtp.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gtp.h,v
retrieving revision 1.5
diff -u -r1.5 gtp.h
--- interface/gtp.h     2001/09/06 21:39:52     1.5
+++ interface/gtp.h     2001/10/09 20:55:48
@@ -62,6 +62,8 @@
 
 void gtp_main_loop(struct gtp_command commands[], FILE *gtp_input);
 void gtp_internal_set_boardsize(int size);
+void gtp_internal_set_orientation(int orient);
+int gtp_internal_get_orientation(void);
 void gtp_mprintf(const char *format, ...);
 void gtp_printf(const char *format, ...);
 void gtp_printid(int id, int status);
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.21
diff -u -r1.21 play_gtp.c
--- interface/play_gtp.c        2001/10/06 20:00:51     1.21
+++ interface/play_gtp.c        2001/10/09 20:55:56
@@ -468,7 +468,7 @@
   char untilstring[GTP_BUFSIZE];
   SGFNode *sgf;
   Gameinfo gameinfo;
-  int nread;
+  int nread, orient;
   
   nread = sscanf(s, "%s %s", filename, untilstring);
   if (nread == 0)
@@ -480,10 +480,12 @@
   gameinfo_clear(&gameinfo, 19, 5.5); /* Probably unnecessary. */
   gameinfo_load_sgfheader(&gameinfo, sgf);
 
+  orient = gtp_internal_get_orientation();
   if (nread == 1)
-    color_to_move = gameinfo_play_sgftree(&gameinfo, sgf, NULL);
+    color_to_move = gameinfo_play_sgftree_rot(&gameinfo, sgf, NULL, orient);
   else
-    color_to_move = gameinfo_play_sgftree(&gameinfo, sgf, untilstring);
+    color_to_move = gameinfo_play_sgftree_rot(&gameinfo, sgf, untilstring,
+                                              orient);
 
   gnugo_force_to_globals(&gameinfo.position);
   movenum = gameinfo.move_number;
Index: utils/gg_utils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/utils/gg_utils.c,v
retrieving revision 1.7
diff -u -r1.7 gg_utils.c
--- utils/gg_utils.c    2001/10/05 20:03:59     1.7
+++ utils/gg_utils.c    2001/10/09 20:56:06
@@ -236,10 +236,16 @@
 /* Reorientation of point (i,j) into (*ri, *rj) */
 void rotate(int i, int j, int *ri, int *rj, int bs, int rot) {
   assert (bs > 0);
-  assert (i >= 0 && i < bs);
-  assert (j >= 0 && j < bs);
   assert (ri != NULL && rj != NULL);
   assert (rot >= 0 && rot < 8);
+  /* PASS case */
+  if (i == -1 && j == -1) {
+    *ri = i;
+    *rj = j;
+    return;
+  }
+  assert (i >= 0 && i < bs);
+  assert (j >= 0 && j < bs);
 
   if (rot == 0) {
     /* identity map */

reply via email to

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