Jump to content

Maze generation: Difference between revisions

m
→‎{{header|Tcl}}: Tinkering to add support for Maze Solution task
m (→‎{{header|Tcl}}: Tinkering to add support for Maze Solution task)
Line 285:
 
oo::class create maze {
variable x y horiz verti content
constructor {width height} {
set y $width
Line 292:
set n [expr {$x * $y - 1}]
if {$n < 0} {error "illegal maze dimensions"}
set horiz [set verti [lrepeat [expr {$x+1}] [lrepeat [expr {$y+1}] 0]]]
# This matrix holds the output for the Maze Solving task; not used for generation
set content [lrepeat $x [lrepeat $y " "]]
set unvisited [lrepeat [expr {$x+2}] [lrepeat [expr {$y+2}] 0]]
# Helper to write into a list of lists (with offsets)
Line 330 ⟶ 332:
}
}
 
rename unvisited= {}
}
 
Line 338 ⟶ 342:
set line {}
for {set k 0} {$k < $y*4+1} {incr k} {
if {$j%2 && ($k%4 || $k && idx($horiz, ($j-1)/==2, $k/4-1))} {
# At the centre of the cell, put the "content" of the cell
append line [expr {idx($content, $j/2, $k/4)}]
} elseif {$j%2 && ($k%4 || $k && idx($horiz, $j/2, $k/4-1))} {
append line " "
} elseif {$j%2} {
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.