class Gobstones::Runner::Board

Attributes

columns[R]
rows[R]

Public Class Methods

new(rows_num, cols_num, matrix = []) click to toggle source
# File lib/gobstones/runner/board.rb, line 8
def initialize(rows_num, cols_num, matrix = [])
  @rows = rows_num
  @columns = cols_num
  if matrix.empty?
    @matrix = []
    rows_num.times do
      @matrix << []
      cols_num.times { @matrix.last << Cell.new }
    end
  else
    @matrix = matrix
  end
end

Public Instance Methods

are_there_balls?(x, y, color) click to toggle source
# File lib/gobstones/runner/board.rb, line 40
def are_there_balls?(x, y, color)
  cell_at(x, y).are_there_balls?(color)
end
cell_at(x, y) click to toggle source
# File lib/gobstones/runner/board.rb, line 22
def cell_at(x, y)
  raise OutOfBoardError unless x.between?(0, rows - 1) && y.between?(0, columns - 1)

  @matrix[x][y]
end
clone() click to toggle source
# File lib/gobstones/runner/board.rb, line 57
def clone
  new_matrix = @matrix.map { |row| row.map(&:clone) }
  self.class.new(rows, columns, new_matrix)
end
each_cell() { |cell| ... } click to toggle source
# File lib/gobstones/runner/board.rb, line 28
def each_cell
  @matrix.each { |row| row.each { |cell| yield(cell) } }
end
empty!() click to toggle source
# File lib/gobstones/runner/board.rb, line 48
def empty!
  each_cell(&:empty!)
end
empty?() click to toggle source
# File lib/gobstones/runner/board.rb, line 52
def empty?
  each_cell { |cell| return false unless cell.empty? }
  true
end
number_of_balls(x, y, color) click to toggle source
# File lib/gobstones/runner/board.rb, line 44
def number_of_balls(x, y, color)
  cell_at(x, y).number_of_balls(color)
end
put(x, y, color) click to toggle source
# File lib/gobstones/runner/board.rb, line 32
def put(x, y, color)
  cell_at(x, y).put(color)
end
take_out(x, y, color) click to toggle source
# File lib/gobstones/runner/board.rb, line 36
def take_out(x, y, color)
  cell_at(x, y).take_out(color)
end