dumb_probram

Authorstupid_coder
Submission date2016-02-08 13:12:19.370467
Rating3129
Matches played416
Win rate29.33

Use rpsrunner.py to play unranked matches on your computer.

Source code:

n = 10
seed1 = 17
seed2 = 27
rvalue = 13
maxr = 65536
his = ""
scores = {"RR":0, "SS":0, "PP":0, "RP":1, "PS":1, "SR":1, "PR":-1, "SP":-1, "RS":-1}
his_map = {}
vars = "RSP"
def r():
  global rvalue
  rvalue =  ((rvalue * seed1)+seed2)% maxr
  return vars[rvalue%3]

def best(s):
  a = s.count("R")
  b = s.count("S")
  c = s.count("P")
  if a > b and a > c:
    return "R"
  elif b > a and b > c:
    return "S"
  else:
    return "P"

def update():
  key = his[-n:-1]  
  lentry = his_map[key] if key in his_map else ""
  lentry+=his[-1]
  his_map[key]= lentry

if not input:
  score = 0
  prev_move = r()
elif len(input) < n:
  play = prev_move+input
  score += scores[play]
  if score < -100:
    prev_move = r()
  else:
    prev_move = input
  his+=input
else:
  last = his[-n::]
  if last in his_map:
    prev_move = best(his_map[last])
  else:
    prev_move = r()
  his+=input
  update()

output=prev_move