Created
June 23, 2015 17:03
-
-
Save britg/1686652923a179e0e4ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def possible_win_combo(board, combos) | |
combos.each do |combo| | |
multiple_x = board.select {|space,value| combo.include?(space) && value == 'X'} | |
if multiple_x.length == 2 | |
return combo if (board[combo[0]] != 'O' && board[combo[1]] != 'O' && board[combo[2]] != 'O') | |
end | |
end | |
nil #return not necessary, implicit | |
end | |
def possible_win_combo(board, combos) | |
win_combo = nil | |
combos.each do |combo| | |
multiple_x = board.select {|space,value| combo.include?(space) && value == 'X'} | |
if multiple_x.length == 2 | |
win_combo = combo if (board[combo[0]] != 'O' && board[combo[1]] != 'O' && board[combo[2]] != 'O') | |
break | |
end | |
end | |
return win_combo | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment