Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/subparry_labyrinth_solver/node.rb

Overview

Class to represent a single labyrinth square or node

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ Node

Returns a new instance of Node.

Raises:



5
6
7
8
9
10
# File 'lib/subparry_labyrinth_solver/node.rb', line 5

def initialize(paths)
  raise MissingPathsError if paths[:up].nil? || paths[:down].nil? || paths[:left].nil? || paths[:right].nil?

  @paths = paths
  @cheese = paths[:cheese] || false
end

Instance Method Details

#cheese?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/subparry_labyrinth_solver/node.rb', line 16

def cheese?
  @cheese
end

#close(direction) ⇒ Object



20
21
22
# File 'lib/subparry_labyrinth_solver/node.rb', line 20

def close direction
  @paths[direction] = false
end

#open?(direction) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/subparry_labyrinth_solver/node.rb', line 12

def open? direction
  @paths[direction]
end