class JustGo::Point

Point

A Point on a go board

Attributes

id[R]
stone[R]
territory_id[R]
x[R]
y[R]

Public Class Methods

new(id: , x: , y: , stone: , territory_id: nil) click to toggle source
# File lib/just_go/point.rb, line 9
def initialize(id: , x: , y: , stone: , territory_id: nil)
  @id = id
  @x = x
  @y = y
  @stone = case stone
    when JustGo::Stone
      stone
    when Hash
      JustGo::Stone.new(**stone)
    when nil 
      stone
    else
      raise ArgumentError, "stone must be Stone, Hash or nil"
    end
  @territory_id = territory_id
end

Public Instance Methods

==(other) click to toggle source
# File lib/just_go/point.rb, line 43
def ==(other)
  self.id == other.id
end
add_to_territory(t_id) click to toggle source
# File lib/just_go/point.rb, line 75
def add_to_territory(t_id)
  @territory_id = t_id
end
as_json() click to toggle source
# File lib/just_go/point.rb, line 32
def as_json
  _stone = stone ? stone.as_json : nil
  {
    id: id,
    x: x,
    y: y,
    stone: _stone,
    territory_id: territory_id
  }
end
capture_stone() click to toggle source
# File lib/just_go/point.rb, line 71
def capture_stone
  @stone = nil
end
clear_territory() click to toggle source
# File lib/just_go/point.rb, line 79
def clear_territory
  @territory_id = nil
end
occupied?() click to toggle source
# File lib/just_go/point.rb, line 47
def occupied?
  !stone.nil?
end
occupied_by?(player_number) click to toggle source
# File lib/just_go/point.rb, line 55
def occupied_by?(player_number)
  !stone.nil? && stone.player_number == player_number
end
occupied_by_opponent?(player_number) click to toggle source
# File lib/just_go/point.rb, line 59
def occupied_by_opponent?(player_number)
  !stone.nil? && stone.player_number != player_number
end
place(s) click to toggle source
# File lib/just_go/point.rb, line 67
def place(s)
  @stone = s
end
unmarked?() click to toggle source
# File lib/just_go/point.rb, line 63
def unmarked?
  territory_id.nil?
end
unoccupied?() click to toggle source
# File lib/just_go/point.rb, line 51
def unoccupied?
  stone.nil?
end