From 3f702ed231134d224ee5fd5525f627a8058909a1 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 13 Mar 2015 19:34:04 +0100 Subject: Solutions w6 --- Week6/src/Main.java | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'Week6/src/Main.java') diff --git a/Week6/src/Main.java b/Week6/src/Main.java index 9122749..4225013 100644 --- a/Week6/src/Main.java +++ b/Week6/src/Main.java @@ -1,16 +1,35 @@ /** - * - * @author Pieter Koopman, Sjaak Smetsers + * 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) { - int [] game = {1,2,3, 4,5,6, 7,9,8}; - - SlidingGame s = new SlidingGame (game); - System.out.println(s); -// Solver solver = new Solver(s); -// System.out.println(solver.solve()); + // 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