{{ message }}

Instantly share code, notes, and snippets.

# Feh/Labyrinth.java

Created Jun 15, 2011
Labyrinth
 /** * Assignment 9, exercise 3 * Class representing a labyrinth * Two constructors are already implemented, also a method to print out the labyrinth and its solution * * @author Lisa Julia Nebel Julius Plenz */ // TODO Take a look how this class works. // TODO Look at the docstrings, document your own functions // TODO Implement two functions to solve the Labyrinth. You will find the stubs below // (solve and solveRightHandRule) // TODO Implement the third constructor that generates a labyrinth with given size and given probability // test the solvability of 1000 labyrinths of size 10 by 10 with the parameters p=0.8 and p=0.9 // (p stands for the probability of any entry in the matrix being 1) public class Labyrinth{ int[][] labyrinth; // labyrinth as defined in the assignment int[][] solution; // solution to the labyrinth Boolean solved; // Is the labyrinth already solved? /** * Construct a Labyrinth with default size */ public Labyrinth(){ this.labyrinth=makeRandomLabyrinth(4,0.8); this.solved=false; } /** * Construct a Labyrinth with given size and given "1"-probability * Not yet implemented! */ public Labyrinth(int size, double p){ this.labyrinth = makeRandomLabyrinth(size,p); } public Labyrinth(int[][]labyrinth){ this.labyrinth=labyrinth; this.solved=false; } /** * @param labyrinth size and probability for "1" * * @return a labyrinth (int[][]) */ public static int[][] makeRandomLabyrinth(int size, double p){ int[][] labyrinth=new int[size][size]; for (int i1=0; i10){ labyrinth[i1-1][i2]=8; i1 = i1-1; } else if (labyrinth[i1+1][i2]==1 && (i1+1)0){ labyrinth[i1][i2-1]=8; i2 = i2-1; } else if (labyrinth[i1][i2+1]==1 && (i2+1)0){ i1 = i1-1; } else if (labyrinth[i1+1][i2]==8 && (i1+1)0){ i2 = i2-1; } else if (labyrinth[i1][i2+1]==8 && (i2+1)

### omartem commented Aug 1, 2017

 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at Labyrinth.solve(Labyrinth.java:88) at Labyrinth.main(Labyrinth.java:137)