Author | zdg |
Submission date | 2011-09-03 03:36:43.783846 |
Rating | 6225 |
Matches played | 2858 |
Win rate | 60.43 |
Use rpsrunner.py to play unranked matches on your computer.
# somewhat random
import math
import random
beats = {'R':'P', 'P':'S', 'S':'R'}
def randHand():
return random.choice(['R', 'P', 'S'])
def response(mine, other):
if mine == other:
return other
elif beats[mine] == other:
return beats[other]
else:
return mine
# start of main code
if input is None or input == '':
whiskerLength = 334
myResponses = []
output = randHand()
lastHand = output
handsPlayed = 1
else:
index = handsPlayed % whiskerLength
if handsPlayed < whiskerLength:
myResponses.append(response(lastHand, input))
output = randHand()
else:
output = myResponses[index]
if index > 0:
myResponses[index - 1] = response(lastHand, input)
elif handsPlayed == whiskerLength:
myResponses.append(response(lastHand, input))
lastHand = output
handsPlayed += 1