The newPos gives me the position of pacman agent (like (3,5) ).
newPos = successorGameState.getPacmanPosition()
The oldfood gives me the remaining food available for pacman in the form of grid. We can access the grid via list like if we want to know if food is available at (3,4) then we do
oldFood = currentGameState.getFood()
if oldFood[x][y] == true....
newGhostStates = successorGameState.getGhostStates()
This will give me the list for the ghosts that are present.
I need to find the surrounding ghos开发者_StackOverflow社区ts i.e the ghosts that are next to newPos. How would I do that ? I am not able to implement it. I got a soln on google but I dont want to use this method. Here , radius is used, i dont know why?
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
basically , i need to find the surrrounding positions related to my current postion. Then I will check these postions with the gjost positions, if they match, then there is a ghost.
Well, imagine this:
...
.P.
.G.
P is the pacman an G is a ghost. Checking with "radius = 1" is ghosts adjacent to the pacman. This check will find the ghost. But:
....
.P.G
....
....
But here a ghost won't be found with radius of 1, so radius of 2 is required.
精彩评论