Author | __NR__ |
Submission date | 2018-05-18 17:34:12.029290 |
Rating | 5952 |
Matches played | 297 |
Win rate | 55.56 |
Use rpsrunner.py to play unranked matches on your computer.
#!/usr/bin/env python
import sys
import time
import random
random_dict = {1:"R", 2:"P", 3:"S"}
random_pick = random_dict[random.randint(1,3)]
beat_list = {"R":"P", "P":"S", "S":"R"}
if input == "": # initialize variables for the first round
rockCount = paperCount = scissorsCount = 0
history = ''
masterCount = 0
newVariable = random_pick
elif masterCount < 4:
history += input
newVariable = random_pick
masterCount += 1
else:
# print "new variable: ", input
# print "history length", len(history)
match = history + input
for idx, val in enumerate(history):
match = match[idx:]
# print "match attempted", match
# print "history full", history
if match in history:
# print "perfect fit!"
try:
befor_keyowrd, keyword, after_keyword = history.partition(match)
# print after_keyword[1]
# print beat_list[after_keyword[1]]
newVariable = beat_list[after_keyword[1]]
except:
# print "our match is the last"
newVariable = random_pick
break
else:
# print "keep trying"
if len(match) < 2:
newVariable = random_pick
break
history += input
# print "________________"
output = newVariable
# time.sleep(.5)