Plan Space

A plan space algorithm represents a quest as a graph (see Generative Grammars for explanation of graphs) where nodes are partial or complete plans for what happens in the quest, and edges are operations like "walk" or "fight" that take you closer to a complete plan from start to end.

Plan Space Algorithm
This algorithm is also presented in pseudocode, and will be implemented in a code example. Plan space algorithms are more elaborate than state space, and is also considered more akin to how humans naturally think. The starting point, the root node, has the initial state and the goal state. Each step along the graph goes closer to an end state, and tries to fix a flaw in the plan, which is one of two things: 1: Construct the root node as the planning problem 2: Select a non-terminal node, based on a heuristic value 3: Select a flaw in the node If there is no flaw, the node is a full plan from initial state to end, return it as a solution 4: Create children by repairing the flaw If the flaw is an open precondition a) Establish a causal link from an existing plan step, or      b) Add a plan step that satisfies the open precondition If the flaw is a threat a) Add a temporal ordering constraint so that the causal link is not disrupted, or      b) Add a binding constraint to separate the threatening step from steps involved in the threatened casual link If the flaw is not repairable, this node is terminal and cannot lead to a solution. Go to step 2. If the number of nodes created exceeds the amount of nodes allowed, mark this node as a failure and try another one. 5: Otherwise go to step 2 and repeat
 * An open precondition, a precondition for a solution that has not yet been met.
 * A threat, a condition that could undo an established step.

Plan Space Algorithm Explained
This more complicated algorithm begins with knowledge of both the start and end states. For each state being checked, it analyzes it with a heuristic algorithm to see which one is the most likely to reach a solution the quickest. Whichever one is the best is selected. The algorithm then looks for either unmet conditions or cases that might undo existing conditions. If the flaw can't be repaired, the node is discarded and the next best one is picked. This continues until either the amount of nodes is too big, or a node with no flaws is found. The path from the starting node, to the one with no flaws, is the desired path.