コード例 #1
0
        public void MultiAVandAC(ref PlanAction receivedAction,
                                 WorldDynamic currentState,
                                 KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                 CSP_Module cspModule,
                                 StoryGraph currentGraph,
                                 StoryNode currentNode,
                                 bool root,
                                 ref int globalNodeNumber,
                                 ref Queue <StoryNode> queue)
        {
            List <PlanAction> actionsList = cspModule.MassiveAssignVariables(ref receivedAction, currentState, agent);

            AgentStateStatic  sCurrentAgent = (AgentStateStatic)agent.Key.Clone();
            AgentStateDynamic dCurrentAgent = (AgentStateDynamic)agent.Value.Clone();
            KeyValuePair <AgentStateStatic, AgentStateDynamic> currentAgent =
                new KeyValuePair <AgentStateStatic, AgentStateDynamic>(sCurrentAgent, dCurrentAgent);

            WorldDynamic statePrefab = (WorldDynamic)currentState.Clone();

            foreach (var a in actionsList)
            {
                ActionControl(a, currentGraph, currentAgent, statePrefab, currentNode, root, ref globalNodeNumber, ref queue);
            }

            // Cleaning
            actionsList = null;
            currentNode = null;
            statePrefab = null;
            GC.Collect();
        }
コード例 #2
0
        public void SingleAVandAC(ref PlanAction receivedAction,
                                  WorldDynamic currentState,
                                  KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                  CSP_Module cspModule,
                                  StoryGraph currentGraph,
                                  StoryNode currentNode,
                                  bool root,
                                  ref int globalNodeNumber,
                                  ref Queue <StoryNode> queue)
        {
            cspModule.AssignVariables(ref receivedAction, currentState, agent);

            ActionControl(receivedAction, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue);

            // Cleaning
            currentNode = null;
            GC.Collect();
        }
