gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] arend_3_4.3: dragon_data reported by report_dragon (Re: dr


From: Arend Bayer
Subject: [gnugo-devel] arend_3_4.3: dragon_data reported by report_dragon (Re: dragon_data_3.3.1)
Date: Sat, 15 Jun 2002 21:11:23 +0200 (CEST)

On Sat, 15 Jun 2002 address@hidden wrote:

> I have no objection to unifying them so long as the dragon data
> can be conveniently queried:
>
> (1) from gdb,
> (2) from the command line,
> (3) from the gtp.
>
> Dan

This is what this patch does (assuming that the gdb queries use
ascii_report_dragon, there is no change in any interface, while the
output is minimally changed for all 3 cases).

Arend

 - remove report_dragon/gtp_dragon_data/decide_dragon_data code triplication

Index: engine/dragon.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.65
diff -u -r1.65 dragon.c
--- engine/dragon.c     31 May 2002 15:09:41 -0000      1.65
+++ engine/dragon.c     15 Jun 2002 19:06:03 -0000
@@ -1721,15 +1721,13 @@
 {
   int m, n;
   string_to_location(board_size, string, &m, &n);
-  report_dragon(m, n);
+  report_dragon(stderr, POS(m, n));
 }


 void
-report_dragon(int m, int n)
+report_dragon(FILE *outfile, int pos)
 {
-  int pos = POS(m, n);
-  int i, j;
   int ii;
   int k;
   struct dragon_data *d = &(dragon[pos]);
@@ -1745,72 +1743,49 @@
     return;
   }

-  gprintf("*** dragon at %1m:\n", pos);
-  gprintf("color: %s; origin: %1m; size: %d; effective size: %f\n",
-         (d->color == WHITE) ? "WHITE" : "BLACK",
-         d->origin, d->size, d->effective_size);
-
-  gprintf("strings:");
-  for (i = 0; i < board_size; i++)
-    for (j = 0; j < board_size; j++) {
-      ii = POS(i, j);
-
-      if (worm[ii].origin == ii
-         && is_same_dragon(ii, pos))
-       gprintf(" %1m", ii);
-    }
-
-  gprintf("\nhalf eyes: %d, ", d2->heyes);
-  if (d2->heye != NO_MOVE)
-    gprintf("half eye: %1m, ", d2->heye);
-  else
-    gprintf("half eye: NONE,");
-
-  gprintf(" genus %d, escape_route %d,", d2->genus, d2->escape_route);
-  if (d2->lunch != NO_MOVE)
-    gprintf(" lunch at %1m\n", d2->lunch);
-  else
-    gprintf(" no lunch\n");
-
-  gprintf("dragon status %s, owl status %s, matcher status %s, owl threat 
status %s\n",
-         status_to_string(d->status),
-         status_to_string(d->owl_status),
-         status_to_string(d->matcher_status),
-         status_to_string(d->owl_threat_status));
-
-  if (d->owl_attack_point != NO_MOVE)
-    gprintf("owl attack point %1m, code %d, ",
-           d->owl_attack_point, d->owl_attack_code);
-  else
-    gprintf("no owl attack point, ");
-
-  if (d->owl_second_attack_point != NO_MOVE)
-    gprintf("second owl attack point %1m\n", d->owl_second_attack_point);
-  else
-    gprintf("no second owl attack point\n");
-
-  if (d->owl_defense_point != NO_MOVE)
-    gprintf("owl defense point %1m, code %d, ",
-           d->owl_defense_point, d->owl_defense_code);
-  else
-    gprintf("no owl defense point, ");
-
-  if (d->owl_second_defense_point != NO_MOVE)
-    gprintf("second owl defense point %1m\n", d->owl_second_defense_point);
-  else
-    gprintf("no second owl defense point\n");
-
-  if (d2->semeai)
-    gprintf("This dragon is involved in a semeai. Margin of safety %d\n",
-           d2->semeai_margin_of_safety);
-  else
-    gprintf("This dragon is not involved in a semeai.\n");
-
-  gprintf("neighbor dragons: ");
-  for (k = 0; k < d2->neighbors; k++)
-    gprintf("%1m ", dragon2[d2->adjacent[k]].origin);
-  gprintf("\nhostile neighbors: %d\n", d2->hostile_neighbors);
-  gprintf("\nmoyo: %d; safety: %d\n", d2->moyo, d2->safety);
+  gfprintf(outfile,"color                   %s\n", 
color_to_string(dragon[pos].color));
+  gfprintf(outfile,"origin                  %1m\n", dragon[pos].origin);
+  gfprintf(outfile,"size                    %d\n", dragon[pos].size);
+  gfprintf(outfile,"effective_size          %f\n", dragon[pos].effective_size);
+  gfprintf(outfile,"heyes                   %d\n", DRAGON2(pos).heyes);
+  gfprintf(outfile,"heye                    %1m\n", DRAGON2(pos).heye);
+  gfprintf(outfile,"genus                   %d\n", DRAGON2(pos).genus);
+  gfprintf(outfile,"escape_route            %d\n", DRAGON2(pos).escape_route);
+  gfprintf(outfile,"lunch                   %1m\n", DRAGON2(pos).lunch);
+  gfprintf(outfile,"status                  %s\n",
+            status_to_string(dragon[pos].status));
+  gfprintf(outfile,"owl_status              %s\n",
+            status_to_string(dragon[pos].owl_status));
+  gfprintf(outfile,"matcher_status          %s\n",
+            status_to_string(dragon[pos].matcher_status));
+  gfprintf(outfile,"owl_threat_status       %s\n",
+            status_to_string(dragon[pos].owl_threat_status));
+  gfprintf(outfile,"owl_attack              %1m\n", 
dragon[pos].owl_attack_point);
+  gfprintf(outfile,"owl_attack_certain      %s\n",
+            (dragon[pos].owl_attack_certain) ? "YES" : "NO");
+  gfprintf(outfile,"owl_2nd_attack          %1m\n", 
dragon[pos].owl_second_attack_point);
+  gfprintf(outfile,"owl_defend              %1m\n", 
dragon[pos].owl_defense_point);
+  gfprintf(outfile,"owl_defense_certain     %s\n",
+            (dragon[pos].owl_defense_certain) ? "YES" : "NO");
+  gfprintf(outfile,"owl_2nd_defend          %1m\n", 
dragon[pos].owl_second_defense_point);
+  gfprintf(outfile,"semeai                  %d\n", DRAGON2(pos).semeai);
+  gfprintf(outfile,"semeai_margin_of_safety %d\n",
+         DRAGON2(pos).semeai_margin_of_safety);
+  gfprintf(outfile,"neighbors               ");
+  for (k = 0; k < DRAGON2(pos).neighbors; k++)
+    gfprintf(outfile,"%1m ", DRAGON(DRAGON2(pos).adjacent[k]).origin);
+  gfprintf(outfile,"\nhostile neighbors       %d\n", d2->hostile_neighbors);
+  gfprintf(outfile,"moyo                    %d\n", DRAGON2(pos).moyo);
+  gfprintf(outfile,"safety                  %s\n",
+         safety_to_string(DRAGON2(pos).safety));
+  gfprintf(outfile,"strings                 ");
+
+  for (ii = BOARDMIN; ii < BOARDMAX; ii++)
+    if (ON_BOARD(ii)
+       && worm[ii].origin == ii
+       && is_same_dragon(ii, pos))
+       gfprintf(outfile,"%1m ", ii);
+  gfprintf(outfile,"\n");
 }


Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.103
diff -u -r1.103 liberty.h
--- engine/liberty.h    3 Jun 2002 15:00:59 -0000       1.103
+++ engine/liberty.h    15 Jun 2002 19:06:07 -0000
@@ -191,7 +191,7 @@
 void dump_stack(void);
 void report_worm(int m, int n);
 void ascii_report_worm(char *string);
