1 Star 0 Fork 0

Metoor / astar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test.js 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
caiufen 提交于 2017-08-02 14:17 . 优化
const wall = 1;
const roud = 0;
const start = 2;
const end = 3;
const line = 4;
function disPlayMap(map) {
console.log("\n");
for (let i = 0; i < map.length; i++) {
let str = " ";
for (let j = 0; j < map[0].length; j++) {
if (map[i][j] == roud) {
str += " * "; //可行区域
} else if (map[i][j] == wall) {
str += " | "; //墙
} else if (map[i][j] == start) {
str += " S "; //起点
} else if (map[i][j] == end) {
str += " E "; //终点
} else if (map[i][j] == line) {
str += " X "; //路径
}
}
console.log(str, "\n");
}
}
function generateMap(path) {
for (let i = 0; i < path.length; i++) {
if(i == 0 || i == path.length -1){
let temp = path[i];
mv[temp.row][temp.col] = i==0?end:start;
}else{
let temp = path[i];
mv[temp.row][temp.col] = line;
}
}
}
//测试
let mv = require("./map");
const astar = require("./astar");
astar.initMap(mv);
let t1 = new Date().getTime();
let t2 = t1;
t1 = process.uptime()*1000;
let path = astar.search(6, 4, 6, 6);
t2 = process.uptime()*1000;
console.log(" search finished,cost time:", t2-t1,"ms");
generateMap(path);
disPlayMap(mv);
NodeJS
1
https://gitee.com/metoor/astar.git
git@gitee.com:metoor/astar.git
metoor
astar
astar
master

搜索帮助