summaryrefslogtreecommitdiffstats
path: root/Algorithms/Part-I/4-Puzzle/Solver.java
diff options
context:
space:
mode:
Diffstat (limited to 'Algorithms/Part-I/4-Puzzle/Solver.java')
-rw-r--r--Algorithms/Part-I/4-Puzzle/Solver.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/Algorithms/Part-I/4-Puzzle/Solver.java b/Algorithms/Part-I/4-Puzzle/Solver.java
new file mode 100644
index 0000000..1f96098
--- /dev/null
+++ b/Algorithms/Part-I/4-Puzzle/Solver.java
@@ -0,0 +1,53 @@
+/* vim: set expandtab tabstop=4 shiftwidth=4 : */
+
+public class Solver {
+
+ // find a solution to the initial board (using the A* algorithm)
+ public Solver(Board initial)
+ {
+ // use MinPQ
+ }
+
+ // is the initial board solvable?
+ public boolean isSolvable()
+ {
+ return false;
+ }
+
+ // min number of moves to solve initial board; -1 if no solution
+ public int moves()
+ {
+ return 0;
+ }
+
+ // sequence of boards in a shortest solution; null if no solution
+ public Iterable<Board> solution()
+ {
+ return null;
+ }
+
+ // solve a slider puzzle (given below)
+ public static void main(String[] args)
+ {
+ // create initial board from file
+ In in = new In(args[0]);
+ int N = in.readInt();
+ int[][] blocks = new int[N][N];
+ for (int i = 0; i < N; i++)
+ for (int j = 0; j < N; j++)
+ blocks[i][j] = in.readInt();
+ Board initial = new Board(blocks);
+
+ // solve the puzzle
+ Solver solver = new Solver(initial);
+
+ // print solution to standard output
+ if (!solver.isSolvable())
+ StdOut.println("No solution possible");
+ else {
+ StdOut.println("Minimum number of moves = " + solver.moves());
+ for (Board board : solver.solution())
+ StdOut.println(board);
+ }
+ }
+}