Class: TttGame

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt/interfaces/rails/app/models/ttt_game.rb

Class Method Summary collapse

Class Method Details

.evaluate_game(game_id, context) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ttt/interfaces/rails/app/models/ttt_game.rb', line 4

def self.evaluate_game(game_id, context)
  @game_id, @context = game_id, context
  if finished? && winner?
    winner = @context.winner(@game_id) + " is the winner!"
    return winner, "end_game"
  elsif finished?
    return "It's a draw", "end_game"
  else
    player = @context.which_current_player?(@game_id) + "'s turn"
    return player, "show"
  end
end

.finished?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ttt/interfaces/rails/app/models/ttt_game.rb', line 27

def self.finished?
  @context.finished?(@game_id)
end

.get_history_board(game, move_index_diff) ⇒ Object



21
22
23
24
25
# File 'lib/ttt/interfaces/rails/app/models/ttt_game.rb', line 21

def self.get_history_board(game, move_index_diff)
  move_traverser = game.history.move_traverser
  move_traverser.adjust_move_index(move_index_diff.to_i)
  move_traverser.history_board_builder(game.board, move_traverser.move_index)
end

.get_history_length(game_id, context) ⇒ Object



17
18
19
# File 'lib/ttt/interfaces/rails/app/models/ttt_game.rb', line 17

def self.get_history_length(game_id, context)
  context.get_history_length(game_id)
end

.winner?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ttt/interfaces/rails/app/models/ttt_game.rb', line 31

def self.winner?
  @context.winner?(@game_id)
end