summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-04-21 22:03:18 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-04-21 22:03:18 +0200
commit9b0f17494440f3d5d2f711a2fd20c2ca8970db21 (patch)
treecafa1f85475d583859698a3065aea3bdc262d543
parent811e453013ec548a3750c1fcb39f36fd4cd77dcf (diff)
Improve speed by 30000%
-rw-r--r--main.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/main.rb b/main.rb
index 57f4889..0d7591d 100644
--- a/main.rb
+++ b/main.rb
@@ -6,6 +6,7 @@ class MazeGenerator
def initialize(width, height)
@maze = Maze.new(width, height)
+ @visitedTiles = Array.new(width) { Array.new(height) { false } }
end
def generate()
@@ -20,7 +21,7 @@ class MazeGenerator
def step()
neighbors = @maze.neighbors(@stack.last)
neighbors.select! do |neighbor|
- !@visitedCells.include? neighbor
+ @visitedTiles[neighbor.x][neighbor.y] == false
end
if neighbors.empty?
@@ -31,7 +32,7 @@ class MazeGenerator
@maze.set(@stack.last, randomNeighbor.dir_from(@stack.last), false)
@stack.push(randomNeighbor)
- @visitedCells.push(randomNeighbor)
+ @visitedTiles[randomNeighbor.x][randomNeighbor.y] = true
end
end
end