class Morchi::Board
The board class.
Attributes
size[R]
Property
Public Class Methods
new(num)
click to toggle source
Initialize.
# File lib/morchi/board.rb, line 12 def initialize(num) @size = num @range = 0..(@size - 1) clear end
Public Instance Methods
[](row, col)
click to toggle source
Get disk
# File lib/morchi/board.rb, line 19 def [](row, col) return false unless include?(row, col) @board[index(row, col)] end
[]=(row, col, value)
click to toggle source
Set disk
# File lib/morchi/board.rb, line 25 def []=(row, col, value) fail OutOfRangeError.new unless include?(row, col) @board[index(row, col)] = value end
clear()
click to toggle source
Clear.
# File lib/morchi/board.rb, line 31 def clear @board = Array.new(@size ** 2, Morchi::Disk.empty) end
full?()
click to toggle source
Query, is full?
# File lib/morchi/board.rb, line 36 def full? (@size ** 2).times do |index| return false if @board[index].empty? end true end
Private Instance Methods
include?(row, col)
click to toggle source
Is include?
# File lib/morchi/board.rb, line 46 def include?(row, col) @range.include?(row) && @range.include?(col) end
index(row, col)
click to toggle source
Get index.
# File lib/morchi/board.rb, line 51 def index(row, col) (row * @size) + col end