The project is no longer under maintenance. Please visit LINQ to A* for latest version.
Heuristic Suite is an experimental implementation of a series of heuristic algorithms in generic programming. The project is aimed to provide an infrastructure that can be applied to any puzzle - as long as the puzzle can be resolved with the algorithm.
Implemented algorithms:
The implementation is fully object-oriented and takes advantages of built-in .NET Framework comparison mechanism such as IComparer(T) and IEqualityComparer(T) to create great compatibility with .NET Standard and entire .NET ecosystem. Source code can be easily brought to other platforms such as Unity and Xamarin.
In order to apply the algorithm to puzzle, following implementations are needed:
Step Definition The type that defines step of the puzzle will be required to implement IStep(TKey) interface. The Key property serves two purposes:
Step Comparison Steps are compared to each other based on Key property to determine which has better score. The comparison can be done in one of following ways:
Key.The Available Steps from Current Step Next step information can be provided by implementing INextStepFactory(TKey, TStep) interface, or providing NextStepFactory delegate.
After which, the algorithm can be run by invoking FindSolution method with from and goal steps as parameters. If the solution exists, each of steps can be obtained by calling Enumerate method. Steps can be Reversed before the enumeration starts.
The project provides HeuristicComparer and DiscreteHeuristicComparer for different step comparison scenarios.
Key property can be directly compared to each other without explicit h(n) function, by default, DiscreteHeuristicComparer will be used for faster step comparison.HeuristicComparer will be used to perform traditional estimation f(n) = g(n) + h(n).The HeuristicFunctionPreference enumeration enable users to change the balance of estimation f(n) = g(n) + h(n). When two steps are evaluated same score, the enumeration decides which function, g(n) or h(n), will be considered first. The changed balance can affect the behavior of heuristic algorithm.
Path Finding (AlgorithmForce.Example.PathFinding)
The example demonstrates the most common and traditional puzzle that use heuristic algorithms to solve.
8-Puzzle (AlgorithmForce.Example.EightPuzzle)
The example demonstrates how to solve the 8-puzzle with heuristic algorithm. The initial and goal steps of the puzzle are shown below:
Coins Flipping Puzzle (AlgorithmForce.Example.CoinsFlipping)
This example demonstrates how the game AI solves the coins flipping puzzle. In the puzzle, only a pair of adjacent coins is allowed to be flipped over at same time. All ten coins that are head is the goal. The puzzle is inspired by brilliant.org.
More examples will be added in future.
The project currently targets .NET Core and .NET Framework 4.5 or above.