dirk4

Authordirknbr
Submission date2019-03-16 20:37:17.177438
Rating5063
Matches played236
Win rate47.88

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

Source code:

# check what was most frequent opp action after last me/opp combo

# http://www.rpscontest.com/authorSearch?name=dirknbr

import random

rps = ['R', 'P', 'S']
best = {'R': 'P', 'P': 'S', 'S': 'R'}

hist_me = []
hist_opp = []

# input = 'R'
# hist_me = ['P']

if input == '' or len(hist_me) < 2:
  output = random.choice(rps)
else:
  hist_opp.append(input)
  last = (hist_me[-1], hist_opp[-1])
  freq = {'R': 0, 'P': 0, 'S': 0}
  for i in range(len(hist_opp) - 1):
    if (hist_me[i], hist_opp[i]) == last:
      nex = hist_opp[i + 1]
      freq[nex] += 1
  # sort
  if sum(freq.values()) == 0:
    output = random.choice(rps)
  else:
    freq = sorted([(v, k) for k, v in freq.iteritems()], reverse=True)
    output = best(freq[0][1])


hist_me.append(output)