1.0.2 • Published 11 years ago
parse-grid-bench v1.0.2
parse-grid-bench
Parses the data files from Nathan Sturtevant's grid path finding benchmark.
Example
var fs = require('fs')
var path = require('path')
var imshow = require('ndarray-imshow')
var parseMap = require('../map')
var parseScen = require('../scenario')
//Read in data
var mapStr = fs.readFileSync('./maps/bg512/AR0011SR.map', 'utf-8')
var scenStr = fs.readFileSync('./scenarios/bg512/AR0011SR.map.scen', 'utf-8')
console.log(parseScen(scenStr))
imshow(parseMap(mapStr))Output:
[ { bucket: 61,
map: 'maps/bgmaps/AR0011SR.map',
width: 512,
height: 512,
srcX: 210,
srcY: 395,
dstX: 87,
dstY: 201,
length: 244.95 },
{ bucket: 33,
map: 'maps/bgmaps/AR0011SR.map',
width: 512,
height: 512,
srcX: 244,
srcY: 370,
dstX: 359,
dstY: 376,
length: 132.4 },
...
]Install
npm i parse-grid-benchAPI
var map = require('parse-grid-bench/map')(mapStr)
Parses a map file from a string
mapStris a string containing the map data
Returns An ndarray representing the map data. Each entry in the map file has the following meaning:
0free terrain1impassable terrain/obstacle2swamp3water
var scen = require('parse-grid-bench/scenario')(scenStr)
Parses a scenario file.
scenStris a string containing the scenario
Returns An array of scenario data. Each scenario has the following properties:
bucketA random number, ignore itmapA path to the map data for the scenario.widththe width of the map data in themapstringheightthe height of the map data in themapstringsrcXthe start X positionsrcYthe start Y positiondstXthe goal X positiondstYthe goal Y positionlengththe optimal path length, assuming diagonal motion allowed
License
(c) 2015 Mikola Lysenko. MIT License