/// <summary> /// The method that controls the creation of the history graph. /// </summary> public StoryGraph CreateStoryGraph(StoryNode rootNode) { // We clone the root into a separate variable. StoryNode originRoot = (StoryNode)rootNode.Clone(); // We continue to work until at least one target state is reached. while (!reachedGoalState) { // We create a new graph by starting to expand the root. BFSTraversing(newStoryGraph.GetRoot()); // We go through the created graph, looking for target states in it. BFSGoalAchieveControl(newStoryGraph.GetRoot()); // If it was not possible to find even one target state in the constructed graph. if (!reachedGoalState || newStoryGraph.GetNodes().Count > maxNodes) { graphСonstructor.CreateGraph(newStoryGraph, @"D:\Graphviz\bin\newStoryGraph.dt"); // Then we clear the graph, and all the links added to the root. newStoryGraph = new StoryGraph(); originRoot.GetEdges().Clear(); originRoot.GetLinks().Clear(); // After that, we reassign to the previously cleared column an indication of the root. newStoryGraph.SetRoot((StoryNode)originRoot.Clone()); reachedGoalState = false; } } // We return a graph that is guaranteed to have at least one target state. return(newStoryGraph); }