class Gobstones::Board
Attributes
cells[R]
head_position[R]
size[R]
Public Class Methods
new(x, y)
click to toggle source
# File lib/gobstones/board.rb, line 9 def initialize(x, y) @size = [x, y] @cells = Hash.new(Cell.new) @head_position = Position.new(0, 0) end
Private Class Methods
includes_cells?(this, that)
click to toggle source
# File lib/gobstones/board.rb, line 51 def self.includes_cells?(this, that) this.cells.all? { |position, cell| that.cell_at(position) == cell } end
Public Instance Methods
==(other)
click to toggle source
# File lib/gobstones/board.rb, line 31 def ==(other) self.class === other && other.size == @size && all_cells_equal?(other) end
add_cell(position, cell)
click to toggle source
# File lib/gobstones/board.rb, line 15 def add_cell(position, cell) @cells[position] = cell self end
cell_at(position)
click to toggle source
# File lib/gobstones/board.rb, line 26 def cell_at(position) check_is_within_bounds position @cells[position] end
move_head_to(position)
click to toggle source
# File lib/gobstones/board.rb, line 20 def move_head_to(position) check_is_within_bounds position @head_position = position self end
Private Instance Methods
all_cells_equal?(other)
click to toggle source
# File lib/gobstones/board.rb, line 47 def all_cells_equal?(other) self.class.includes_cells?(self, other) && self.class.includes_cells?(other, self) end
check_is_within_bounds(position)
click to toggle source
# File lib/gobstones/board.rb, line 43 def check_is_within_bounds(position) raise OutOfBoardError unless within_bounds?(position) end
within_bounds?(position)
click to toggle source
# File lib/gobstones/board.rb, line 39 def within_bounds?(position) @size[0] > position.x && @size[1] > position.y end