diff --git a/src/algorithms/aldous_broder.coffee b/src/algorithms/aldous_broder.coffee index d4f74ca..8d83639 100644 --- a/src/algorithms/aldous_broder.coffee +++ b/src/algorithms/aldous_broder.coffee @@ -23,8 +23,11 @@ class Maze.Algorithms.AldousBroder extends Maze.Algorithm @updateAt @x, @y @remaining-- @state = 1 + @carvedOnLastStep = true runStep: -> + carved = false + if @remaining > 0 for dir in @rand.randomDirections() nx = @x + Maze.Direction.dx[dir] @@ -37,6 +40,7 @@ class Maze.Algorithms.AldousBroder extends Maze.Algorithm @maze.carve x, y, dir @maze.carve @x, @y, Maze.Direction.opposite[dir] @remaining-- + carved = true if @remaining == 0 delete @x @@ -47,6 +51,9 @@ class Maze.Algorithms.AldousBroder extends Maze.Algorithm break + @eventAt @x, @y if carved != @carvedOnLastStep + @carvedOnLastStep = carved + return @remaining > 0 step: -> diff --git a/src/algorithms/backtracker.coffee b/src/algorithms/backtracker.coffee index 765b947..799b61c 100644 --- a/src/algorithms/backtracker.coffee +++ b/src/algorithms/backtracker.coffee @@ -32,6 +32,7 @@ class Maze.Algorithms.RecursiveBacktracker extends Maze.Algorithm @updateAt x, y @stack.push x: x, y: y, dirs: @rand.randomDirections() @state = @RUN + @carvedOnLastStep = true runStep: -> loop @@ -48,12 +49,16 @@ class Maze.Algorithms.RecursiveBacktracker extends Maze.Algorithm @maze.carve nx, ny, Maze.Direction.opposite[dir] | @STACK @updateAt nx, ny + @eventAt nx, ny unless @carvedOnLastStep + @carvedOnLastStep = true break if current.dirs.length == 0 @maze.uncarve current.x, current.y, @STACK @updateAt current.x, current.y + @eventAt current.x, current.y if @carvedOnLastStep @stack.pop() + @carvedOnLastStep = false break @state = @DONE if @stack.length == 0 diff --git a/src/algorithms/binary_tree.coffee b/src/algorithms/binary_tree.coffee index 95a5192..6cb08f7 100644 --- a/src/algorithms/binary_tree.coffee +++ b/src/algorithms/binary_tree.coffee @@ -39,5 +39,6 @@ class Maze.Algorithms.BinaryTree extends Maze.Algorithm if @x >= @maze.width @x = 0 @y++ + @eventAt @x, @y return @y < @maze.height diff --git a/src/algorithms/eller.coffee b/src/algorithms/eller.coffee index 8243762..f4c3996 100644 --- a/src/algorithms/eller.coffee +++ b/src/algorithms/eller.coffee @@ -62,6 +62,7 @@ class Maze.Algorithms.Eller extends Maze.Algorithm @mode = @VERTICAL @next_state = @state.next() @verticals = @computeVerticals() + @eventAt 0, @row computeVerticals: -> verts = [] @@ -88,6 +89,7 @@ class Maze.Algorithms.Eller extends Maze.Algorithm @state = @next_state.populate() @row += 1 @initializeRow() + @eventAt 0, @row step: -> switch @mode diff --git a/src/algorithms/houston.coffee b/src/algorithms/houston.coffee index a79ab5d..aefa30c 100644 --- a/src/algorithms/houston.coffee +++ b/src/algorithms/houston.coffee @@ -38,6 +38,7 @@ class Maze.Algorithms.Houston extends Maze.Algorithm delete @worker.x delete @worker.y @updateAt x, y + @eventAt x, y # switch to wilsons and redefine the step method so it # no longer watches the threshold. diff --git a/src/algorithms/hunt_and_kill.coffee b/src/algorithms/hunt_and_kill.coffee index 6cd496a..67058b3 100644 --- a/src/algorithms/hunt_and_kill.coffee +++ b/src/algorithms/hunt_and_kill.coffee @@ -45,6 +45,7 @@ class Maze.Algorithms.HuntAndKill extends Maze.Algorithm delete @x delete @y @updateAt x, y # remove highlight from current cell + @eventAt x, y @y = 0 @callbackRow 0 # highlight the first row @state = 2 @@ -75,6 +76,7 @@ class Maze.Algorithms.HuntAndKill extends Maze.Algorithm # clear highlight in row (because we set @x) and update passages at @x, @y @callbackRow @y + @eventAt nx, ny return diff --git a/src/algorithms/sidewinder.coffee b/src/algorithms/sidewinder.coffee index 4644a63..313c7a5 100644 --- a/src/algorithms/sidewinder.coffee +++ b/src/algorithms/sidewinder.coffee @@ -28,6 +28,7 @@ class Maze.Algorithms.Sidewinder extends Maze.Algorithm @maze.carve cell, @y-1, Maze.Direction.S @updateAt cell, @y @updateAt cell, @y-1 + @eventAt @x, @y if @x - @runStart > 0 @runStart = @x + 1 else if @x+1 < @maze.width @maze.carve @x, @y, Maze.Direction.E diff --git a/src/algorithms/wilson.coffee b/src/algorithms/wilson.coffee index 9cc21ef..56673dd 100644 --- a/src/algorithms/wilson.coffee +++ b/src/algorithms/wilson.coffee @@ -36,6 +36,7 @@ class Maze.Algorithms.Wilson extends Maze.Algorithm @x = @rand.nextInteger(@maze.width) @y = @rand.nextInteger(@maze.height) if @maze.isBlank(@x, @y) + @eventAt @x, @y @state = 2 @start = x: @x, y: @y @addVisit @x, @y @@ -57,6 +58,7 @@ class Maze.Algorithms.Wilson extends Maze.Algorithm @x = @start.x @y = @start.y @state = 3 + @eventAt @x, @y break