예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }