Class: JustGo::Point
- Inherits:
-
Object
- Object
- JustGo::Point
- Defined in:
- lib/just_go/point.rb
Overview
Point
A Point on a go board
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#stone ⇒ Object
readonly
Returns the value of attribute stone.
-
#territory_id ⇒ Object
readonly
Returns the value of attribute territory_id.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_to_territory(t_id) ⇒ Object
- #as_json ⇒ Object
- #capture_stone ⇒ Object
- #clear_territory ⇒ Object
-
#initialize(id:, x:, y:, stone:, territory_id: nil) ⇒ Point
constructor
A new instance of Point.
- #occupied? ⇒ Boolean
- #occupied_by?(player_number) ⇒ Boolean
- #occupied_by_opponent?(player_number) ⇒ Boolean
- #place(s) ⇒ Object
- #unmarked? ⇒ Boolean
- #unoccupied? ⇒ Boolean
Constructor Details
#initialize(id:, x:, y:, stone:, territory_id: nil) ⇒ Point
Returns a new instance of Point.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'lib/just_go/point.rb', line 26 def id @id end |
#stone ⇒ Object (readonly)
Returns the value of attribute stone.
29 30 31 |
# File 'lib/just_go/point.rb', line 29 def stone @stone end |
#territory_id ⇒ Object (readonly)
Returns the value of attribute territory_id.
30 31 32 |
# File 'lib/just_go/point.rb', line 30 def territory_id @territory_id end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
27 28 29 |
# File 'lib/just_go/point.rb', line 27 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
28 29 30 |
# File 'lib/just_go/point.rb', line 28 def y @y end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/just_go/point.rb', line 43 def ==(other) self.id == other.id end |
#add_to_territory(t_id) ⇒ Object
75 76 77 |
# File 'lib/just_go/point.rb', line 75 def add_to_territory(t_id) @territory_id = t_id end |
#as_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
71 72 73 |
# File 'lib/just_go/point.rb', line 71 def capture_stone @stone = nil end |
#clear_territory ⇒ Object
79 80 81 |
# File 'lib/just_go/point.rb', line 79 def clear_territory @territory_id = nil end |
#occupied? ⇒ Boolean
47 48 49 |
# File 'lib/just_go/point.rb', line 47 def occupied? !stone.nil? end |
#occupied_by?(player_number) ⇒ Boolean
55 56 57 |
# 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) ⇒ Boolean
59 60 61 |
# File 'lib/just_go/point.rb', line 59 def occupied_by_opponent?(player_number) !stone.nil? && stone.player_number != player_number end |
#place(s) ⇒ Object
67 68 69 |
# File 'lib/just_go/point.rb', line 67 def place(s) @stone = s end |
#unmarked? ⇒ Boolean
63 64 65 |
# File 'lib/just_go/point.rb', line 63 def unmarked? territory_id.nil? end |
#unoccupied? ⇒ Boolean
51 52 53 |
# File 'lib/just_go/point.rb', line 51 def unoccupied? stone.nil? end |