AI-Pathfinding-AStar-Rectangle

 view release on metacpan or  search on metacpan

examples/snake_labirint.pl  view on Meta::CPAN

    $map[10][$_] = 0 for 10 .. WIDTH_Y - 10;
    $map[$_][WIDTH_Y - 10] = 0 for 10 .. WIDTH_X - 15;
    $map[WIDTH_X - 15][$_] = 0 for 15 .. WIDTH_Y - 10;
    $map[$_][15] = 0 for 15 .. WIDTH_X - 15;
}

# copy map to map object
$m->foreach_xy_set( sub { $map[$a][$b] });

my ($path) = $m->astar(@to, @from);
sub swap(\@\@){
    @_[0,1] = @_[1,0];;
}
#swap(@to, @from);

$m->draw_path(@to, $path);

lib/AI/Pathfinding/AStar/Rectangle.pm  view on Meta::CPAN

    local ($a, $b );
    local $_;
    for $a ( $self->start_x .. $self->last_x ){
	for $b ( $self->start_y .. $self->last_y ){
	    $_ = $self->get_passability( $a, $b );
	    $self->set_passability( $a, $b, (scalar &$sub()) );
	};
    };

}
sub create_map($){
    unshift @_, __PACKAGE__;
    goto &new;
}

1 for ($a, $b); #suppress warnings

sub set_passability_string{
    my $self = shift;
    my $passability = shift;
    die "Bad passabilitity param for set_passability_string" unless $self->width * $self->height == length( $passability );



( run in 0.777 second using v1.01-cache-2.11-cpan-3b35f9de6a3 )