Created
March 22, 2012 20:07
-
-
Save teh/2163031 to your computer and use it in GitHub Desktop.
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
def from_number(r) | |
third = 1.0 / 3 | |
if r>= 0 and r<= third then choice = "r" end | |
if r >=third and r<= 2*third then choice = 'p' end | |
if r>= 2*third and r<= 1 then choice ='s' end | |
return choice | |
end | |
def play(weapon) | |
opponent = from_number(rand) | |
if weapon == opponent then result ="d" | |
else | |
wins = "pr", "rs", "sp" | |
choice = weapon + opponent | |
if wins.count(choice) == 0 then result = "l" end | |
if wins.count(choice) == 1 then result = "w" end | |
end | |
return result, opponent | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment