aboutsummaryrefslogtreecommitdiffstats
path: root/board.rb
blob: df66a8d91cfc21b7b23199c6b313d2e2b51e0d0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Board
  attr_accessor :current_player
  
  def initialize
    @board = [
      ['.', '.', '.'],
      ['.', '.', '.'],
      ['.', '.', '.']
    ]
  end
  
  def render
    output = ''
    @board.each {|row| output << row.join + "\n" }
    output
  end
  
  # Raises an ArgumentError if integer conversion fails
  def transform_coordinates(str)
    coordinates = str.split(',')
    
    begin
      coordinates[0] = Integer(coordinates[0])
      coordinates[1] = Integer(coordinates[1])
      
      coordinates if coordinates.length > 1
    rescue
    end
  end
  
  def update_cell(row_index, column_index, value)
    @board[row_index][column_index] = value
  end
  
  def winner?
  end
end