问题 7
Uncaught TypeError: Cannot read properties of undefined (reading '7') at r.getNodeAt(pathfinding-browser.min.js:1:4349) at r.findPath(pathfinding-browser.min.js:1:7595) at js.js:37:19 have such problem How can I decide it? Leave a code: const lab = [ [ "1", "1", "1", "1", "1", "1", "1", "1", "1"], [ "1", "1", "1", "1", "0", "1", "1", "1", "1"], [ "1", "1", "0", "0", "0", "1", "1", "1", "1"], [ "1", "1", "0", "1", "0", "1", "1", "1", "1"], [ "1", "1", "1", "0", "0", "0", "0", "0", "1"], [ "1", "1", "1", "1", "0", "1", "1", "1", "1"], [ "1", "1", "1", "1", "0", "1", "1", "0", "1"], [ "1", "1", "0", "0", "0", "0", "0", "0", "1"], [ "1", "1", "1", "1", "1", "1", "0", "1", "1"] ];
// 确定入口和出口的坐标 const startx = 5; const starty = 2; const exitx = 7 const exity = 9; var width = 9; var height = 9;
// 创建网格 var grid = new PF.Grid(width, height);
// 设置可行的格子 for (var i = 0; i < lab.length; i++) { for (var j = 0; j < lab[i].length; j++) { if (lab[i][j] == "1") { grid.setWalkableAt(j, i, false); } else { grid.setWalkableAt(j, i, true); }; } } console.log(grid);
// 创建A*找路器 var finder = new PF.AStarFinder();
// 找路 var path = finder.findPath(startx, starty, exitx, exity, grid);
// 显示路径 document.getElementById("decider").innerHTML = path;
内容来源: qiao/PathFinding.js