class TicTacToe::Board

Public Class Methods

new() click to toggle source
# File lib/tic_tac_toe/board.rb, line 5
def initialize
  @board_positions = []
end

Public Instance Methods

columns() click to toggle source
# File lib/tic_tac_toe/board.rb, line 31
def columns
  position_groups_to_marks([
    [1, 4, 7],
    [2, 5, 8],
    [3, 6, 9]
  ])
end
diagonals() click to toggle source
# File lib/tic_tac_toe/board.rb, line 39
def diagonals
  position_groups_to_marks([
    [1, 5, 9],
    [3, 5, 7]
  ])
end
get_mark_at(position) click to toggle source
# File lib/tic_tac_toe/board.rb, line 13
def get_mark_at(position)
  @board_positions[position]
end
return_entire_board() click to toggle source
# File lib/tic_tac_toe/board.rb, line 17
def return_entire_board
  return [get_mark_at(1), get_mark_at(2), get_mark_at(3),
          get_mark_at(4), get_mark_at(5), get_mark_at(6),
          get_mark_at(7), get_mark_at(8), get_mark_at(9)]
end
rows() click to toggle source
# File lib/tic_tac_toe/board.rb, line 23
def rows
  position_groups_to_marks([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ])
end
set_mark(mark, position) click to toggle source
# File lib/tic_tac_toe/board.rb, line 9
def set_mark(mark, position)
  @board_positions[position] = mark
end

Private Instance Methods

position_groups_to_marks(position_groups) click to toggle source
# File lib/tic_tac_toe/board.rb, line 48
def position_groups_to_marks(position_groups)
  position_groups.collect do |positions|
    positions.collect do |position|
      get_mark_at(position)
    end
  end
end