class TicTacToe::Line

Attributes

squares[R]

Public Class Methods

new(board, squares) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 5
def initialize(board, squares)
  @board = board
  @squares = squares
  listen
end

Public Instance Methods

&(other) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 11
def &(other)
  squares & other.squares
end
can_lose?(player) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 20
def can_lose?(player)
  squares.taken_by_opponent(player).count == 2 &&
    squares.empty.one?
end
can_win?(player) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 15
def can_win?(player)
  squares.taken_by(player).count == 2 &&
    squares.empty.one?
end
could_lose?(player) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 30
def could_lose?(player)
  squares.taken_by_opponent(player).one? &&
    squares.empty.count == 2
end
could_win?(player) click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 25
def could_win?(player)
  squares.taken_by(player).one? &&
    squares.empty.count == 2
end
square_taken() click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 35
def square_taken
  if three_in_a_row?
    @board.three_in_a_row(squares.first.player)
  end
end

Private Instance Methods

listen() click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 47
def listen
  squares.each {|s| s << self }
end
three_in_a_row?() click to toggle source
# File lib/tic_tac_toe_mchliakh/board/line.rb, line 43
def three_in_a_row?
  squares.all_taken? && squares.all_equal?
end