Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created August 15, 2014 01:33
Show Gist options
  • Save pumpkincouture/eb0d95a075e5aee6a2e4 to your computer and use it in GitHub Desktop.
Save pumpkincouture/eb0d95a075e5aee6a2e4 to your computer and use it in GitHub Desktop.
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