Created
August 4, 2014 03:29
-
-
Save pumpkincouture/b07a0ecf1f5f70b512fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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 winner?(board) | |
winning_combos=[[1,2,3], [4,5,6], [7,8,9], | |
[1,4,7], [2,5,8], [3,6,9], | |
[1,5,9], [3,5,7]] | |
human_win=[] | |
computer_win=[] | |
board.cells.each do |k,v| | |
if board.cells[k]=="X" | |
computer_win << k | |
elsif board.cells[k]=="O" | |
human_win << k | |
else | |
false | |
end | |
end | |
human_win.map!(&:to_i) | |
computer_win.map!(&:to_i) | |
winning_combos.each do |sub_array| | |
if sub_array.all? {|x|human_win.include?(x)} | |
puts "Human won!" | |
return true | |
elsif sub_array.all? {|y|computer_win.include?(y)} | |
puts "Computer won!" | |
return true | |
end | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment