Class: Board

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

Constant Summary collapse

BOARD_SIZE =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoard

Returns a new instance of Board.



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

def initialize()
  @number_of_tiles_marked = 0
  @tile = Array.new(BOARD_SIZE) {Array.new(BOARD_SIZE, '_')}
end

Instance Attribute Details

#tileObject (readonly)

Returns the value of attribute tile.



6
7
8
# File 'lib/tic_tac_toe_vj/board.rb', line 6

def tile
  @tile
end

Instance Method Details

#is_game_finish?(player_symbol) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/tic_tac_toe_vj/board.rb', line 28

def is_game_finish?(player_symbol)
  return check_left_diognal?(player_symbol) || chek_right_diognal?(player_symbol) || check_row?(player_symbol) || check_column?(player_symbol)
end

#is_tile_not_marked?(location) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/tic_tac_toe_vj/board.rb', line 20

def is_tile_not_marked?(location)
  return @tile[location.row][location.column] == "_"
end

#mark_tile(location, mark) ⇒ Object



13
14
15
16
17
18
# File 'lib/tic_tac_toe_vj/board.rb', line 13

def mark_tile(location, mark)
  if is_tile_not_marked?(location)
    @tile[location.row][location.column] = mark
    @number_of_tiles_marked += 1
  end
end

#number_of_ternsObject



24
25
26
# File 'lib/tic_tac_toe_vj/board.rb', line 24

def number_of_terns
  @number_of_tiles_marked
end