diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-04-21 22:03:18 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-04-21 22:03:18 +0200 |
commit | 9b0f17494440f3d5d2f711a2fd20c2ca8970db21 (patch) | |
tree | cafa1f85475d583859698a3065aea3bdc262d543 | |
parent | 811e453013ec548a3750c1fcb39f36fd4cd77dcf (diff) |
Improve speed by 30000%
-rw-r--r-- | main.rb | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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 |