Class: MazeSolver::Position
- Inherits:
-
Object
- Object
- MazeSolver::Position
- Defined in:
- lib/maze_solver/position.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Position Of Element in the maze (Cartesians)##.
-
#y ⇒ Object
readonly
Position Of Element in the maze (Cartesians)##.
Instance Method Summary collapse
- #==(position) ⇒ Object
- #east ⇒ Object
-
#initialize(x, y) ⇒ Position
constructor
A new instance of Position.
-
#north ⇒ Object
Adjacent position (In a Cartesian way) ##.
- #south ⇒ Object
- #to_s ⇒ Object
- #west ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Position
Returns a new instance of Position.
6 7 8 9 |
# File 'lib/maze_solver/position.rb', line 6 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Position Of Element in the maze (Cartesians)##
4 5 6 |
# File 'lib/maze_solver/position.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Position Of Element in the maze (Cartesians)##
4 5 6 |
# File 'lib/maze_solver/position.rb', line 4 def y @y end |
Instance Method Details
#==(position) ⇒ Object
11 12 13 14 |
# File 'lib/maze_solver/position.rb', line 11 def ==(position) ## Compare two positions ## @x == position.x && @y == position.y end |
#east ⇒ Object
26 27 28 |
# File 'lib/maze_solver/position.rb', line 26 def east Position.new(@x+1, @y) end |
#north ⇒ Object
Adjacent position (In a Cartesian way) ##
22 23 24 |
# File 'lib/maze_solver/position.rb', line 22 def north Position.new(@x, @y-1) end |
#south ⇒ Object
30 31 32 |
# File 'lib/maze_solver/position.rb', line 30 def south Position.new(@x, @y+1) end |
#to_s ⇒ Object
16 17 18 19 |
# File 'lib/maze_solver/position.rb', line 16 def to_s ## Represent a Position ## "(#{@x}, #{@y})" end |
#west ⇒ Object
34 35 36 |
# File 'lib/maze_solver/position.rb', line 34 def west Position.new(@x-1, @y) end |