Anonymous avatar Anonymous committed 69a4457

Add a check for a single-true-cell letter.

Comments (0)

Files changed (1)

abc-path/perl-quick-and-dirty/abc-path-solver.pl

 
 sub set_conclusive_verdict_for_letter
 {
-    my ($letter_ascii, $xy) = @_;
+    my ($letter, $xy) = @_;
 
     my ($l_x, $l_y) = @$xy;
 
+    xy_loop(sub {
+            my ($x, $y) = @_;
+
+            set_verdict($letter, $x, $y,
+                ((($l_x == $x) && ($l_y == $y))
+                    ? $ABCP_VERDICT_YES
+                    : $ABCP_VERDICT_NO
+                )
+            );
+        }
+    );
+    OTHER_LETTER:
+    foreach my $other_letter (0 .. $#letters)
     {
-        my $letter = get_letter_numeric($letter_ascii);
-        xy_loop(sub {
-                my ($x, $y) = @_;
-
-                set_verdict($letter, $x, $y,
-                    ((($l_x == $x) && ($l_y == $y))
-                        ? $ABCP_VERDICT_YES
-                        : $ABCP_VERDICT_NO
-                    )
-                );
-            }
-        );
-        OTHER_LETTER:
-        foreach my $other_letter (0 .. $#letters)
+        if ($other_letter == $letter)
         {
-            if ($other_letter == $letter)
-            {
-                next OTHER_LETTER;
-            }
-            set_verdict($other_letter, $l_x, $l_y, $ABCP_VERDICT_NO);
+            next OTHER_LETTER;
         }
+        set_verdict($other_letter, $l_x, $l_y, $ABCP_VERDICT_NO);
     }
 }
 
     }
     
     set_conclusive_verdict_for_letter(
-        $clue_letter,
+        get_letter_numeric($clue_letter),
         [$clue_x, $clue_y],
     );
 }
                 }
             });
 
+            if (@true_cells == 1)
+            {
+                my $xy = $true_cells[0];
+                if (get_verdict($letter, @$xy) ==
+                    $ABCP_VERDICT_MAYBE)
+                {
+                    $num_changed++;
+                    set_conclusive_verdict_for_letter($letter, $xy);
+                    print "For $letters[$letter] only ($xy->[0],$xy->[1]) is possible.\n";
+                }
+            }
+
             my @neighbourhood = (map { [(0) x $BOARD_LEN] } (0 .. $BOARD_LEN_LIM));
             
             foreach my $true (@true_cells)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.