/// <summary> /// Method is an entry point that controls the operation of the algorithm (the sequence of launching other methods). /// </summary> public void Start() { // We read the settings and create the initial state of the world. // ReadUserSettingsInput(); CreateInitialState(); CreateConstraints(); GenerateNewPDDLDomains(); // We create a start node (root) based on the start state of the world. StoryNode root = new StoryNode(); root.SetWorldState(currentStoryState); root.SetActivePlayer(false); root.SetActiveAgent(currentStoryState.GetFirstAgent()); newStoryGraph.SetRoot(root); // We go through all the agents and remember their goals. storyworldConvergence.ExtractGoals(currentStoryState); // The algorithm calculates a SPECIFIC story. newStoryGraph = CreateStoryGraph(newStoryGraph.GetRoot()); // Create a visual graph. graphСonstructor.CreateGraph(newStoryGraph, @"D:\Graphviz\bin\newStoryGraph.dt"); // Create an HTML file including Twine engine and generated history. //twineGraphConstructor.ConstructGraph(newStoryGraph); //twineGraphConstructor.CreateHTMLFileWithGame(); // SaveFile(); }
/// <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); }
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); }
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); }