Example #1
0
 def __call__(self, state):
     self.state = NodeState.SUCCESS
     problem = sa.PositionSearchProblem(state, visualize=False)
     pos = search.breadthFirstSearchPath(problem)
     problem = sa.positionSearchP(state, goal=pos, visualize=False)
     vals = search.aStarSearchAvoid(problem, state, sa.AvoidGhosts)
     return vals[0]
Example #2
0
 def __call__(self, state):
     gpos = state.getGhostPositions()
     offsetx = 3
     offsety = 2
     walls = state.getWalls()
     top, right = walls.height - 2, walls.width - 2
     timer = []
     for index in range(1, len(state.data.agentStates)):
         timer.append(state.data.agentStates[index].scaredTimer)
     if sum(timer) > 10/len(gpos):
         vals = []
         vals_len = []
         for index in range(len(gpos)):
             if timer[index] > 10:
                 tmppos = gpos[index]
                 x = int(tmppos[0])
                 y = int(tmppos[1])
                 newpos=(x,y)
                 if (x < right/2+offsetx and x > right/2-offsetx) and (y < top/2+offsety and y > top/2-offsety):
                     continue
                 problem = sa.positionSearchP(state, goal=newpos, visualize=False)
                 tmp_val = search.aStarSearchAvoid(problem,state,sa.AvoidGhosts)
                 vals.append(tmp_val)
                 vals_len.append(len(tmp_val))
                 self.state = NodeState.SUCCESS
         if len(vals) > 0:
             return vals[np.argmin(vals_len)][0]
     self.state = NodeState.FAILED
     return None
Example #3
0
 def __call__(self, state):
     capsules = state.getCapsules()
     ## Set deppending on the level!
     if (len(capsules) != 2):
         self.firstEaten = True
     else:
         self.firstEaten = False
     if not self.firstEaten:
         vals = []
         for capsule in capsules:
             problem = sa.positionSearchP(state, goal=capsule)
             vals.append(search.aStarSearch(problem, sa.manhattanHeuristic))
         path = sorted(vals, key=len)[0]
         self.state = NodeState.SUCCESS
         return path[0]
     else:
         self.state = NodeState.FAILED
         return None
Example #4
0
 def __call__(self, state):
     capsules = state.getCapsules()
     minammountCapsules = 2
     ## Set deppending on the level!
     if (len(capsules) < minammountCapsules):
         self.firstEaten = True
     else:
         self.firstEaten = False
     if not self.firstEaten:
         vals = []
         for capsule in capsules:
             problem = sa.positionSearchP(state, goal=capsule, visualize=False)
             vals.append(search.aStarSearchAvoid(problem,state, sa.AvoidGhosts))
         path = sorted(vals, key=len)[0]
         self.state = NodeState.SUCCESS
         return path[0]
     else:
         self.state = NodeState.FAILED
         return None