private static void Main(string[] args) { int[] board1 = { 0, 1, -1, 2, 5, 6, 10, 3, 4, 8, 11, 7, 12, 9, 13, 14 }; Node init1 = new Node(board1, 4, 4, 0, NPuzzle.Operator.Root); NPuzzle puzz1 = new NPuzzle(init1); //Data 3 puzz1.SolveWithAStar(1); puzz1.PrintSolution(); int[] board2 = { 0, 1, 2, 3, 11, 12, 13, 4, 10, -1, 14, 5, 9, 8, 7, 6 }; Node init2 = new Node(board2, 4, 4, 0, NPuzzle.Operator.Root); NPuzzle puzz2 = new NPuzzle(init2); //Data 1: spiral puzz2.SolveWithAStar(1); puzz2.PrintSolution(); int[] board3 = { -1, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; Node init3 = new Node(board3, 4, 4, 0, NPuzzle.Operator.Root); NPuzzle puzz3 = new NPuzzle(init3); //Data 2: backward //0 causes A* to act like BestFirst. This is done because A* takes longer than the heat death of the universe to complete with large problems. puzz3.SolveWithAStar(0); puzz3.PrintSolution(); Console.WriteLine("\n\n\nDone. Press 'Enter' to terminate."); Console.ReadLine(); }
/// <summary> /// /// </summary> /// <param name="boardArry">Make this 0 based indexed. -1 is the blank.</param> /// <param name="rows">1 indexed based</param> /// <param name="colums">1 indexed based</param> public Node(int[] boardArry, int rows, int colums, int currentDistance, NPuzzle.Operator previousOp) { this.rows = rows; this.columns = colums; state = boardArry; heuristic = NPuzzle.FindHeuristic(this); distance = currentDistance; appliedOp = previousOp; }