AI-Pathfinding-AStar
view release on metacpan or search on metacpan
lib/AI/Pathfinding/AStar/AStarNode.pm view on Meta::CPAN
my $self = {};
$self->{id} = $id;
$self->{g} = $g;
$self->{h} = $h;
$self->{f} = $g+$h;
$self->{parent} = undef;
$self->{cost} = 0;
$self->{inopen} = 0;
$self->{heap} = undef;
bless ($self, $class);
return $self;
}
sub heap {
my ($self, $val) = @_;
$self->{heap} = $val if (defined $val);
return $self->{heap};
}
sub cmp {
t/01_AI-Pathfinding-AStar.t view on Meta::CPAN
#Where . represents open squares and | represents walls. The @ represents our
#starting square and the * the target square. This module assumes that
#orthogonal moves cost 10 points and diagonal moves cost 140. The heuristic
#used is Manhattan, which simply counts the orthogonal distance between any 2
#squares whilst disregarding any barriers.
sub new
{
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = bless {}, $class;
$self->{map} = {};
for(my $x=1; $x<=7; $x++)
{
for(my $y=1; $y<=5; $y++)
{$self->{map}->{$x.'.'.$y} = 1;}
}
$self->{map}->{'4.2'} = 0;
$self->{map}->{'4.3'} = 0;
$self->{map}->{'4.4'} = 0;
( run in 0.338 second using v1.01-cache-2.11-cpan-de7293f3b23 )