record all adjustments, even those without alternatives
[scpubgit/DX.git] / lib / DX / SearchProcess.pm
index 10248ab..e2ec2d5 100644 (file)
@@ -6,21 +6,14 @@ use DX::Class;
 has current_search_state => (
   is => 'ro', isa => SearchState, required => 1,
   handles => [ qw(
-    current_hypothesis next_step propositions alternatives
+    current_hypothesis next_step propositions adjustments_made
   ) ],
 );
 
 sub new_for {
   my ($class, $hyp, $props) = @_;
   $class->new(
-    current_search_state => DX::SearchState->new(
-      current_hypothesis => $hyp,
-      alternatives => [],
-      next_step => DX::Step::InvokeNextPredicate->new(
-        proposition => $props->members->[0],
-      ),
-      propositions => $props,
-    ),
+    current_search_state => DX::SearchState->new_for($hyp, $props),
   );
 }
 
@@ -34,18 +27,19 @@ sub with_one_step {
 sub find_solution {
   my ($self) = @_;
   my $state = $self->current_search_state;
-  while ($state and $state->next_proposition) {
+  while ($state and (not $state->is_solution_state)) {
     $state = $state->with_one_step;
   }
   return undef unless $state;
-  trace 'search.solution.hyp' => $state->current_hypothesis;
   return $self->but(current_search_state => $state);
 }
 
 sub force_backtrack {
   my ($self) = @_;
   my $new_ss = $self->current_search_state->force_backtrack;
-  return undef unless $new_ss;
+  # XXX infinite loop without the next line and I'm unsure why we don't
+  # get a loop-ending undef from elsewhere if the backtrack failed
+  return undef unless $new_ss->next_step;
   return $self->but(current_search_state => $new_ss);
 }