newPos给了我pacman代理的位置(比如(3,5))。你知道吗
newPos = successorGameState.getPacmanPosition()
旧食物以网格的形式给我剩下的食物。我们可以通过列表访问网格,比如如果我们想知道(3,4)是否有食物,那么我们就知道了
oldFood = currentGameState.getFood()
if oldFood[x][y] == true....
newGhostStates = successorGameState.getGhostStates()
这会给我一份幽灵的名单。你知道吗
我需要找到周围的鬼魂,也就是靠近newPos的鬼魂。我该怎么做?我无法实施它。我在谷歌上得到了一个解决方案,但我不想使用这种方法。这里用的是半径,我不知道为什么?你知道吗
def surroundingGhosts(gList,(x,y), radius=1):
allGhosts = {}
sGhosts = []
for g in gList:
### map ghosts positions to ghost obj
allGhosts[g.getPosition()] = g
checkPos = []
for xx in range(x-radius,x+radius+1):
if xx == x:
for yy in range(y-radius, y+radius+1):
checkPos += [(xx,yy)]
else:
checkPos += [(xx,y)]
for p in checkPos:
if p[0] and p[1] >= 0:
if p in allGhosts:
sGhosts += [allGhosts[p]]
return sGhosts
基本上,我需要找到与我目前职位相关的职位。然后我将检查这些位置与gjost位置,如果它们匹配,则有一个幽灵。你知道吗
好吧,想象一下:
p是吃豆人G是鬼。“radius=1”是pacman附近的重影。这张支票能找到鬼魂。但是:
但是在这里,半径为1的鬼魂是找不到的,所以半径为2是必需的。你知道吗
相关问题 更多 >
编程相关推荐