Game::DijkstraMap - a numeric grid of weights plus some related functions
use Game::DijkstraMap; my $map = Game::DijkstraMap->new; $map->map( [[ ... ]] ); my $dimap = $map->dimap; $map->update( [ 0, 1, -1 ] );
This module implements what the author of the "The Incredible Power of Dijkstra Maps" article (see below) calls Dijkstra Maps. Such maps have various uses in roguelikes or other games. This implementation may not be particularly fast but should allow quick prototyping of map-building and path-finding exercises.
The new method accepts any of the "ATTRIBUTES".
Cost for non-goal non-wall points. A large number by default. These points should be reduced by normalize_costs if all goes well.
Cost for points that are goals. Zero by default.
Cost for cells through which motion is illegal (walls, typically). -1 by default, and ignored when updating the map.
-1
A code reference called with the object and the contents of the map passed to map. This function must convert those items into suitable cost numbers for the internal Dijkstra Map. Defaults to a function that assigns bad_cost to # and min_cost to x, otherwise max_cost.
#
x
Accessor for the Dijkstra Map, presently an array reference of array references. Do not change this reference unless you know what you are doing.
This is set after map or update calls and indicates how many iterations it took the normalize_costs method to stabilize the map.
These return the object so can be chained with other calls. These methods will throw exceptions if something goes awry (especially when given known bad input).
Accepts a level map (an array reference of array references, or a 2D grid) and uses the costfn to convert the objects in that map to the internal Dijkstra Map that is held in the dimap attribute.
Mostly an internal routine called by map or update that reduces max_cost cells as appropriate relative to the connected min_cost cells.
Updates the given row and column with the given value for each array reference passed then updates the Dijkstra Map.
Please report any bugs or feature requests to bug-game-dijkstramap at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-DijkstraMap.
bug-game-dijkstramap at rt.cpan.org
Patches might best be applied towards:
https://github.com/thrig/Game-DijkstraMap
New code. In particular the update method will need a different interface or an attribute to handle two different possibilities, see the commentary in the test code. Also need to add path finding (routes) and next cell (steps along routes) methods.
The code in this module is based on the following article (as of August 2018):
http://www.roguebasin.com/index.php?title=The_Incredible_Power_of_Dijkstra_Maps
There are various other graph and pathfinding modules on CPAN that may be more suitable to the task at hand.
thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>
<jmates at cpan.org>
Copyright (C) 2018 by Jeremy Mates
This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause
To install Game::DijkstraMap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::DijkstraMap
CPAN shell
perl -MCPAN -e shell install Game::DijkstraMap
For more information on module installation, please visit the detailed CPAN module installation guide.