只是为了提高我的 java 脚本技能,我正在尝试用 js 开发一个 pacman 游戏。有一个 20 x 20 的网格。这个网格有 0 和 1,表示是否有墙或路径。现在我想开发一个算法让恶魔跟随吃豆人。我不确定我应该使用哪种算法。
所以我对函数的输入将是 foo(current position, pacman position,grid, path)
var maze = [ [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
[0,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,0],
[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0],
[0,1,0,1,0,1,1,1,1,0,0,1,1,1,1,0,1,0,1,0],
[0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0],
[0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
[0,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,0],
[0,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0],
[0,1,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,1,0],
[1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,1],
[0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,1,0],
[0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0],
[0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0],
[0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0],
[0,1,0,1,0,1,1,1,1,0,0,1,1,1,1,0,1,0,1,0],
[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0],
[0,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,0],
[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0]];