Created
May 10, 2012 01:01
-
-
Save jwilger/2650202 to your computer and use it in GitHub Desktop.
Tic-Tac-Toe in Ruby
This file contains 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
#!/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