Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/pathfinding/core/node.rb

Overview

Represents a node in the grid.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, walkable = true) ⇒ Node

Creates a node.



25
26
27
28
29
# File 'lib/pathfinding/core/node.rb', line 25

def initialize(x, y, walkable = true)
  @x = x
  @y = y
  @walkable = walkable
end

Instance Attribute Details

#walkableObject (readonly)

Gets whether the node is walkable.



20
21
22
# File 'lib/pathfinding/core/node.rb', line 20

def walkable
  @walkable
end

#xObject (readonly)

Gets the x coordinate in the grid.



14
15
16
# File 'lib/pathfinding/core/node.rb', line 14

def x
  @x
end

#yObject (readonly)

Gets the y coordinate in the grid.



17
18
19
# File 'lib/pathfinding/core/node.rb', line 17

def y
  @y
end

Instance Method Details

#to_sObject

Makes the string format of a node.



34
35
36
# File 'lib/pathfinding/core/node.rb', line 34

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