Skip to content

Instantly share code, notes, and snippets.

@dvoryankin
Created September 5, 2016 16:52
Show Gist options
  • Save dvoryankin/5c34eb5a4d7b05b4ac76ad868d22b0ee to your computer and use it in GitHub Desktop.
Save dvoryankin/5c34eb5a4d7b05b4ac76ad868d22b0ee to your computer and use it in GitHub Desktop.
rock scissors paper autoplay less code
options = [:paper, :rock, :scissors]
player1 = ""
player2 = ""
loop do
p1 = rand(0..2)
p2 = rand(0..2)
puts "Player 1: #{options[p1]}, Player 2: #{options[p2]}"
sleep 1
if p1 == p2
puts 'Draw! Start again. One, two, three..'
elsif ((p1 - p2) == options.size - 1)
puts 'Player 1 - win'
elsif ((p2 - p1) == options.size - 1)
puts 'Player 2 - win'
elsif p1 < p2
puts 'Player 1 - win'
else
puts 'Player 2 - win'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment