Jump to content

Maze generation: Difference between revisions

Line 3,459:
=={{header|Kotlin}}==
{{trans|Java}}
<lang scala>importclass shuffle.shuffleMazeGenerator(val x: Int, val y: Int) {
private val maze = Array(x) { IntArray(y) }
 
class Maze_generator(val x: Int, val y: Int) {
fun generate(cx: Int, cy: Int) {
arrayOf(*DIRDirection.values()).shuffle().forEach {
val nx = cx + it.dx
val ny = cy + it.dy
Line 3,492:
}
 
private enum class DIRDirection(val bit: Int, val dx: Int, val dy: Int) {
N(1, 0, -1), S(2, 0, 1), E(4, 1, 0),W(8, -1, 0);
 
var opposite: DIRDirection? = null
 
companion object {
Line 3,508:
 
private fun between(v: Int, upper: Int) = v >= 0 && v < upper
 
private val maze = Array(x) { IntArray(y) }
}
 
Line 3,515 ⟶ 3,513:
val x = if (args.size >= 1) args[0].toInt() else 8
val y = if (args.size == 2) args[1].toInt() else 8
with(Maze_generatorMazeGenerator(x, y)) {
generate(0, 0)
display()
Cookies help us deliver our services. By using our services, you agree to our use of cookies.