Class: Judge

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt-cli/judge.rb

Overview

Класс Judge - судья (проверщик).

Constant Summary collapse

WIN_COMBINATIONS =
[
  [0, 1, 2], [3, 4, 5], [6, 7, 8],
  [0, 3, 6], [1, 4, 7], [2, 5, 8],
  [0, 4, 8], [2, 4, 6]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ Judge

Returns a new instance of Judge.



13
14
15
# File 'lib/ttt-cli/judge.rb', line 13

def initialize(game)
  @board = game.board.cells
end

Instance Attribute Details

#boardObject

Returns the value of attribute board.



5
6
7
# File 'lib/ttt-cli/judge.rb', line 5

def board
  @board
end

Instance Method Details

#is_combo?(player) ⇒ Boolean

основной метод для проверки на выигрыш возвращает true если обнаружена выигрышная комбинация

Returns:

  • (Boolean)


19
20
21
# File 'lib/ttt-cli/judge.rb', line 19

def is_combo?(player)
  !winning_combination(player.token).nil?
end