Class: Pathfinder
- Inherits:
-
Object
- Object
- Pathfinder
- Defined in:
- lib/gamefic-standard/pathfinder.rb
Instance Attribute Summary collapse
- #destination ⇒ Room readonly
- #origin ⇒ Room readonly
Instance Method Summary collapse
-
#initialize(origin, destination) ⇒ Pathfinder
constructor
A new instance of Pathfinder.
- #path ⇒ Array<Room>
- #valid? ⇒ Boolean
Constructor Details
#initialize(origin, destination) ⇒ Pathfinder
Returns a new instance of Pathfinder.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gamefic-standard/pathfinder.rb', line 14 def initialize origin, destination @origin = origin @destination = destination @path = nil @paths = [[@origin]] @visited = [] if @origin == @destination @path = [] else while @path.nil? && @paths.length > 0 end end |
Instance Attribute Details
#destination ⇒ Room (readonly)
12 13 14 |
# File 'lib/gamefic-standard/pathfinder.rb', line 12 def destination @destination end |
#origin ⇒ Room (readonly)
9 10 11 |
# File 'lib/gamefic-standard/pathfinder.rb', line 9 def origin @origin end |
Instance Method Details
#path ⇒ Array<Room>
28 29 30 31 32 |
# File 'lib/gamefic-standard/pathfinder.rb', line 28 def path # @path is nil if the path is invalid, but #path should return an empty # array instead. @path || [] end |
#valid? ⇒ Boolean
35 36 37 |
# File 'lib/gamefic-standard/pathfinder.rb', line 35 def valid? path.length > 0 || origin == destination end |