Algorithm-Search

 view release on metacpan or  search on metacpan

lib/Algorithm/Search.pm  view on Meta::CPAN


=head1 SYNOPSIS

  use Algorithm::Search;
  my $as = new Algorithm::Search();

  $as->search({ # Example parameters here are the default parameters
   search_this => $object_to_search, #no default
   search_type => 'dfs', # dfs, bfs, cost, or rdfs
   max_steps => 20000, # number of moves to look at
   maximum_depth => 0, # longest allowable path length if > 0
   solutions_to_find => 0, # search stops when number reached, 0 finds all
   do_not_repeat_values => 0, # only traverse position with value once
   cost_cannot_increase => 0, # whether or not moves can increase cost
   initial_cost => undef, # for cost based search
   return_search_trace => 0, # does $as->search_trace return array ref of moves
  });
  if (!$as->completed) {
    $as->continue_search({additional_steps => 300});
  }

t/p54.t  view on Meta::CPAN

        }
      }
    }
    $self->{final_count} -= 1; #start 

  }

  sub move {
    my $self = shift;
    my $direction = shift;
    my $length = ++$self->{count} % 3;
    if ($length == 0) {$length = 3};
    my $row = $self->{position}->[0];
    my $column = $self->{position}->[1];

    if ($direction eq 'U' || $direction eq 'UL' || $direction eq 'UR') {
      if ($row - $length < 0) {return}
      else {$row -= $length}
    }
    if ($direction eq 'D' || $direction eq 'DL' || $direction eq 'DR') {
      if ($row + $length > $self->{max_row}) {return}
      else {$row += $length}
    }
    if ($direction eq 'L' || $direction eq 'DL' || $direction eq 'UL') {
      if ($column - $length < 0) {return}
      else {$column -= $length}
    }
    if ($direction eq 'R' || $direction eq 'DR' || $direction eq 'UR') {
      if ($column + $length > $self->{max_column}) {return}
      else {$column += $length}
    }

    if ($self->{value}->[$row]->[$column]) {
      return;
    }

    if (($self->{start}->[0]== $row) && ($self->{start}->[1] == $column)) {
      return;
    }

t/ws.t  view on Meta::CPAN

  package main;
  my @solutions;
  my $sol_count;
  use Algorithm::Search;

  my $board =
"TEA
SEA
ART";
  my @rows = split /\n/,$board;
  my $columns = length($rows[0])-1;

  my %words_found;
  my $puzzle_search = new Algorithm::Search();
  for my $i (0..$#rows) {
    for my $j (0..$columns) {
      my $puzzle = new words;
      $puzzle->set_position($i,$j,$board);
      $puzzle_search->search({search_this=>$puzzle,
       max_steps=>3000,
       solutions_to_find=>0,



( run in 0.644 second using v1.01-cache-2.11-cpan-65fba6d93b7 )