Maze generation: Difference between revisions

(→‎{{header|Java}}: randomize() was not a correct shuffle (http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Implementation_errors), plus shuffle is already in library)
Line 1,035:
*/
public class MazeGenerator {
private final int x;
private final int y;
private final int[][] maze;
private static final Random rand = new Random(System.currentTimeMillis());
 
public MazeGenerator(int x, int y) {
Line 1,051:
// draw the north edge
for (int j = 0; j < x; j++) {
System.out.print(((maze[j][i] & 1) == 0) ? "+---" : "+ ");
}
System.out.println("+");
// draw the west edge
for (int j = 0; j < x; j++) {
System.out.print(String.format(maze[j][i] & 8) == 0 ? "%s| " : " ",);
((maze[j][i] & 8) == 0 ? "|" : " "), maze[j][i]));
}
System.out.println("|");
Line 1,074 ⟶ 1,073:
int nx = cx + dir.dx;
int ny = cy + dir.dy;
if (between(nx, maze.lengthx) && between(ny, maze[0].lengthy)
&& (maze[nx][ny] == 0)) {
maze[cx][cy] |= dir.bit;
Line 1,089 ⟶ 1,088:
private enum DIR {
N(1, 0, -1), S(2, 0, 1), E(4, 1, 0), W(8, -1, 0);
private final int bit;
private final int dx;
private final int dy;
private DIR opposite;
 
Anonymous user