-void report_dragon(int m, int n);
+void report_dragon(FILE *outfile, int pos);
 void ascii_report_dragon(char *string);
 struct dragon_data2 * dragon2_func(int pos);

Index: engine/sgfdecide.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/sgfdecide.c,v
retrieving revision 1.33
diff -u -r1.33 sgfdecide.c
--- engine/sgfdecide.c  22 May 2002 19:22:25 -0000      1.33
+++ engine/sgfdecide.c  15 Jun 2002 19:06:09 -0000
@@ -290,56 +290,15 @@
 void
 decide_dragon_data(int pos)
 {
-  int w, k;
-
   if (board[pos] == EMPTY) {
     fprintf(stderr, "gnugo: --decide-dragon-data called on an empty vertex\n");
     return ;
   }
   reset_engine();
   silent_examine_position(board[pos], EXAMINE_DRAGONS);
-  gprintf("color                   %s\n", color_to_string(dragon[pos].color));
-  gprintf("origin                  %1m\n", dragon[pos].origin);
-  gprintf("size                    %d\n", dragon[pos].size);
-  gprintf("effective_size          %f\n", dragon[pos].effective_size);
-  gprintf("heyes                   %d\n", DRAGON2(pos).heyes);
-  gprintf("heye                    %1m\n", DRAGON2(pos).heye);
-  gprintf("genus                   %d\n", DRAGON2(pos).genus);
-  gprintf("escape_route            %d\n", DRAGON2(pos).escape_route);
-  gprintf("lunch                   %1m\n", DRAGON2(pos).lunch);
-  gprintf("status                  %s\n",
-            status_to_string(dragon[pos].status));
-  gprintf("owl_status              %s\n",
-            status_to_string(dragon[pos].owl_status));
-  gprintf("matcher_status          %s\n",
-            status_to_string(dragon[pos].matcher_status));
-  gprintf("owl_threat_status       %s\n",
-            status_to_string(dragon[pos].owl_threat_status));
-  gprintf("owl_attack              %1m\n", dragon[pos].owl_attack_point);
-  gprintf("owl_attack_certain:     %s\n",
-            (dragon[pos].owl_attack_certain) ? "YES" : "NO");
-  gprintf("owl_2nd_attack          %1m\n", 
dragon[pos].owl_second_attack_point);
-  gprintf("owl_defend              %1m\n", dragon[pos].owl_defense_point);
-  gprintf("owl_defense_certain:     %s\n",
-            (dragon[pos].owl_defense_certain) ? "YES" : "NO");
-  gprintf("owl_2nd_defend          %1m\n", 
dragon[pos].owl_second_defense_point);
-  gprintf("semeai                  %d\n", DRAGON2(pos).semeai);
-  gprintf("semeai_margin_of_safety %d\n",
-         DRAGON2(pos).semeai_margin_of_safety);
-  gprintf("neighbors:              ");
-  for (k = 0; k < DRAGON2(pos).neighbors; k++)
-    gprintf("%1m ", DRAGON(DRAGON2(pos).adjacent[k]).origin);
-  gprintf("\n");
-  gprintf("moyo:                   %d\n", DRAGON2(pos).moyo);
-  gprintf("safety:                 %s\n",
-         safety_to_string(DRAGON2(pos).safety));
-  gprintf("strings: ");
-  for (w = BOARDMIN; w < BOARDMAX; w++)
-    if (ON_BOARD(w)
-       && worm[w].origin == w
-       && is_same_dragon(w, pos))
-       gprintf("%1m ", w);
-  gprintf("\n");
+
+  gprintf("Dragon at %1m:\n", pos);
+  report_dragon(stderr, pos);
 }


Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.76
diff -u -r1.76 play_gtp.c
--- interface/play_gtp.c        22 May 2002 19:22:25 -0000      1.76
+++ interface/play_gtp.c        15 Jun 2002 19:06:20 -0000
@@ -2637,72 +2637,9 @@
            || (i == -1
                && BOARD(m, n) != EMPTY
                && dragon[POS(m, n)].origin == POS(m, n))) {
-         int k, ti, tj;
-         struct dragon_data *d = &dragon[POS(m, n)];
-         struct dragon_data2 *d2 = &(dragon2[d->id]);
          gtp_print_vertex(m, n);
          gtp_printf(":\n");
-         gtp_printf("color                   %s\n",
-                    color_to_string(d->color));
-         gtp_mprintf("origin                  %m\n",
-                     I(d->origin), J(d->origin));
-         gtp_printf("size                    %d\n",   d->size);
-         gtp_printf("effective_size          %.2f\n", d->effective_size);
-         gtp_printf("heyes                   %d\n",   d2->heyes);
-         gtp_mprintf("heye                    %m\n",
-                     I(d2->heye), J(d2->heye));
-         gtp_printf("genus                   %d\n",   d2->genus);
-         gtp_printf("escape_route            %d\n",   d2->escape_route);
-         /* We would like to use the %1m format used in gprintf
-          * but this is not implemented in gtp_mprintf. Moreover adding this
-          * format would entail including liberty.h in gtp.c, which we
-          * don't want to do in order to maintain independence of the
-          * GNU Go internals. Therefore we use the I and J macros here.
-          */
-         gtp_mprintf("lunch                   %m\n",
-                     I(d2->lunch), J(d2->lunch));
-         gtp_printf("status                  %s\n",
-                    status_to_string(d->status));
-         gtp_printf("owl_status              %s\n",
-                    status_to_string(d->owl_status));
-         gtp_printf("matcher_status          %s\n",
-                    status_to_string(d->matcher_status));
-         gtp_printf("owl_threat_status       %s\n",
-                    status_to_string(d->owl_threat_status));
-         gtp_mprintf("owl_attack              %m\n",
-                     I(d->owl_attack_point), J(d->owl_attack_point));
-         gtp_printf("owl_attack_certain:     %s\n",
-                    (d->owl_attack_certain) ? "YES" : "NO");
-         gtp_mprintf("owl_2nd_attack          %m\n",
-                     I(d->owl_second_attack_point),
-                     J(d->owl_second_attack_point));
-         gtp_mprintf("owl_defend              %m\n",
-                     I(d->owl_defense_point), J(d->owl_defense_point));
-         gtp_printf("owl_defense_certain:     %s\n",
-                    (d->owl_defense_certain) ? "YES" : "NO");
-         gtp_mprintf("owl_2nd_defend          %m\n",
-                     I(d->owl_second_defense_point),
-                     J(d->owl_second_defense_point));
-         gtp_printf("semeai                  %d\n",
-                    d2->semeai);
-         gtp_printf("semeai_margin_of_safety %d\n",
-                    d2->semeai_margin_of_safety);
-         gtp_printf("neighbors:              ");
-         for (k = 0; k < DRAGON2(POS(m, n)).neighbors; k++)
-           gtp_mprintf("%m ",
-                       I(DRAGON(DRAGON2(POS(m, n)).adjacent[k]).origin),
-                       J(DRAGON(DRAGON2(POS(m, n)).adjacent[k]).origin));
-         gtp_printf("\n");
-         gtp_printf("moyo:                   %d\n", DRAGON2(POS(m, n)).moyo);
-         gtp_printf("safety:                 %s\n",
-                    safety_to_string(DRAGON2(POS(m, n)).safety));
-         gtp_printf("strings: ");
-         for (ti = 0; ti < board_size; ti++)
-           for (tj = 0; tj < board_size; tj++)
-             if (worm[POS(ti, tj)].origin == POS(ti, tj)
-                 && dragon[POS(ti, tj)].origin == dragon[POS(m, n)].origin)
-               gtp_mprintf("%m ", ti, tj);
-         gtp_printf("\n");
+         report_dragon(stdout, POS(m, n));
        }
   }
   gtp_printf("\n");





reply via email to

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