Class: MazeSolver::Element
- Inherits:
-
Object
- Object
- MazeSolver::Element
- Defined in:
- lib/maze_solver/element.rb
Instance Attribute Summary collapse
-
#f ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited.
-
#g ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited.
-
#h ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited.
-
#parent ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(element) ⇒ Object
-
#initialize(value, position, type) ⇒ Element
constructor
A new instance of Element.
- #is_goal? ⇒ Boolean
- #is_path? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(value, position, type) ⇒ Element
Returns a new instance of Element.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/maze_solver/element.rb', line 22 def initialize(value, position, type) @value = value @position = position @type = type ## Default Astar values @g = 0 @h = 0 @f = 0 @parent = nil end |
Instance Attribute Details
#f ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited
8 9 10 |
# File 'lib/maze_solver/element.rb', line 8 def f @f end |
#g ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited
8 9 10 |
# File 'lib/maze_solver/element.rb', line 8 def g @g end |
#h ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited
8 9 10 |
# File 'lib/maze_solver/element.rb', line 8 def h @h end |
#parent ⇒ Object
Represent an element in the Maze, defined by his position and value There are also some Astar factors like g, h, f functions Also the precedent element, (parent) visited is a flag that aknowledge that the element had been visited
8 9 10 |
# File 'lib/maze_solver/element.rb', line 8 def parent @parent end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
9 10 11 |
# File 'lib/maze_solver/element.rb', line 9 def position @position end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/maze_solver/element.rb', line 9 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/maze_solver/element.rb', line 9 def value @value end |
Instance Method Details
#==(element) ⇒ Object
16 17 18 19 20 |
# File 'lib/maze_solver/element.rb', line 16 def ==(element) ## Compare two elements by its position return true if ( @position == element.position && @value == element.value && @type == element.type ) return false end |
#is_goal? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/maze_solver/element.rb', line 34 def is_goal? ## is the end point? return true if @type == 'GOAL' false end |
#is_path? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/maze_solver/element.rb', line 40 def is_path? ## Can be traversed? return true if ( @type == 'PATH' || @type == 'START' || @type == 'GOAL' ) false end |
#to_s ⇒ Object
11 12 13 14 |
# File 'lib/maze_solver/element.rb', line 11 def to_s ## Represent the class "(#{@position}), #{@value}" end |