class Pacman::Coordinate

Represent position in grid

Attributes

x[RW]
y[RW]

Public Class Methods

new(x, y) click to toggle source
# File lib/pacman/Coordinate.rb, line 6
def initialize(x, y)
  @x = x
  @y = y
end

Public Instance Methods

distance(coord) click to toggle source

manhatan

# File lib/pacman/Coordinate.rb, line 33
def distance(coord)
  x = @x - coord.x
  y = @y - coord.y
  x.abs + y.abs
end
get_direction(coord) click to toggle source
# File lib/pacman/Coordinate.rb, line 22
def get_direction(coord)
  res = UNDEF

  res = LEFT if @x > coord.x
  res = RIGHT if @x < coord.x
  res = UP if @y > coord.y
  res = DOWN if @y < coord.y
  res
end
neighbor(direction) click to toggle source
# File lib/pacman/Coordinate.rb, line 11
def neighbor(direction)
  x = @x
  y = @y
  x -= 1 if direction == LEFT
  x += 1 if direction == RIGHT
  y -= 1 if direction == UP
  y += 1 if direction == DOWN

  Coordinate.new(x, y)
end