我有这样的x,y坐标板:

这块板可达100×100。
在myPosition是黄金的地方,destinations是绿色的,是红色的。myPosition是对象destinations,collisions是对象数组:
let myPosition={x:0,y:0};
let destinations = [{x: 0, y: 5}, {x: 2, y: 0}, {x: 2, y: 2}];
let collisions = [{x: 1, y: 0},{x: 1, y: 1},{x: 1, y: 2},{x: 1, y: 3},{x: 1, y: 4},{x: 2, y: 1},{x: 2, y: 0},{x: 2, y: 1}]有了这段代码(现场演示),我可以找到最近的目的地,但它根本不知道碰撞。我不知道如何编写算法,这将额外检查碰撞,并在上述场景中给出输出0,5。
也有假设,我们不能对角移动。
我找到了这就是答案,它似乎为我的问题提供了答案,但我无法让它与我的输入数组一起工作。
发布于 2019-03-24 13:30:03
我使用了pathFinding.js库,查找非常简单:
currentPath = finder.findPath(heroCoords.x,
heroCoords.y,
monstersCoords[i].x,
monstersCoords[i].y,
currentGrid);https://stackoverflow.com/questions/55305115
复制相似问题