// runs all search algorithms for start and goal state private static void RunSingleSearch(PuzzleState initState, PuzzleState goalState) { var searcher = new Searcher(initState, goalState); // for 15-puzzle, cost from one state to next is always 1 CostFunc cost = (fromState, toState) => 1; // do each search on a separate thread to speed things up var searchThreads = new List <Thread> { new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(6).ToString())), new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(12).ToString())), new Thread(() => Console.WriteLine(searcher.DepthFirstSearch(18).ToString())), new Thread(() => Console.WriteLine(searcher.IterativeDeepeningDfs().ToString())), new Thread(() => Console.WriteLine(searcher.BreadthFirstSearch().ToString())), new Thread(() => Console.WriteLine(searcher.UniformCostSearch(cost).ToString())), new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new MyHeuristic()).ToString())), new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new MyHeuristic()).ToString())), new Thread(() => Console.WriteLine(searcher.GreedySearch(cost, new ManhattanDistanceHeuristic()).ToString())), new Thread(() => Console.WriteLine(searcher.AStarSearch(cost, new ManhattanDistanceHeuristic()).ToString())), }; // start all searches searchThreads.ForEach(x => x.Start()); // wait for all searches to complete searchThreads.ForEach(x => x.Join()); }