Class: TicTacToe::Board

Inherits:
Object
  • Object
show all
Defined in:
lib/tic_tac_toe/board.rb

Instance Method Summary collapse

Constructor Details

#initializeBoard

Returns a new instance of Board.



5
6
7
# File 'lib/tic_tac_toe/board.rb', line 5

def initialize
  @board_positions = []
end

Instance Method Details

#columnsObject



31
32
33
34
35
36
37
# 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

#diagonalsObject



39
40
41
42
43
44
# 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) ⇒ Object



13
14
15
# File 'lib/tic_tac_toe/board.rb', line 13

def get_mark_at(position)
  @board_positions[position]
end

#return_entire_boardObject



17
18
19
20
21
# 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

#rowsObject



23
24
25
26
27
28
29
# 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) ⇒ Object



9
10
11
# File 'lib/tic_tac_toe/board.rb', line 9

def set_mark(mark, position)
  @board_positions[position] = mark
end