コード例 #3
0
        public void ActionCounteract(PlanAction action,
                                     StoryGraph currentGraph,
                                     KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                     WorldDynamic currentState,
                                     StoryNode currentNode,
                                     bool root,
                                     ref int globalNodeNumber,
                                     ref Queue <StoryNode> queue)
        {
            CSP_Module cspModule = new CSP_Module();

            bool stageOne_NewNode       = true;
            bool stageTwo_ConnectedNode = false;
            bool counterreactionFound   = false;

            bool skip = false;

            string currentAction = action.GetType().ToString().Remove(0, 20);

            while (!counterreactionFound)
            {
                PlanAction counterreactionTalk = new CounterTalk();
                bool       assignVariables     = cspModule.AssignVariables(ref counterreactionTalk, currentState, agent);
                counterreactionTalk.Arguments.Add(currentAction);

                if (assignVariables && counterreactionTalk.CheckPreconditions(currentState))
                {
                    bool constractionAndDeadEndAndCicle = false;
                    bool duplicate = false;

                    CounterreactionControl(counterreactionTalk, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                           ref constractionAndDeadEndAndCicle, ref duplicate);

                    if (stageOne_NewNode)
                    {
                        if (constractionAndDeadEndAndCicle && duplicate)
                        {
                            ApplyAction(counterreactionTalk, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                            counterreactionFound = true;
                        }
                    }
                    else if (stageTwo_ConnectedNode)
                    {
                        if (constractionAndDeadEndAndCicle && !duplicate)
                        {
                            currentGraph.DuplicateNodeConnecting(currentState, counterreactionTalk, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                            counterreactionFound = true;
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionEntrap = new CounterEntrap();
                    assignVariables = cspModule.AssignVariables(ref counterreactionEntrap, currentState, agent);
                    counterreactionEntrap.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionEntrap.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionEntrap, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionEntrap, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionEntrap, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionKill = new CounterKill();
                    assignVariables = cspModule.AssignVariables(ref counterreactionKill, currentState, agent);
                    counterreactionKill.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionKill.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionKill, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionKill, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionKill, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionIR = new InvestigateRoom();
                    assignVariables = cspModule.AssignVariables(ref counterreactionIR, currentState, agent);
                    counterreactionIR.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionIR.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionIR, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionIR, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionIR, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionNK = new CounterNeutralizeKiller();
                    assignVariables = cspModule.AssignVariables(ref counterreactionNK, currentState, agent);
                    counterreactionNK.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionNK.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionNK, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionNK, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionNK, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionTalkAboutSuspicious = new CounterTellAboutASuspicious();
                    assignVariables = cspModule.AssignVariables(ref counterreactionTalkAboutSuspicious, currentState, agent);
                    counterreactionTalkAboutSuspicious.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionTalkAboutSuspicious.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionTalkAboutSuspicious, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionTalkAboutSuspicious, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionTalkAboutSuspicious, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionFight = new CounterFight();
                    assignVariables = cspModule.AssignVariables(ref counterreactionFight, currentState, agent);
                    counterreactionFight.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionFight.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionFight, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionFight, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionFight, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionReassure = new CounterReassure();
                    assignVariables = cspModule.AssignVariables(ref counterreactionReassure, currentState, agent);
                    counterreactionReassure.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionReassure.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionReassure, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionReassure, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionReassure, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionRun = new CounterRun();
                    assignVariables = cspModule.AssignVariables(ref counterreactionRun, currentState, agent);
                    counterreactionRun.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionRun.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionRun, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionRun, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionRun, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (!counterreactionFound)
                {
                    PlanAction counterreactionMove = new CounterMove();
                    assignVariables = cspModule.AssignVariables(ref counterreactionMove, currentState, agent);
                    counterreactionMove.Arguments.Add(currentAction);

                    if (assignVariables && counterreactionMove.CheckPreconditions(currentState))
                    {
                        bool constractionAndDeadEndAndCicle = false;
                        bool duplicate = false;

                        CounterreactionControl(counterreactionMove, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                               ref constractionAndDeadEndAndCicle, ref duplicate);

                        if (stageOne_NewNode)
                        {
                            if (constractionAndDeadEndAndCicle && duplicate)
                            {
                                ApplyAction(counterreactionMove, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                                counterreactionFound = true;
                            }
                        }
                        else if (stageTwo_ConnectedNode)
                        {
                            if (constractionAndDeadEndAndCicle && !duplicate)
                            {
                                currentGraph.DuplicateNodeConnecting(currentState, counterreactionMove, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                                counterreactionFound = true;
                            }
                        }
                    }
                }

                if (stageTwo_ConnectedNode)
                {
                    PlanAction counterreactionSkip = new NothingToDo();
                    counterreactionSkip.Arguments.Add(agent);

                    bool constractionAndDeadEndAndCicle = false;
                    bool duplicate = false;

                    CounterreactionControl(counterreactionSkip, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue,
                                           ref constractionAndDeadEndAndCicle, ref duplicate);

                    if (constractionAndDeadEndAndCicle && duplicate)
                    {
                        ApplyAction(counterreactionSkip, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, true, true);
                        counterreactionFound = true;
                    }
                    else if (constractionAndDeadEndAndCicle && !duplicate)
                    {
                        currentGraph.DuplicateNodeConnecting(currentState, counterreactionSkip, agent, currentNode, globalNodeNumber, ref queue, true, ref skip);
                        counterreactionFound = true;
                    }
                }

                //stageOne_NewNode = false;
                //stageTwo_ConnectedNode = true;


                if (stageOne_NewNode)
                {
                    stageOne_NewNode       = false;
                    stageTwo_ConnectedNode = true;
                }
                else if (stageTwo_ConnectedNode)
                {
                    stageOne_NewNode       = true;
                    stageTwo_ConnectedNode = false;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// The agent updates his beliefs, calculates a plan, chooses an action, assigns variables to it, and sends it for further control.
        /// </summary>
        public void ActionRequest(KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                  ref StoryGraph currentGraph,
                                  ref WorldDynamic currentState,
                                  StoryNode currentNode,
                                  bool root,
                                  ref int globalNodeNumber,
                                  ref Queue <StoryNode> queue)
        {
            CSP_Module cspModule = new CSP_Module();

            if (agent.Key.GetRole().Equals(AgentRole.PLAYER))
            {
                agent.Value.RefreshBeliefsAboutTheWorld(currentState, agent);
                agent.Value.GenerateNewPDDLProblem(agent, currentState);
                agent.Value.ReceiveAvailableActions(agent);

                List <PlanAction> receivedActions = agent.Value.GetAvailableActions();

                for (int i = 0; i < receivedActions.Count; i++)
                {
                    PlanAction receivedAction = receivedActions[i];

                    if (receivedAction != null)
                    {
                        switch (receivedAction.GetType().ToString().Remove(0, 20))
                        {
                        case "Move":
                            MultiAVandAC(ref receivedAction, currentState, agent, cspModule, currentGraph, currentNode, root,
                                         ref globalNodeNumber, ref queue);
                            break;

                        case "Fight":     // Not relevant yet
                            break;

                        case "InvestigateRoom":
                            SingleAVandAC(ref receivedAction, currentState, agent, cspModule, currentGraph, currentNode, root,
                                          ref globalNodeNumber, ref queue);
                            break;

                        case "NeutralizeKiller":     // Not relevant yet
                            break;

                        case "NothingToDo": SkipTurn(currentState);
                            break;

                        case "Reassure":     // Not relevant yet
                            break;

                        case "Run":     // Not relevant yet
                            break;

                        case "Talk":     // Not relevant yet
                            break;
                        }

                        // Cleaning
                        receivedAction = null;
                        GC.Collect();
                    }
                }

                // Cleaning
                receivedActions = null;
                GC.Collect();
            }
            else
            {
                agent.Value.RefreshBeliefsAboutTheWorld(currentState, agent);
                agent.Value.GenerateNewPDDLProblem(agent, currentState);
                agent.Value.CalculatePlan(agent, currentState);
                agent.Value.ReceiveAvailableActions(agent);

                PlanAction receivedAction = agent.Value.ChooseAction();

                if (receivedAction != null)
                {
                    cspModule.AssignVariables(ref receivedAction, currentState, agent);

                    ActionControl(receivedAction, currentGraph, agent, currentState, currentNode, root, ref globalNodeNumber, ref queue);

                    // Cleaning
                    receivedAction = null;
                    currentNode    = null;
                    GC.Collect();
                }
                else
                {
                    SkipTurn(currentState);
                }
            }
        }