Class: Theseus::SigmaMaze

Inherits:
Maze
  • Object
show all
Defined in:
lib/theseus/sigma_maze.rb

Overview

A “sigma” maze is one in which the field is tesselated into hexagons. Trying to map such a field onto a two-dimensional grid is a little tricky; Theseus does so by treating a single row as the hexagon in the first column, then the hexagon below and to the right, then the next hexagon above and to the right (on a line with the first hexagon), and so forth. For example, the following grid consists of two rows of 8 cells each:

 _   _   _   _
/ \_/ \_/ \_/ \_
\_/ \_/ \_/ \_/ \ 
/ \_/ \_/ \_/ \_/ 
\_/ \_/ \_/ \_/ \ 
  \_/ \_/ \_/ \_/

SigmaMaze supports weaving, but not symmetry (yet).

maze = Theseus::SigmaMaze.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

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, #initialize, #inspect, #move, #new_path, #new_solver, #opposite, #relative_direction, #row_length, #solve, #sparsify!, #start, #step, #to, #to_s, #type, #valid?, #vmirror, #wrap_x?, #wrap_y?

Constructor Details

This class inherits a constructor from Theseus::Maze

Instance Method Details

#potential_exits_at(x, y) ⇒ Object

Because of how the cells are positioned relative to other cells in the same row, the definition of the diagonal walls changes depending on whether a cell is “shifted” (e.g. moved down a half-row) or not.

  ____        ____
 / N  \      /
/NW  NE\____/
\W    E/ N  \
 \_S__/W    E\____
      \SW  SE/
       \_S__/

Thus, if a cell is shifted, W/E are in the upper diagonals, otherwise they are in the lower diagonals. It is important that W/E always point to cells in the same row, so that the #dx and #dy methods do not need to be overridden.

This change actually makes it fairly easy to generalize the other operations, although weaving needs special attention (see #weave_allowed? and #perform_weave).



44
45
46
47
# File 'lib/theseus/sigma_maze.rb', line 44

def potential_exits_at(x, y) #:nodoc:
  [N, S, E, W] + 
    ((x % 2 == 0) ? [NW, NE] : [SW, SE])
end