Created
June 11, 2012 19:43
-
-
Save ddd1600/2912222 to your computer and use it in GitHub Desktop.
rps console -- human versus computer
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
require("./rps.rb") | |
HAND = { :rock => 1, :paper => 3, :scissors => 4 } | |
class DoAIGame | |
def promptuser | |
loop do | |
$stdout.write("Player 1: ") | |
param1 = $stdin.gets.chomp | |
param1 = param1.to_sym | |
break if param1 == :quit | |
possibles = HAND.keys | |
param2 = possibles[Random.rand(possibles.size)] | |
rps9 = RockPaperScissors.new | |
winner = rps9.play(param1, param2) | |
if winner == param1 | |
puts "Human wins." | |
elsif winner == "tie" | |
puts "No one won." | |
elsif winner == "invalid parameters" | |
puts winner | |
else | |
puts "Computer beats human." | |
end | |
end | |
end | |
end | |
g = DoAIGame.new | |
g.promptuser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment