Exemplo n.º 1
0
        /// <summary>
        /// Checking whether the application of an action would violate the established constraints.
        /// </summary>
        public bool ConstraintsControl(WorldDynamic currentState, PlanAction action, bool succsessControl)
        {
            WorldDynamic worldForTest = (WorldDynamic)currentState.Clone();

            if (!succsessControl)
            {
                action.Fail(ref worldForTest);
            }
            else
            {
                action.ApplyEffects(ref worldForTest);
            }

            foreach (var constraint in constraints)
            {
                if (!constraint.IsSatisfied(worldForTest))
                {
                    // Cleaning
                    worldForTest = null;
                    GC.Collect();

                    // Return result
                    return(false);
                }
            }

            // Cleaning
            worldForTest = null;
            GC.Collect();

            // Return result
            return(true);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new node for the story graph and inserts it.
        /// </summary>
        public void CreateNewNode(PlanAction action,
                                  KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                  WorldDynamic currentState,
                                  StoryNode currentNode,
                                  ref int globalNodeNumber,
                                  bool succsessControl,
                                  bool counteract)
        {
            WorldDynamic newState = (WorldDynamic)currentState.Clone();

            if (!succsessControl)
            {
                action.Fail(ref newState);
            }
            else
            {
                action.ApplyEffects(ref newState);
            }
            newState.UpdateHashCode();

            // Create an empty new node.
            StoryNode newNode = new StoryNode();

            if (counteract)
            {
                newNode.counteract = true;
            }

            // We assign the state of the world (transferred) to the new node.
            newNode.SetWorldState((WorldDynamic)newState.Clone());

            newNode.SetActiveAgent(newNode.GetWorldState().GetAgentByName(agent.Key.GetName()));
            if (agent.Key.GetRole() == AgentRole.PLAYER)
            {
                newNode.SetActivePlayer(true);
            }
            else
            {
                newNode.SetActivePlayer(false);
            }

            ConnectionTwoNodes(action, currentNode, newNode, false);

            globalNodeNumber++;
            newNode.SetNumberInSequence(globalNodeNumber);

            if (nodes.Contains(newNode))
            {
                bool test = true;
            }

            // Add a new node to the graph.
            AddNode(newNode);
        }
Exemplo n.º 4
0
        public StoryNode CreateTestNode(WorldDynamic currentState,
                                        PlanAction action,
                                        KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                        StoryNode currentNode,
                                        bool connection,
                                        int globalNodeNumber,
                                        bool succsessControl)
        {
            WorldDynamic worldForTest = (WorldDynamic)currentState.Clone();

            if (!succsessControl)
            {
                action.Fail(ref worldForTest);
            }
            else
            {
                action.ApplyEffects(ref worldForTest);
            }
            worldForTest.UpdateHashCode();

            StoryNode testNode = new StoryNode();

            //if (counteract) { testNode.counteract = true; }
            //testNode.SetWorldState(worldForTest);
            testNode.SetWorldState((WorldDynamic)worldForTest.Clone());

            // Create a clone of the agent.
            //KeyValuePair<AgentStateStatic, AgentStateDynamic> newAgent =
            //    new KeyValuePair<AgentStateStatic, AgentStateDynamic>((AgentStateStatic)agent.Key.Clone(), (AgentStateDynamic)agent.Value.Clone());
            testNode.SetActiveAgent(testNode.GetWorldState().GetAgentByName(agent.Key.GetName()));

            // We take the last node from the list of all nodes and assign whether the player is active and which of the agents was active on this turn.
            if (agent.Key.GetRole() == AgentRole.PLAYER)
            {
                testNode.SetActivePlayer(true);
            }
            else
            {
                testNode.SetActivePlayer(false);
            }

            //testNode.SetActiveAgent(newAgent);

            /*if (connection)
             * {
             *  ConnectionTwoNodes(action, currentNode, testNode, false);
             * }*/

            testNode.SetNumberInSequence(globalNodeNumber + 1);

            return(testNode);
        }
Exemplo n.º 5
0
        public bool DeadEndsControl(PlanAction action,
                                    WorldDynamic currentState,
                                    KeyValuePair <AgentStateStatic, AgentStateDynamic> player,
                                    bool succsessControl)
        {
            if (player.Key.GetRole() == AgentRole.PLAYER)
            {
                WorldDynamic worldForTest = (WorldDynamic)currentState.Clone();
                if (!succsessControl)
                {
                    action.Fail(ref worldForTest);
                }
                else
                {
                    action.ApplyEffects(ref worldForTest);
                }

                worldForTest.GetAgentByRole(AgentRole.PLAYER).Value.CalculatePlan(worldForTest.GetAgentByRole(AgentRole.PLAYER), worldForTest);

                if (worldForTest.GetAgentByRole(AgentRole.PLAYER).Value.GetPlanStatus())
                {
                    // Cleaning
                    worldForTest = null;
                    GC.Collect();

                    // Return result
                    return(true);
                }
                else
                {
                    // Cleaning
                    worldForTest = null;
                    GC.Collect();

                    // Return result
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 6
0
        public void CreateRootNode(PlanAction action,
                                   KeyValuePair <AgentStateStatic, AgentStateDynamic> agent,
                                   WorldDynamic currentState,
                                   StoryNode currentNode,
                                   ref int globalNodeNumber,
                                   bool succsessControl)
        {
            WorldDynamic newState = (WorldDynamic)currentState.Clone();

            if (!succsessControl)
            {
                action.Fail(ref newState);
            }
            else
            {
                action.ApplyEffects(ref newState);
            }

            if (agent.Key.GetRole() == AgentRole.PLAYER)
            {
                currentNode.SetActivePlayer(true);
            }
            else
            {
                currentNode.SetActivePlayer(false);
            }

            // We assign the state of the world (transferred) to the new node.
            currentNode.SetWorldState((WorldDynamic)newState.Clone());

            //Edge newEdge = new Edge();

            // We adjust the edge - assign its action and indicate the nodes that it connects.
            //newEdge.SetAction(action);
            //newEdge.SetUpperNode(ref currentNode);

            //currentNode.AddEdge(newEdge);

            globalNodeNumber++;
            currentNode.SetNumberInSequence(globalNodeNumber);
        }