Example #1
0
class Agent:
    def __init__( self ):
        # [rps] agents each have their own worldstate
        #   agents will have to communicate with each other to share worldstate
        self.planner = GOAP( self )
        self.goals = []
        heapq.heapify( self.goals )
        self.actions = []
        self.worldstate = {}

    def addAction( self, newAction ):
        # [rps] newAction must be a clone!!
        # [rps] must call this method when building agent in memory
        #   becuase it sets the action's neighbors to actions that
        #   this agent has
        for action in self.actions:
            if newAction.satisfies( action ):
                action.chain.append( newAction )


            if action.satisfies( newAction ):
                newAction.chain.append( action )

        self.actions.append( newAction )

    def worldstateSatisfies( self, actionOrGoal ):
        # [rps] this returns true if an action or goal can be completed in agent's current state
        # [rps] since the target state has to completely match current worldstate
        #   this will return false the first time it comes across an inconsistency
        targetState = actionOrGoal.getTargetState()

        # [rps] just return true if the target state is nothing
        #   saves the planner from going through the entire agent's worldstate for no reason
        if not len( targetState ):
            return True

        for tsKey, tsValue in targetState.iteritems():
            if tsKey in self.worldstate:
                if self.worldstate[ tsKey ] is not tsValue:
                    return False
            else:
                if tsValue is not False:
                    return False

        return True

    def formulate( self ):
        self.planner.formulate()
Example #2
0
 def __init__( self ):
     # [rps] agents each have their own worldstate
     #   agents will have to communicate with each other to share worldstate
     self.planner = GOAP( self )
     self.goals = []
     heapq.heapify( self.goals )
     self.actions = []
     self.worldstate = {}