Created
August 15, 2014 01:33
-
-
Save pumpkincouture/eb0d95a075e5aee6a2e4 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 moves_left(cells) | |
move = [] | |
cells.each do |k,v| | |
move << k if cells[k] != "X" && cells[k] != "O" | |
end | |
move | |
end | |
def possible_moves(cells) | |
to_win = win_move(cells) | |
block = to_block?(cells) | |
random = moves_left(cells) | |
to_win.map!(&:to_s) | |
if to_win.empty? | |
return random | |
elsif to_win.include? "5" | |
return "5" | |
elsif block | |
return block | |
else to_win | |
return to_win | |
end | |
end | |
def comp_move(move) | |
return move[-1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment