Class: Stones::Board
- Inherits:
-
Object
- Object
- Stones::Board
- Includes:
- WithHead, WithStones
- Defined in:
- lib/stones/board.rb
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#head_position ⇒ Object
readonly
Returns the value of attribute head_position.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(cells, position) ⇒ Board
constructor
A new instance of Board.
- #size ⇒ Object
Methods included from WithStones
#clear!, #count, #exist?, #pop!, #push!
Methods included from WithHead
#can_move?, #move!, #move_to_edge!
Constructor Details
#initialize(cells, position) ⇒ Board
Returns a new instance of Board.
14 15 16 17 |
# File 'lib/stones/board.rb', line 14 def initialize(cells, position) @cells = cells @head_position = position end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
12 13 14 |
# File 'lib/stones/board.rb', line 12 def cells @cells end |
#head_position ⇒ Object (readonly)
Returns the value of attribute head_position.
12 13 14 |
# File 'lib/stones/board.rb', line 12 def head_position @head_position end |
Class Method Details
.empty(x, y, position = [0, 0]) ⇒ Object
33 34 35 |
# File 'lib/stones/board.rb', line 33 def self.empty(x, y, position=[0, 0]) self.new(empty_cells(x, y), position) end |
.from(cells, position = [0, 0]) ⇒ Object
37 38 39 |
# File 'lib/stones/board.rb', line 37 def self.from(cells, position=[0, 0]) self.new(cells.map { |row| row.map { |cell| empty_cell.merge(cell) } }, position) end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/stones/board.rb', line 23 def ==(other) self.class == other.class && self.cells == other.cells && self.head_position == other.head_position end |
#hash ⇒ Object
29 30 31 |
# File 'lib/stones/board.rb', line 29 def hash self.cells.hash ^ self.head_position.hash end |
#size ⇒ Object
19 20 21 |
# File 'lib/stones/board.rb', line 19 def size [cells[0].size, cells.size] end |