Commits

Anonymous committed 54d7c7c

Now checking for solution uniqueness.

Comments (0)

Files changed (1)

abc-path/generator/generate-abs-path.pl

 
 use base 'Games::ABC_Path::Solver::Base';
 
+use Games::ABC_Path::Solver::Board '0.1.0';
+
 use Data::Dumper;
 
 sub _init
             if (!@clues)
             {
                 # Yay! We found a configuration.
-                return
+                my $riddle =
                 {
                     solution => $layout,
                     clues => [map { [ map { vec($layout, $_, 8) } @{$_->{cells}}] } @{$last_state->{clues}}],
                     A_pos => [$self->_to_xy($A_pos)],
                 };
+                
+                my $riddle_string = $self->_get_riddle_only_as_string($riddle);
+
+                my $solver = 
+                    Games::ABC_Path::Solver::Board->input_from_v1_string(
+                        $riddle_string
+                    );
+                
+                $solver->solve();
+
+                if (@{$solver->get_successes_text_tables()} != 1)
+                {
+                    # The solution is ambiguous
+                    pop(@dfs_stack);
+                    next DFS;
+                }
+                else
+                {
+                    return $riddle;
+                }
             }
             # Not enough for the clues there.
             if ($clues[0][1]->{num_remaining} < 2)
 
     my $layout_string = $self->get_layout_as_string($riddle->{solution});
     
+    my $riddle_string = $self->_get_riddle_only_as_string($riddle);
+
+    return <<"EOF";
+ABC Path Solver Layout Version 1:
+$riddle_string
+
+Solution:
+$layout_string
+EOF
+}
+
+sub _get_riddle_only_as_string
+{
+    my ($self,$riddle) = @_;
+
     my $s = ((' ' x 7)."\n")x7;
 
     substr($s, ($riddle->{A_pos}->[$Y]+1) * 8 + $riddle->{A_pos}->[$X]+1, 1) = 'A';
         }
     }
 
-    return <<"EOF";
-ABC Path Solver Layout Version 1:
-$s
+    return $s;
+}
 
-Solution:
-$layout_string
-EOF
-}
 
 package main;
 
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.