From 6a44b074f0169a1b0f9e92347af929c5e471746e Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 18 Apr 2015 13:44:44 +0200 Subject: Reorganised projects --- Week6 Sliding game solver/src/Main.java | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Week6 Sliding game solver/src/Main.java (limited to 'Week6 Sliding game solver/src/Main.java') diff --git a/Week6 Sliding game solver/src/Main.java b/Week6 Sliding game solver/src/Main.java new file mode 100644 index 0000000..4225013 --- /dev/null +++ b/Week6 Sliding game solver/src/Main.java @@ -0,0 +1,35 @@ +/** + * Solutions for the assignments of week 6. + * @author Camil Staps, s4498062 + */ +public class Main +{ + + /** + * Create a new sliding game, attempt to solve it and if it succeeds show a solution. + * @param args command-line arguments are ignored. + */ + public static void main(String[] args) { + // Some examples: + // N = 5 + //int[] x = {7,17,9,4,5,1,12,15,6,10,3,23,25,14,8,22,2,18,19,24,16,21,11,13,20}; // May take some time (that is, it did not find a solution after some hours here, I didn't check if there is one) + //int[] x = {2,4,6,8,10,1,3,5,7,9,12,14,16,18,20,11,13,15,17,19,21,22,23,24,25}; // Solution in 90 + // N = 4 + //int[] x = {2,3,10,11,14,1,13,15,5,4,8,7,6,12,9,16}; // Solution in 112 + //int[] x = {10,8,16,7,6,13,15,3,14,1,4,2,5,9,12,11}; // Solution in 144 + //int[] x = {9,12,5,4,2,16,7,11,3,6,10,13,14,1,8,15}; // Solution in 140 + // N = 3 + //int[] x = {8,7,6,5,4,3,1,2,9}; // No solution (evaluates 292102 different boards before failing) + int[] x = {5,9,3,4,6,2,8,7,1}; // Solution in 35 + + SlidingGame sg = new SlidingGame(x); + System.out.println("Solving:\n" + sg); + Solver s = new Solver(sg); + if (s.solve()) { + System.out.println("Success!"); + System.out.println(s.getWinner()); + } else { + System.out.println("Failure..."); + } + } +} -- cgit v1.2.3