예제 #1
0
    def __init__(self, index,
                 extractor='pacai.core.featureExtractors.IdentityExtractor', **kwargs):
        super().__init__(index, **kwargs)
        self.featExtractor = reflection.qualifiedImport(extractor)

        # You might want to initialize weights here.
        self.weights = counter.Counter()
예제 #2
0
def createTeam(firstIndex, secondIndex, isRed,
        first = 'pacai.agents.capture.dummy.DummyAgent',
        second = 'pacai.agents.capture.dummy.DummyAgent'):
    """
    This function should return a list of two agents that will form the capture team,
    initialized using firstIndex and secondIndex as their agent indexed.
    isRed is True if the red team is being created,
    and will be False if the blue team is being created.
    """

    firstAgent = reflection.qualifiedImport(first)
    secondAgent = reflection.qualifiedImport(second)

    return [
        firstAgent(firstIndex),
        secondAgent(secondIndex),
    ]
예제 #3
0
    def __init__(self,
                 index,
                 evalFn='pacai.core.eval.score',
                 depth=2,
                 **kwargs):
        super().__init__(index)

        self._evaluationFunction = reflection.qualifiedImport(evalFn)
        self._treeDepth = int(depth)
예제 #4
0
    def _fetchSearchFunction(self, functionName, heuristicName):
        """
        Get the specified search function by name.
        If that function also takes a heurisitc (i.e. has a parameter called "heuristic"),
        then return a lambda that binds the heuristic to the function.
        """

        # Locate the function.
        function = reflection.qualifiedImport(functionName)

        # Check if the function has a heuristic.
        if 'heuristic' not in function.__code__.co_varnames:
            logging.info('[SearchAgent] using function %s.' % (functionName))
            return function

        # Fetch the heuristic.
        heuristic = reflection.qualifiedImport(heuristicName)
        logging.info('[SearchAgent] using function %s and heuristic %s.' %
                     (functionName, heuristicName))

        # Bind the heuristic.
        return lambda x: function(x, heuristic=heuristic)
예제 #5
0
    def loadAgent(name, index, args={}):
        """
        Load an agent with the given class name.
        The name can be fully qualified or just the bare class name.
        If the bare name is given, the class should appear in the
        `pacai.agents` or `pacai.student` package.
        """

        if (name.startswith('pacai.')):
            # This name looks like a fully qualified name, load it directly.
            agentClass = reflection.qualifiedImport(name)
            return agentClass(index=index, **args)
        else:
            # This is probably just a class name.
            return BaseAgent._loadAgentByName(name, index, args)
예제 #6
0
def loadAgents(isRed, agentModule, textgraphics, args):
    """
    Calls agent factories and returns lists of agents.
    """

    createTeamFunctionPath = agentModule + '.createTeam'
    createTeamFunction = reflection.qualifiedImport(createTeamFunctionPath)

    logging.info('Loading Team: %s', agentModule)
    logging.info('Arguments: %s', args)

    indexAddend = 0
    if (not isRed):
        indexAddend = 1
    indices = [2 * i + indexAddend for i in range(2)]

    return createTeamFunction(indices[0], indices[1], isRed, **args)
예제 #7
0
    def __init__(self,
                 index,
                 fn='pacai.student.search.depthFirstSearch',
                 prob='pacai.core.search.position.PositionSearchProblem',
                 heuristic='pacai.core.search.heuristic.null',
                 **kwargs):
        super().__init__(index)

        # Get the search problem type from the name.
        self.searchType = reflection.qualifiedImport(prob)
        logging.info('[SearchAgent] using problem type %s.' % (prob))

        # Get the search function from the name and heuristic.
        self.searchFunction = self._fetchSearchFunction(fn, heuristic)

        # The actions the search produced.
        self._actions = []

        # The currentl action (from self._actions) that the agent is performing.
        self._actionIndex = 0
    def __init__(self, index, evalFn="pacai.core.eval.score", **kwargs):
        super().__init__(index)

        self.evaluationFunction = reflection.qualifiedImport(evalFn)
        assert (self.evaluationFunction is not None)
예제 #9
0
 def __init__(self,
              index,
              extractor='pacai.core.featureExtractors.IdentityExtractor',
              **kwargs):
     super().__init__(index, **kwargs)
     self.featExtractor = reflection.qualifiedImport(extractor)