Class: Theseus::DeltaMaze
Overview
A “delta” maze is one in which the field is tesselated into triangles. Thus, each cell has three potential exits: east, west, and either north or south (depending on the orientation of the cell).
__ __ __
/\ /\ /\ /
/__\/__\/__\/
\ /\ /\ /\
\/__\/__\/__\
/\ /\ /\ /
/__\/__\/__\/
\ /\ /\ /\
\/__\/__\/__\
Delta mazes in Theseus do not support either weaving, or symmetry.
maze = Theseus::DeltaMaze.generate(width: 10)
puts maze
Constant Summary
Constants inherited from Maze
Maze::E, Maze::N, Maze::NE, Maze::NW, Maze::PRIMARY, Maze::RESERVED, Maze::S, Maze::SE, Maze::SW, Maze::UNDER, Maze::UNDER_SHIFT, Maze::W
Instance Attribute Summary
Attributes inherited from Maze
#algorithm, #braid, #entrance, #exit, #height, #mask, #randomness, #symmetry, #weave, #width, #wrap
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DeltaMaze
constructor
:nodoc:.
-
#points_up?(x, y) ⇒ Boolean
Returns
trueif the cell at (x,y) is oriented so the vertex is “up”, or north. -
#potential_exits_at(x, y) ⇒ Object
:nodoc:.
Methods inherited from Maze
#[], #[]=, #add_opening_from, #adjacent_point, #apply_move_at, #clockwise, #counter_clockwise, #dead?, #dead_ends, #dx, #dy, #finish, generate, #generate!, #generated?, #hmirror, #inspect, #move, #new_path, #new_solver, #opposite, #perform_weave, #relative_direction, #row_length, #solve, #sparsify!, #start, #step, #to, #to_s, #type, #valid?, #vmirror, #weave_allowed?, #wrap_x?, #wrap_y?
Constructor Details
#initialize(options = {}) ⇒ DeltaMaze
:nodoc:
24 25 26 27 |
# File 'lib/theseus/delta_maze.rb', line 24 def initialize(={}) #:nodoc: super raise ArgumentError, "weaving is not supported for delta mazes" if @weave > 0 end |
Instance Method Details
#points_up?(x, y) ⇒ Boolean
Returns true if the cell at (x,y) is oriented so the vertex is “up”, or north. Cells for which this returns true may have exits on the south border, and cells for which it returns false may have exits on the north.
32 33 34 |
# File 'lib/theseus/delta_maze.rb', line 32 def points_up?(x, y) (x + y) % 2 == height % 2 end |
#potential_exits_at(x, y) ⇒ Object
:nodoc:
36 37 38 39 40 41 42 43 |
# File 'lib/theseus/delta_maze.rb', line 36 def potential_exits_at(x, y) #:nodoc: vertical = points_up?(x, y) ? S : N # list the vertical direction twice. Otherwise the horizontal direction (E/W) # will be selected more often (66% of the time), resulting in mazes with a # horizontal bias. [vertical, vertical, E, W] end |