gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] view.pike enhancement


From: Arend Bayer
Subject: Re: [gnugo-devel] view.pike enhancement
Date: Sun, 18 Apr 2004 22:17:36 +0200 (CEST)


Gunnar wrote:

> Arend wrote:
> > Gunnar, while you are resurfaced on the list, maybe you have comments
> > on this ;) I have modified view.pike to allow it to connect simultaneously
> > to several engines. Of course the intended use is to compare a patched
> > version with the stabled one when analyzing a PASS/FAIL.
> 
> When testing it I found some things had broken. This patch repairs
> those and fixes a few odd indentations.
> 
> - bugfixes in view.pike

Yes the logic there had confused me and know I understand why. The
if (has_value("1234...", testline[0..0]")) happens after
sccanf has already stripped testline from the starting id, maybe I had
moved it there by accident. How about this patch instead? Tries to strip
down complete_testcase and full_testcase a bit more aggressively. (try
viewing unconditional:25 to see the effect) It includes your patch.


Arend


Index: regression/view.pike
===================================================================
RCS file: /cvsroot/gnugo/gnugo/regression/view.pike,v
retrieving revision 1.7
diff -u -p -r1.7 view.pike
--- regression/view.pike        10 Apr 2004 14:56:31 -0000      1.7
+++ regression/view.pike        18 Apr 2004 21:16:09 -0000
@@ -160,7 +160,7 @@ class Goban
                int width = text_image->xsize();
                int height = text_image->ysize();
                image->paste(text_image * 0 + ({220, 150, 50}), x - width / 2,
-                                        y - height / 2);
+                            y - height / 2);
                image->paste_alpha_color(text_image, x - width / 2,
                                         y - height / 2);
            }
@@ -1219,21 +1219,27 @@ class Controller
     string testcase_command;
     string result;
     string expected_result;
+
+    // All lines from the test file shown at the top of the control window.
     array(string) full_testcase;
 
+    // All lines from the test file which may be needed to load the
+    // testcase correctly.
+    array(string) complete_testcase;
+
     static void create(SimpleGtp engine_, string testcase)
     {
-       if (!excerpt_testcase(testcase))
+       if (!excerpt_testcase(testcase, engine_))
        {
            werror("Failed to load testcase.\n");
            exit(1);
        }
        testcase_name = testcase;
 
-        viewers += ({RegressionViewer(engine_, testcase, full_testcase,
-                                        testcase_command,
-                                        button_pressed_on_a_board,
-                                        this_object())});
+        viewers += ({RegressionViewer(engine_, testcase, complete_testcase,
+                                     testcase_command,
+                                     button_pressed_on_a_board,
+                                     this_object())});
 
        notebook_window = GTK.Window(GTK.WindowToplevel);
        notebook = GTK.Notebook();
@@ -1306,8 +1312,7 @@ class Controller
            GTK.Label("after move influence for PASS");
        after_move_influence_button_text->set_justify(GTK.JUSTIFY_LEFT);
        after_move_influence_button =
-           GTK.RadioButton(0,
-                           initial_w_influence_dragons_known_button);
+           GTK.RadioButton(0, initial_w_influence_dragons_known_button);
        after_move_influence_button->add(after_move_influence_button_text);
        followup_influence_button_text =
            GTK.Label("followup influence for PASS");
@@ -1578,7 +1583,12 @@ class Controller
        }
     }
 
-    static int excerpt_testcase(string testcase)
+    // The engine parameter is only needed to find out the color to
+    // move when an sgf file is given. Since there can be multiple
+    // viewers we shouldn't use this engine object for anything else
+    // though. Notice also that no viewer has been set up yet at the
+    // time of this call.
+    static int excerpt_testcase(string testcase, SimpleGtp engine)
     {
        string filename;
        int number;
@@ -1597,33 +1607,45 @@ class Controller
        {
            // Only sgf file provided. Fake a testcase.
            string s = "loadsgf " + filename + " " + number;
-           string color = viewers[0]->send_command(s);
+           string color = engine->send_command(s)->text;
            testcase_command = "reg_genmove " + color;
            full_testcase = ({s, testcase_command});
+           complete_testcase = ({s, testcase_command});
            expected_result = "";
            return 1;
        }
        
        full_testcase = ({});
+       complete_testcase = ({});
        array(string) testlines = testfile / "\n";
        for (int k = 0; k < sizeof(testlines); k++)
        {
            int this_number;
            string testline = testlines[k];
-           if (sscanf(testline, "%d %s", this_number, testline) == 2
-                    && this_number == number)
-           {
-               testcase_command = testline;
-               sscanf(testlines[k + 1], "#? [%s]", expected_result);
-               full_testcase += ({testlines[k]});
-               full_testcase += ({testlines[k + 1]});
-               return 1;
-           }
-
-           if (has_value("0123456789 ", testline[0..0]))
+           if (sscanf(testline, "%d %s", this_number, testline) == 2) {
+               /* Line with id: Either it is our test command, or we
+                * completely ignore it.
+                */
+               if (this_number == number) {
+                       testcase_command = testline;
+                       sscanf(testlines[k + 1], "#? [%s]", expected_result);
+                       full_testcase += ({testlines[k]});
+                       full_testcase += ({testlines[k + 1]});
+                       return 1;
+                   }
+               }
+           else if (testline == "")
                full_testcase = ({});
-           else
+           else if (testline[0..0] >= "a" && testline[0..0] <= "z") {
+               complete_testcase += ({testline});
                full_testcase += ({testline});
+           }
+           else if (search(testline, "#? ") != 0)
+               full_testcase += ({testline});
+           if (search(testline, "loadsgf ") == 0) {
+               /* loadsgf means we can forget all previous stuff */
+               complete_testcase = ({testline});
+           }
        }
        
        return 0;




reply via email to

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