class Board
Constants
- BOARD_SIZE
Attributes
tile[R]
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
is_game_finish?(player_symbol)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_terns()
click to toggle source
# File lib/tic_tac_toe_vj/board.rb, line 24 def number_of_terns @number_of_tiles_marked end
Private Instance Methods
check_column?(player_symbol)
click to toggle source
# File lib/tic_tac_toe_vj/board.rb, line 63 def check_column?(player_symbol) BOARD_SIZE.times do |row| check_win = true BOARD_SIZE.times do |column| check_win = check_win && @tile[column][row] == player_symbol end return true if check_win end return false end
check_left_diognal?(player_symbol)
click to toggle source
# File lib/tic_tac_toe_vj/board.rb, line 34 def check_left_diognal?(player_symbol) check_win = true BOARD_SIZE.times do |index| check_win = @tile[index][index] == player_symbol return false if !check_win end return true end
check_row?(player_symbol)
click to toggle source
# File lib/tic_tac_toe_vj/board.rb, line 52 def check_row?(player_symbol) BOARD_SIZE.times do |row| check_win = true BOARD_SIZE.times do |column| check_win = check_win && @tile[row][column] == player_symbol end return true if check_win end return false end
chek_right_diognal?(player_symbol)
click to toggle source
# File lib/tic_tac_toe_vj/board.rb, line 43 def chek_right_diognal?(player_symbol) check_win = true BOARD_SIZE.times do |index| check_win = @tile[index][BOARD_SIZE - 1 - index] == player_symbol return false if !check_win end return true end