java - DFS Maze Generator -


I am currently working on a maze program that uses the first search in depth. I have the following code, but I do not know what I'm doing wrong. I am trying to say in the middle of X which walls are but I have written it on them, and putting the path ahead of each other Any help will be very good. Below is the output.

 . . ##### . . #. . . . . . . . . #. ### . #. #. . . #. . . #### ## . . . #. . . ## ## #. ##### . . #### . . . #Jav.util.Random; Import ####################################### Import Java.util.Random; Public class depthfish search (private stack stack; public DepthFirstSearch () {} public four [] [] DFS (integer shape, four [] [] maze) {random myRand = new random (stack); new stack; Int x = myRand.nextInt (size); while (x% 2 == 0) x = myRand.nextInt (size); int y = myRand.nextInt (size); while (y% 2 == 0) y = myRand .nextInt (size); maze [x] [y] = ''; integer = (size * size) / 4; int visited = 1; ink random [] = new int [4]; integer; while Visited & lt; Total) {totalrand = 0; if (X & gt; 1 and Maze [x - 2] [y] == 'X') Random [totalrand ++] = 1; If (x and lieutenant; shape - 2 & amp; maze [x + 2] [y] == ' X ') random [totalrand ++] = 2; if (y> 1 & amp; maze [x] [y - 2] ==' X ') random [totalrand ++] = 3; if (Y & lt; size - 2 & maze [x] [y + 2] == 'X') random [totalrand ++] = 4; if (totalrand> 0) {switch (random [myRand. NextInt (totalrand)]} {case 1: maze [x-2] [y] = maze [x-1] [y] = '; X - = 2; Stack.push (x * size + y); Visited ++; break; Case 2: Maze [x + 2] [y] = Maze [x + 1] [y] = ';; X + = 2; Stack.push (x * size + y); Visited ++; break; Case 3: Maze [x] [y-2] = Maze [x] [y-1] = '; Y - = 2; Stack.push (x * size + y); Visited ++; break; Case 4: Maze [x] [y + 2] = Maze [x] [y + 1] = '; Y + = 2; Stack.push (x * size + y); Visited ++; break; }} And {int vert = stack.pop (); X = hero / size; Y = Veerata% size; }} Return maze; }}    

As it turns out, it works perfectly Trying to be more efficient with its stack, and messed it up. So with a working pile, it works perfectly.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -