Class: JbcdenTtt::GameState

Inherits:
Object
  • Object
show all
Defined in:
lib/jbcden_ttt/game_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board, turn_num, current_player) ⇒ GameState

Returns a new instance of GameState.



4
5
6
7
8
# File 'lib/jbcden_ttt/game_state.rb', line 4

def initialize(board, turn_num, current_player)
  @board = board
  @turn_num = turn_num
  @player = current_player
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



3
4
5
# File 'lib/jbcden_ttt/game_state.rb', line 3

def board
  @board
end

#current_playerObject (readonly)

Returns the value of attribute current_player.



3
4
5
# File 'lib/jbcden_ttt/game_state.rb', line 3

def current_player
  @current_player
end

#turn_numObject (readonly)

Returns the value of attribute turn_num.



3
4
5
# File 'lib/jbcden_ttt/game_state.rb', line 3

def turn_num
  @turn_num
end

Instance Method Details

#end_state?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/jbcden_ttt/game_state.rb', line 10

def end_state?
  if turn_num >= min_turns
    row_win(board) || column_win(board) || diagonal_win(board) || full_board(board)
  else
    false
  end
end