예제 #1
0
        /// <summary>
        /// A method that returns all valid NOW actions for the agent, given the context.
        /// </summary>
        /// <param name="agent"></param>
        public List <PlanAction> GetAvailableActions(KeyValuePair <AgentStateStatic, AgentStateDynamic> agent)
        {
            // We initialize a variable that stores a list of valid actions. We will add actions that meet the conditions to it.
            List <PlanAction> result = new List <PlanAction>();

            // If the agent is alive.
            if (agent.Value.GetStatus())
            {
                Talk talk = new Talk();
                result.Add(talk);

                // If the agent thinks that one of the other agents is angry, then he can try to calm him down.
                if (agent.Value.ThinksThatSomeoneIsAngry())
                {
                    Reassure reassure = new Reassure();
                    result.Add(reassure);
                }

                // If the agent is scared, then he can start running away.
                if (agent.Value.CheckScared())
                {
                    Run run = new Run();
                    result.Add(run);
                }

                // If the role of the agent is a killer.
                if (agent.Key.GetRole() == AgentRole.KILLER)
                {
                    // Then he can kill.
                    Kill kill = new Kill();
                    result.Add(kill);

                    // He can also lure into a trap (being in a place where there is no one).
                    Entrap entrap = new Entrap();
                    result.Add(entrap);

                    // Or lure into a trap in another way (telling another agent that a certain place is suspicious, forcing him to be sent there).
                    TellAboutASuspicious tellAboutASuspicious = new TellAboutASuspicious();
                    result.Add(tellAboutASuspicious);
                }

                if (agent.Key.GetRole() == AgentRole.USUAL)
                {
                    // If he is angry, then he can start fighting.
                    if (agent.Value.GetObjectOfAngry().AngryCheck())
                    {
                        Fight fight = new Fight();
                        result.Add(fight);
                    }
                }

                if (agent.Key.GetRole() == AgentRole.USUAL || agent.Key.GetRole() == AgentRole.KILLER)
                {
                    // And he can do nothing.
                    NothingToDo nothingToDo = new NothingToDo();
                    result.Add(nothingToDo);
                }

                // If the agent role is usual or player.
                if (agent.Key.GetRole() == AgentRole.USUAL || agent.Key.GetRole() == AgentRole.PLAYER)
                {
                    // If he is angry, then he can start fighting.
                    if (agent.Value.GetObjectOfAngry().AngryCheck())
                    {
                        // And if he has evidence against the killer, he can try to neutralize him.
                        if (agent.Value.GetEvidenceStatus().CheckEvidence())
                        {
                            NeutralizeKiller neutralizeKiller = new NeutralizeKiller();
                            result.Add(neutralizeKiller);
                        }
                    }

                    if (!agent.Value.CheckIfLocationIsExplored(agent.Value.GetMyLocation()))
                    {
                        // Can look for evidence against the killer in the room where he is.
                        InvestigateRoom investigateRoom = new InvestigateRoom();
                        result.Add(investigateRoom);
                    }
                }

                // Then he can move.
                Move move = new Move();
                result.Add(move);
            }

            // Returning a list of valid actions.
            return(result);
        }
예제 #2
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;
                }
            }
        }
예제 #3
0
        public void AddAction(string actionName, List <string> parameters)
        {
            if (actionName.Contains("killer_move"))
            {
                Move move = new Move();

                foreach (var parameter in parameters)
                {
                    move.Arguments.Add(parameter);
                }

                actions.Add(move);
            }
            if (actionName.Contains("move") && !actionName.Contains("killer"))
            {
                Move move = new Move();
                actions.Add(move);
            }
            if (actionName.Contains("kill") && !actionName.Contains("move") && !actionName.Contains("neutralize"))
            {
                Kill kill = new Kill();
                actions.Add(kill);
            }
            if (actionName == "entrap")
            {
                Entrap entrap = new Entrap();
                actions.Add(entrap);
            }
            if (actionName == "fight")
            {
                Fight fight = new Fight();
                actions.Add(fight);
            }
            if (actionName == "investigate-room")
            {
                InvestigateRoom investigateRoom = new InvestigateRoom();
                actions.Add(investigateRoom);
            }
            if (actionName == "neutralize-killer")
            {
                NeutralizeKiller neutralizeKiller = new NeutralizeKiller();
                actions.Add(neutralizeKiller);
            }
            if (actionName == "nothing-to-do")
            {
                NothingToDo nothingToDo = new NothingToDo();
                actions.Add(nothingToDo);
            }
            if (actionName == "reassure")
            {
                Reassure reassure = new Reassure();
                actions.Add(reassure);
            }
            if (actionName == "run")
            {
                Run run = new Run();
                actions.Add(run);
            }
            if (actionName == "tell-about-killer")
            {
                TellAboutASuspicious tellAboutASuspicious = new TellAboutASuspicious();
                actions.Add(tellAboutASuspicious);
            }
            if (actionName == "talk")
            {
                Talk talk = new Talk();
                actions.Add(talk);
            }
        }
예제 #4
0
        /// <summary>
        /// To skip a turn (action), an action "NothingToDo" is created and applied.
        /// </summary>
        public void SkipTurn(WorldDynamic currentState)
        {
            NothingToDo skipAction = new NothingToDo();

            skipAction.ApplyEffects(ref currentState);
        }