Author | msherry |
Submission date | 2014-10-11 05:22:51.134242 |
Rating | 3524 |
Matches played | 522 |
Win rate | 36.21 |
Use rpsrunner.py to play unranked matches on your computer.
import random
defeats = {
'R': 'S',
'S': 'P',
'P': 'R',
}
def won_last(us, opponent):
return defeats[us] == opponent
output = ''
won = False
opponent_last = input
if input == '':
# First move
last = ''
opponent_last = ''
else:
print last, opponent_last
won = won_last(last, opponent_last)
if input == 'R':
if won:
output = 'R'
elif input == 'P':
if won:
output = 'P'
elif input == 'S':
if won:
output = 'S'
if not output:
output = random.choice(['R', 'P', 'S'])
last = output