private BFSNode(PatternDatabase db, MiniBoard board, int empty_row, int empty_col, int distance, Direction direction) { this.db = db; this.empty_row = empty_row; this.empty_col = empty_col; this.board = board; this.distance = distance; this.direction = direction; }
public BFSNode(PatternDatabase db) // initial state --> the empty tile is in the bottom right corner { this.db = db; this.empty_row = db.rows - 1; this.empty_col = db.cols - 1; this.direction = Direction.NONE; this.board = new MiniBoard(db.rows, db.cols); this.distance = 0; }
static void Main() { // Read board dimensions Console.Write("Choose dimensions of the puzzle (type `3` for 3x3 or `4` for 4x4): "); int w = int.Parse(Console.ReadLine()), h = w; PuzzleType type; if (w == 3) { type = PuzzleType.PUZZLE_3x3; } else if (w == 4) { type = PuzzleType.PUZZLE_4x4; } else { Console.WriteLine("\nPuzzle {0:d}x{1:d} is not supported! Only 3x3 and 4x4 are supported.", w, h); return; } // // Read a board configuration from the standard input Console.WriteLine("\nEnter a configuration of the puzzle in the following format:"); Console.WriteLine(" --> 1 2 3 4 5 6 7 8 9"); int[,] board = new int[w, h]; int i = 0; foreach (string str in Regex.Split(Console.ReadLine(), "[ ]+")) { if (str.Trim() == string.Empty) { continue; } board[(i / w), (i % w)] = int.Parse(str); if ((++i) >= (w * h)) { break; } } // Initialize the Statically-Partitioned Additive Pattern Database Heuristic Console.Write("\nInitializing the Pattern Database..."); patternDB = new PatternDatabase(type); Console.WriteLine("done."); // Compute the solution Console.Write("\nSolving the puzzle..."); Solution solution = IDAStar(new Board(board)); Console.WriteLine("done.\n"); solution.PrintPath(); Console.WriteLine("\nPress any key to exit..."); Console.ReadKey(); }