0
newPos给我pacman代理的位置(如(3,5))。如何检查python中的邻居状态
newPos = successorGameState.getPacmanPosition()
旧食品给我剩余的食物可用于网格形式的pacman。我们可以通过一样,如果我们想知道,如果食物可在(3,4)列表访问网格然后我们做
oldFood = currentGameState.getFood()
if oldFood[x][y] == true....
newGhostStates = successorGameState.getGhostStates()
这会给我的列表中所存在的鬼。
我需要找到周围的幽灵,即与newPos相邻的幽灵。我会怎么做?我无法实现它。我有一个谷歌soln,但我不想使用这种方法。在这里,使用半径,我不知道为什么?
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位置,如果他们匹配,那么有一个鬼。
有没有其他的方法可以做到这一点?不使用半径? – Shilpa 2010-07-31 06:45:38
基本上,我需要找到与我当前位置相关的周边位置。然后,我会检查这些位置与gjost位置,如果他们匹配,那么有一个鬼。 – Shilpa 2010-07-31 06:48:44
@Shilpa:如果你只需要相邻的位置(比如Pacman的右下角),检查x,y + 1,x,y-1,x + 1,y, 1,你就完成了。这可以扩展到更长的范围,代码可能比上面粘贴的代码简单一些。 – 2010-07-31 06:50:30