Skip to content

Instantly share code, notes, and snippets.

@britg
Created June 23, 2015 17:03
Show Gist options
  • Save britg/1686652923a179e0e4ca to your computer and use it in GitHub Desktop.
Save britg/1686652923a179e0e4ca to your computer and use it in GitHub Desktop.
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