Class: Gamefic::Standard::Pathfinder
- Inherits:
-
Object
- Object
- Gamefic::Standard::Pathfinder
- Defined in:
- lib/gamefic/standard/pathfinder.rb
Overview
Pathfinders provide the shortest route between two rooms. The destination needs to be accessible from the origin through portals. Note that Pathfinder does not take into account portals that characters should not be able to traverse, such as locked doors.
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>
An array of rooms starting with the first room after the origin and ending with the destination.
-
#valid? ⇒ Boolean
True if there is a valid path from the origin to the destination (or the origin and destination are the same room).
Constructor Details
#initialize(origin, destination) ⇒ Pathfinder
Returns a new instance of Pathfinder.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gamefic/standard/pathfinder.rb', line 19 def initialize(origin, destination) @origin = origin @destination = destination @visited = [] if origin == destination @path = [] else [[origin]] end end |
Instance Attribute Details
#destination ⇒ Room (readonly)
15 16 17 |
# File 'lib/gamefic/standard/pathfinder.rb', line 15 def destination @destination end |
#origin ⇒ Room (readonly)
12 13 14 |
# File 'lib/gamefic/standard/pathfinder.rb', line 12 def origin @origin end |
Instance Method Details
#path ⇒ Array<Room>
An array of rooms starting with the first room after the origin and ending with the destination.
The path will be empty if a path could not be found or the origin and destination are the same room.
37 38 39 |
# File 'lib/gamefic/standard/pathfinder.rb', line 37 def path @path || [] end |
#valid? ⇒ Boolean
True if there is a valid path from the origin to the destination (or the origin and destination are the same room).
44 45 46 |
# File 'lib/gamefic/standard/pathfinder.rb', line 44 def valid? !!@path end |