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
(→‎{{header|Java}}: lang tag; whitespace)
(→‎{{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,026:
 
import java.util.Random;
import java.util.Collections;
import java.util.Arrays;
 
/*
Line 1,067 ⟶ 1,069:
 
private void generateMaze(int cx, int cy) {
for (DIR dir : randomize(new DIR[] {dirs DIR.N,= DIR.S, DIR.W, DIR.E }values()) {;
Collections.shuffle(Arrays.asList(dirs));
for (DIR dir : dirs) {
int nx = cx + dir.dx;
int ny = cy + dir.dy;
Line 1,079 ⟶ 1,083:
}
 
private static boolean between(int v, int upper) {
return (v >= 0) && (v < upper);
}
 
private DIR[] randomize(DIR[] list) {
for (int i = 0; i < list.length; i++) {
int r = rand.nextInt(list.length);
DIR t = list[i];
list[i] = list[r];
list[r] = t;
}
return list;
}
 
Anonymous user