Пример #1
0
    public void generatePercepts()
    {
        MailBox <PerceptRequest> requests = simulationState.perceptRequests;

        PerceptRequest request;
        Percept        percept;

        // aca hay que sacar todos los requests de percepciones de la cola
        // y para cada uno, generar la percepcion correspondiente
        while (requests.NotEmpty())
        {
            if (requests.NBRecv(out request))
            {
                percept = new Percept(simulationState, request.agentID);
                request.agentPerceptMailbox.Send(percept);
            }
        }
    }
Пример #2
0
    public void handleActions()
    {
        Action                       currentAction;
        MailBox <Action>             raq    = simulationState.readyActionQueue;
        Dictionary <int, AgentState> agents = simulationState.agents;

        while (raq.NotEmpty())
        {
            // get action from the ready action queue
            // if the action is executable,
            //     put it in unity's action queue
            //     let the agent know that its action was executable
            // else
            //     let the agent know that its action was not executable
            //simulationState.stdout.Send(String.Format("AH: there are actions to process...\n"));
            if (raq.NBRecv(out currentAction))
            {
                int agentID = currentAction.agentID;
                try {
                    AgentState agentState = agents[agentID];
                    agentState.lastAction     = currentAction;
                    agentState.lastActionTime = SimulationState.getInstance().getTime();
                    if (simulationState.executableAction(currentAction))
                    {
                        //simulationState.stdout.Send(String.Format("AH: the action is executable.\n"));
                        //agents[agentID].results.Send(ActionResult.success);
                        agents[agentID].lastActionResult = ActionResult.success;
                        simulationState.applyActionEffects(currentAction);
                    }
                    else
                    {
                        //simulationState.stdout.Send(String.Format("AH: the action is not executable.\n"));
                        agents[agentID].results.Send(ActionResult.failure);
                        agents[agentID].lastActionResult = ActionResult.failure;
                    }
                }
                catch (System.Collections.Generic.KeyNotFoundException e) {
                    simulationState.stdout.Send(String.Format("AH: Error: agent id {0} not present in agent database.\n", agentID));
                    Debug.LogError(e.ToString());
                }
            }
        }
    }