Skip to content

Instantly share code, notes, and snippets.

@jwilger
Created May 10, 2012 01:01
Show Gist options
  • Save jwilger/2650202 to your computer and use it in GitHub Desktop.
Save jwilger/2650202 to your computer and use it in GitHub Desktop.
Tic-Tac-Toe in Ruby
#!/usr/bin/env ruby
def winner_is(winner)
puts "*Time passes...*"
if winner == :computer
puts "I win!"
else
puts "OK, you win this one."
end
end
puts "Let's play Tic-Tac-Toe!"
if rand(2) == 1
puts "I'll go first."
puts "I put an X in the center."
winner_is(:computer)
else
puts "You go first!"
print "Do you put an X in the center? (Y|n): "
if gets.strip =~ /^no?$/i
winner_is(:computer)
else
winner_is(:human)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment