Class: TicTacToe::Lines

Inherits:
Array
  • Object
show all
Defined in:
lib/tic_tac_toe_mchliakh/board/lines.rb

Instance Method Summary collapse

Instance Method Details

#can_lose(player) ⇒ Object



7
8
9
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 7

def can_lose(player)
  select {|l| l.can_lose?(player) }
end

#can_win(player) ⇒ Object



3
4
5
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 3

def can_win(player)
  select {|l| l.can_win?(player) }
end

#could_lose(player) ⇒ Object



15
16
17
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 15

def could_lose(player)
  select {|l| l.could_lose?(player) }
end

#could_win(player) ⇒ Object



11
12
13
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 11

def could_win(player)
  select {|l| l.could_win?(player) }
end

#squares_that_can_be_forked(player) ⇒ Object



25
26
27
28
29
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 25

def squares_that_can_be_forked(player)
  Squares.new(could_lose(player).combination(2).map do |ll|
    (ll.first & ll.last).first
  end.compact)
end

#squares_that_can_fork(player) ⇒ Object



19
20
21
22
23
# File 'lib/tic_tac_toe_mchliakh/board/lines.rb', line 19

def squares_that_can_fork(player)
  Squares.new(could_win(player).combination(2).map do |ll|
    (ll.first & ll.last).first
  end.compact)
end