Class: Point

Inherits:
Object
  • Object
show all
Defined in:
lib/codenjoy/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Coords (1,1) - upper left side of field

Parameters:

  • x (Integer)

    X coord

  • y (Integer)

    Y coord



9
10
11
12
# File 'lib/codenjoy/utils.rb', line 9

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

Instance Attribute Details

#xObject

Returns the value of attribute x.



2
3
4
# File 'lib/codenjoy/utils.rb', line 2

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/codenjoy/utils.rb', line 3

def y
  @y
end

Instance Method Details

#==(other_object) ⇒ Object

Override of compare method for Point



15
16
17
# File 'lib/codenjoy/utils.rb', line 15

def == (other_object)
  other_object.x == @x && other_object.y == @y
end

#downObject

Position of point below current



30
31
32
# File 'lib/codenjoy/utils.rb', line 30

def down
  Point.new(@x, @y - 1)
end

#leftObject

Position of point on the left side



35
36
37
# File 'lib/codenjoy/utils.rb', line 35

def left
  Point.new(@x - 1, @y)
end

#out_of?(board_size) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/codenjoy/utils.rb', line 44

def out_of?(board_size)
  x >= board_size || y >= board_size || x < 0 || y < 0;
end

#rightObject

Position of point on the right side



40
41
42
# File 'lib/codenjoy/utils.rb', line 40

def right
  Point.new(@x + 1, @y)
end

#to_sObject

For better .inspect output



20
21
22
# File 'lib/codenjoy/utils.rb', line 20

def to_s
  "[#{@x},#{@y}]"
end

#upObject

Position of point above current



25
26
27
# File 'lib/codenjoy/utils.rb', line 25

def up
  Point.new(@x, @y + 1)
end