r/javahelp • u/uhmmmpp • Dec 06 '25
need help to code recursive division in java to create maze
helloo
i am a student in first year of computer science, and for my semester project i have to create a 2d game with mazes. i have to write an algorithm that creates mazes using the recursive division, and i have written this :
int [][] createMaze(int width , int height , int difficulty){
int[][] mazeToBe = new int[height][width];
//remplir le maze
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
mazeToBe[y][x] = 0;
}
}
int random = RandomGenerator.rng.nextInt(height);
int random2 = RandomGenerator.rng.nextInt(width);
for (int i = 0; i <=random2; i++) {
//faire la ligne
mazeToBe[random][i] = 1;
//faire un trou
mazeToBe[random][random2] = 0;
int [] randoms = new int [i];
for (int j = 0; j <= width; j++){
randoms[j] = RandomGenerator.rng.nextInt(j);
mazeToBe[random][j] = 1;
mazeToBe[random][randoms[j]] = 0;
}
}
printMaze(mazeToBe, new DiscreteCoordinates(0,0), new DiscreteCoordinates(width, height));
return mazeToBe;
}now, i am pretty sure i did something wrong, but i can't say where. can someone help me ?
1
Upvotes
View all comments
Show parent comment
1
u/uhmmmpp Dec 06 '25
hi, im gonna be honest, i understand how the recursive division works but i really have difficulty to put it into code :(