Author | Jorge |
Submission date | 2011-07-06 18:40:40.816202 |
Rating | 5644 |
Matches played | 4482 |
Win rate | 55.24 |
Use rpsrunner.py to play unranked matches on your computer.
import random
if input == "":
plays = {"R": [],
"P": [],
"S": []}
beats = {"R": "P","P": "S","S": "R"}
shifted = beats
output = random.choice(["R","P","S"])
else:
plays[mylast].append(input)
try:
output = shifted[random.choice(plays[input])]
except IndexError:
output = random.choice(["R","P","S"])
if beats[mylast] == input:
shifted = {"R": shifted["P"], "P": shifted["S"], "S": shifted["R"]}
mylast = output