class TictactoeJ8th::Board

Constants

BOARD_LINES
BOARD_SIZE

Attributes

board[RW]

Public Class Methods

from_s(string) click to toggle source

Public Class Methods

# File lib/tictactoe_j8th/board.rb, line 71
def self.from_s(string)
  board = Board.new
  (0..BOARD_SIZE-1).each do |i|
    board.place(string[i].to_sym, i) unless string[i] == 'E'
  end
  board
end
new() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 17
def initialize
  @board = Array.new(BOARD_SIZE)
end

Public Instance Methods

[](spot) click to toggle source
# File lib/tictactoe_j8th/board.rb, line 34
def [](spot)
  board[spot]
end
create_copy() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 54
def create_copy
  copy = Board.new
  copy.set_board(@board.dup)
  copy
end
empty?() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 21
def empty?
  board.all? { |value| value.nil? }
end
full?() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 29
def full?
  return false if board.include? nil
  true
end
lines() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 38
def lines
  array = []
  BOARD_LINES.each do |line|
    hash = {}
    line.each do |i|
      hash[i] = board[i]
    end
    array.push(hash)
  end
  array
end
place(item, position) click to toggle source
# File lib/tictactoe_j8th/board.rb, line 25
def place(item, position)
  board[position] = item if board[position].nil?
end
set_board(array) click to toggle source
# File lib/tictactoe_j8th/board.rb, line 50
def set_board(array)
  @board = array
end
to_s() click to toggle source
# File lib/tictactoe_j8th/board.rb, line 60
def to_s
  string = ''
  board.each do |spot|
    string += spot.nil? ? 'E' : spot.to_s
  end
  string
end