Class: MazePrim

Inherits:
Object
  • Object
show all
Includes:
MazeBase
Defined in:
lib/willb-mazegen/maze.rb

Overview

Prim algorithm maze generator

Instance Attribute Summary

Attributes included from MazeBase

#cg

Instance Method Summary collapse

Methods included from MazeBase

#closed_sides, #initialize, #size, #walls_for

Instance Method Details

#genObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/willb-mazegen/maze.rb', line 44

def gen
  reset
  while @walls.size > 0
    source,dest = @walls.delete_at(rand(@walls.size))
    unless @maze_cells.include? dest
      @maze_cells << dest
      @cg.add_edge(source=>dest)
      @walls = @walls + walls_for(dest)
    end
  end
end