# MouseRace/DFS.pm - the default mouse solver routine - using depth first search package MouseRace::DFS; sub solve { my ( $self, $current, $choices ) = @_; $self->{visited}->{$current} = 1; my @options = grep { !$self->{visited}->{ $choices->{absolute}->{$_} } } keys %{ $choices->{absolute} }; if (@options) { push @{ $self->{path} }, $current; $choice = $options[ rand @options ]; } else { my $back = pop @{ $self->{path} }; $choice = $choices->{backtrack}->{$back}; } return $choice; } 1;