Class: Maze::Sigma

Inherits:
Generic show all
Defined in:
lib/maze/sigma.rb

Constant Summary collapse

OPPOSITE =
{ N => S, S => N, NE => SW, SW => NE, NW => SE, SE => NW }

Constants inherited from Generic

Generic::E, Generic::N, Generic::NE, Generic::NW, Generic::S, Generic::SE, Generic::SW, Generic::W

Instance Attribute Summary

Attributes inherited from Generic

#algorithm, #grid, #height, #width

Instance Method Summary collapse

Methods inherited from Generic

#[], #[]=, #connect, #connected?, #draw, #generate, #initialize, #tessellation

Constructor Details

This class inherits a constructor from Maze::Generic

Instance Method Details

#calculate_offset_x_axis(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/maze/sigma.rb', line 18

def calculate_offset_x_axis(*args)
  direction, point = args

  case direction
  when N, S
    0
  when NW, SW
    send("noexit_#{direction}?", point) ? 0 : -1
  when NE, SE
    send("noexit_#{direction}?", point) ? 0 : 1
  end
end

#calculate_offset_y_axis(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/maze/sigma.rb', line 31

def calculate_offset_y_axis(*args)
  direction, point = args

  case direction
  when N
    noexit_north?(point) ? 0 : -1
  when S
    noexit_south?(point) ? 0 : 1
  when NW, NE
    send("noexit_#{direction}?", point) || shifted_down?(point) ? 0 : -1
  when SW, SE
    send("noexit_#{direction}?", point) || shifted_up?(point) ? 0 : 1
  end
end

#opposite(direction) ⇒ Object



14
15
16
# File 'lib/maze/sigma.rb', line 14

def opposite(direction)
  OPPOSITE[direction]
end

#random_directionsObject Also known as: directions



8
9
10
# File 'lib/maze/sigma.rb', line 8

def random_directions
  [N, S, NE, NW, SE, SW].sort_by { rand }
end

#shifted_down?(point) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/maze/sigma.rb', line 50

def shifted_down?(point)
  !shifted_up?(point)
end

#shifted_up?(point) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/maze/sigma.rb', line 46

def shifted_up?(point)
  0 == point.x % 2
end