Class: Rubykon::GroupTracker
- Inherits:
-
Object
- Object
- Rubykon::GroupTracker
- Defined in:
- lib/rubykon/group_tracker.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#stone_to_group ⇒ Object
readonly
Returns the value of attribute stone_to_group.
Instance Method Summary collapse
- #assign(identifier, color, board) ⇒ Object
- #dup ⇒ Object
- #group(id) ⇒ Object
- #group_id_of(identifier) ⇒ Object
- #group_of(identifier) ⇒ Object
-
#initialize(groups = {}, stone_to_group = {}) ⇒ GroupTracker
constructor
A new instance of GroupTracker.
- #liberty_count_at(identifier) ⇒ Object
- #stone_joins_group(stone_identifier, group_identifier) ⇒ Object
Constructor Details
#initialize(groups = {}, stone_to_group = {}) ⇒ GroupTracker
Returns a new instance of GroupTracker.
6 7 8 9 |
# File 'lib/rubykon/group_tracker.rb', line 6 def initialize(groups = {}, stone_to_group = {}) @groups = groups @stone_to_group = stone_to_group end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
4 5 6 |
# File 'lib/rubykon/group_tracker.rb', line 4 def groups @groups end |
#stone_to_group ⇒ Object (readonly)
Returns the value of attribute stone_to_group.
4 5 6 |
# File 'lib/rubykon/group_tracker.rb', line 4 def stone_to_group @stone_to_group end |
Instance Method Details
#assign(identifier, color, board) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rubykon/group_tracker.rb', line 11 def assign(identifier, color, board) neighbours_by_color = color_to_neighbour(board, identifier) join_group_of_friendly_stones(neighbours_by_color[color], identifier) create_own_group(identifier) unless group_id_of(identifier) add_liberties(neighbours_by_color[Board::EMPTY], identifier) take_liberties_of_enemies(neighbours_by_color[Game.other_color(color)], identifier, board, color) end |
#dup ⇒ Object
39 40 41 |
# File 'lib/rubykon/group_tracker.rb', line 39 def dup self.class.new(dup_groups, @stone_to_group.dup) end |
#group(id) ⇒ Object
31 32 33 |
# File 'lib/rubykon/group_tracker.rb', line 31 def group(id) @groups[id] end |
#group_id_of(identifier) ⇒ Object
23 24 25 |
# File 'lib/rubykon/group_tracker.rb', line 23 def group_id_of(identifier) @stone_to_group[identifier] end |
#group_of(identifier) ⇒ Object
27 28 29 |
# File 'lib/rubykon/group_tracker.rb', line 27 def group_of(identifier) group(group_id_of(identifier)) end |
#liberty_count_at(identifier) ⇒ Object
19 20 21 |
# File 'lib/rubykon/group_tracker.rb', line 19 def liberty_count_at(identifier) group_of(identifier).liberty_count end |
#stone_joins_group(stone_identifier, group_identifier) ⇒ Object
35 36 37 |
# File 'lib/rubykon/group_tracker.rb', line 35 def stone_joins_group(stone_identifier, group_identifier) @stone_to_group[stone_identifier] = group_identifier end |