From 9b0f17494440f3d5d2f711a2fd20c2ca8970db21 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sat, 21 Apr 2018 22:03:18 +0200 Subject: Improve speed by 30000% --- main.rb | 5 +++-- 1 file 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 -- cgit v1.1