Created
August 8, 2014 02:55
-
-
Save pumpkincouture/b94b63fc2ea47f551e64 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?(computer_spaces, human_spaces) | |
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]] | |
computer_spaces.map!(&:to_i) | |
human_spaces.map!(&:to_i) | |
winning_combos.each do |sub_array| | |
if sub_array.all? {|x|computer_spaces.include?(x)} | |
@ui.computer_wins | |
return true | |
elsif sub_array.all? {|y|human_spaces.include?(y)} | |
@ui.human_wins | |
return true | |
end | |
end | |
return false | |
end | |
def open_spaces(cells) | |
spaces = [] | |
cells.each do |k, v| | |
spaces << k if cells[k] != "X" && cells[k] != "O" | |
end | |
spaces | |
end | |
def game_over?(cells) | |
winner?(computer_spaces(cells), human_spaces(cells)) || open_spaces(cells).length <= 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment