lundi 4 avril 2016

Create a maze with predefined start/end locations (Python)

I've been trying, to no avail, to find a way to create a maze with predefined starting and ending locations. So far, I have a function that creates a maze from a matrix. This function works by reading in files.

Now, i'd like to prompt the user to enter a number, 'N', from 5 to 20 for a maze size, then randomly generate the matrix to pass to my function (rather than a file).

For visualization, a 2x2 matrix would look something like the below. Each '1' is a wall, and each '0' is a path. The algorithm would be (N*2 + 1) to get the width of the matrix.

          1 1 1 1 1
 Start -> 0 0 1 1 1
          1 0 0 0 1
          1 0 1 0 0 <- End
          1 1 1 1 1

The start always has to be at location "Matrix[0][1]" and the end will always be at "Matrix[N-1][N-2]"

If you have a solution to this in Java i'd be more than happy to see that as well. I'm using Python 3 for the record.




Aucun commentaire:

Enregistrer un commentaire