static void eightPuzzleAStarDemo() { System.Console.WriteLine("\nEightPuzzleDemo AStar Search (MisplacedTileHeursitic)-->"); try { IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(random1); ISearchForActions <EightPuzzleBoard, IAction> search = new AStarSearch <EightPuzzleBoard, IAction>( new GraphSearch <EightPuzzleBoard, IAction>(), EightPuzzleFunctions.createMisplacedTileHeuristicFunction()); SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { throw e; } }
public void testHeuristicCalculation() { IToDoubleFunction <Node <EightPuzzleBoard, IAction> > h = EightPuzzleFunctions.createMisplacedTileHeuristicFunction(); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 2, 0, 5, 6, 4, 8, 3, 7, 1 }); Assert.AreEqual(6.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 0, 7, 1 }); Assert.AreEqual(5.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 7, 0, 1 }); Assert.AreEqual(6.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 8, 1, 2, 3, 4, 5, 6, 7, 0 }); Assert.AreEqual(1.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); Assert.AreEqual(0.0, h.applyAsDouble(new Node <EightPuzzleBoard, IAction>(board)), 0.001); }