Esempio n. 1
0
  def getAction( self, state ):
    pos = state.getGhostPosition(self.index)
    if self.origStart == None: self.origStart = pos
    chased = self.index % (state.getNumAgents() - 1) + 1
    chasing = self.index - 1
    if chasing == 0 : chasing =  state.getNumAgents() - 1

    chaserProblem = self.searchType(state, state.getGhostPosition(chasing), pos)
    pacProblem = self.searchType(state, state.getPacmanPosition(), pos)

    pacDir = self.searchFunction(pacProblem)
    successors = pacProblem.getSuccessors(pos)
    if  len(pacDir) <= CatAgent.DIST_FROM_PAC:
        noGo = [suc[0] for suc in successors if len(self.searchFunction(self.searchType(state, state.getPacmanPosition(), suc[0]))) <  len(pacDir) ]
    else:
      noGoDir = self.searchFunction(chaserProblem)
      try:
        noGoDir = noGoDir[0]
        noGo = Actions.directionToIndex(pos , noGoDir)
      except (TypeError, IndexError):
        noGo = None
    #if manhattanDistance(state.getGhost(chasing), state.getGhost(self.index)) < MIN_DIST
    #   return max(dist, action for dist in state.getLegalActions(self.index))
    problem = self.searchType(state, state.getGhostPosition(chased),
         pos, noGo)
    try:
      return self.searchFunction(problem)[0]
    except (TypeError, IndexError):
      if type(noGo) is list:
        return Directions.STOP

      # deColideProblem = self.searchType(state, self.origStart)
      return noGoDir #deColideProblem
Esempio n. 2
0
    def getAction(self, state):
        pos = state.getGhostPosition(self.index)
        if self.origStart == None: self.origStart = pos
        chased = self.index % (state.getNumAgents() - 1) + 1
        chasing = self.index - 1
        if chasing == 0: chasing = state.getNumAgents() - 1

        chaserProblem = self.searchType(state, state.getGhostPosition(chasing),
                                        pos)
        pacProblem = self.searchType(state, state.getPacmanPosition(), pos)

        pacDir = self.searchFunction(pacProblem)
        successors = pacProblem.getSuccessors(pos)
        if len(pacDir) <= CatAgent.DIST_FROM_PAC:
            noGo = [
                suc[0] for suc in successors if len(
                    self.searchFunction(
                        self.searchType(state, state.getPacmanPosition(),
                                        suc[0]))) < len(pacDir)
            ]
        else:
            noGoDir = self.searchFunction(chaserProblem)
            try:
                noGoDir = noGoDir[0]
                noGo = Actions.directionToIndex(pos, noGoDir)
            except (TypeError, IndexError):
                noGo = None
        #if manhattanDistance(state.getGhost(chasing), state.getGhost(self.index)) < MIN_DIST
        #   return max(dist, action for dist in state.getLegalActions(self.index))
        problem = self.searchType(state, state.getGhostPosition(chased), pos,
                                  noGo)
        try:
            return self.searchFunction(problem)[0]
        except (TypeError, IndexError):
            if type(noGo) is list:
                return Directions.STOP

            # deColideProblem = self.searchType(state, self.origStart)
            return noGoDir  #deColideProblem