Class: TicTacToe::Line
- Inherits:
-
Object
- Object
- TicTacToe::Line
- Defined in:
- lib/tic_tac_toe_mchliakh/board/line.rb
Instance Attribute Summary collapse
-
#squares ⇒ Object
readonly
Returns the value of attribute squares.
Instance Method Summary collapse
- #&(other) ⇒ Object
- #can_lose?(player) ⇒ Boolean
- #can_win?(player) ⇒ Boolean
- #could_lose?(player) ⇒ Boolean
- #could_win?(player) ⇒ Boolean
-
#initialize(board, squares) ⇒ Line
constructor
A new instance of Line.
- #square_taken ⇒ Object
Constructor Details
#initialize(board, squares) ⇒ Line
Returns a new instance of Line.
5 6 7 8 9 |
# File 'lib/tic_tac_toe_mchliakh/board/line.rb', line 5 def initialize(board, squares) @board = board @squares = squares listen end |
Instance Attribute Details
#squares ⇒ Object (readonly)
Returns the value of attribute squares.
3 4 5 |
# File 'lib/tic_tac_toe_mchliakh/board/line.rb', line 3 def squares @squares end |
Instance Method Details
#&(other) ⇒ Object
11 12 13 |
# File 'lib/tic_tac_toe_mchliakh/board/line.rb', line 11 def &(other) squares & other.squares end |
#can_lose?(player) ⇒ Boolean
20 21 22 23 |
# 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) ⇒ Boolean
15 16 17 18 |
# 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) ⇒ Boolean
30 31 32 33 |
# 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) ⇒ Boolean
25 26 27 28 |
# 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 ⇒ Object
35 36 37 38 39 |
# 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 |