Class: Rules
- Inherits:
-
Object
- Object
- Rules
- Defined in:
- lib/ttt_malisa/rules.rb
Constant Summary collapse
- WINNING_COMBOS =
[ [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6] ]
Instance Method Summary collapse
- #draw? ⇒ Boolean
- #game_over? ⇒ Boolean
-
#initialize(board) ⇒ Rules
constructor
A new instance of Rules.
- #winning_combination? ⇒ Boolean
Constructor Details
#initialize(board) ⇒ Rules
Returns a new instance of Rules.
5 6 7 |
# File 'lib/ttt_malisa/rules.rb', line 5 def initialize(board) @board = board end |
Instance Method Details
#draw? ⇒ Boolean
32 33 34 |
# File 'lib/ttt_malisa/rules.rb', line 32 def draw? !winning_combination? && @board.full? end |
#game_over? ⇒ Boolean
20 21 22 |
# File 'lib/ttt_malisa/rules.rb', line 20 def game_over? winning_combination? || draw? end |
#winning_combination? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/ttt_malisa/rules.rb', line 24 def winning_combination? WINNING_COMBOS.any? do |x, y, z| @board.position_taken?(x) && @board.squares[x] == @board.squares[y] && @board.squares[x] == @board.squares[z] end end |