所以,在我正在进行的A *搜索实现中,我可以使用路径查找的方向为up,left,right,down:
#define the moving direction: up /left /right /down
xs = (0, -1, 1, 0)
ys = (-1, 0, 0, 1)
如何将移动方向更改为:上,左,右,下,左上,左下,右上和右下?
至于成本,有向上,向左,向右,向下我有1.0,但如果我必须有成本为2.0的方向:左上,左下,右上和右下,我该如何实现是什么?
def get_cost(self, x1, y1, x2, y2):
if x1 == x2 or y1 == y2:
return 1.0
答案 0 :(得分:0)
好吧,您只需检查并查看您是否在每个轴上处于相同位置。
def get_cost(self, x1, y1, x2, y2):
if (x1 == x2 and y1 != y2) or (x1 != x2 and y1 == y2):
# you have just moved in one axis
return 1.0
else:
return 2.0