Class: MazeSolver::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/maze_solver/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject (readonly)

Position Of Element in the maze (Cartesians)##



4
5
6
# File 'lib/maze_solver/position.rb', line 4

def x
  @x
end

#yObject (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

#eastObject



26
27
28
# File 'lib/maze_solver/position.rb', line 26

def east
  Position.new(@x+1, @y)
end

#northObject

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

#southObject



30
31
32
# File 'lib/maze_solver/position.rb', line 30

def south
  Position.new(@x, @y+1)
end

#to_sObject



16
17
18
19
# File 'lib/maze_solver/position.rb', line 16

def to_s
  ## Represent a Position ##
  "(#{@x}, #{@y})"
end

#westObject



34
35
36
# File 'lib/maze_solver/position.rb', line 34

def west
  Position.new(@x-1, @y)
end