menjam

Authorfrodewin
Submission date2018-09-18 10:00:21.701535
Rating4073
Matches played265
Win rate40.0

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

Source code:

import random
HISTORY_L=10
def most_common(l):
    max = 0
    maxitem = None
    for x in set(l):
        count =  l.count(x)
        if count > max:
            max = count
            maxitem = x
    return maxitem

if input == "": # initialize variables for the first round
    RPS=["R","P","S"]
    history=''
    offset=0
    for n in range(1, HISTORY_L):
            history += random.choice(['R','P','S'])
    lastgames=[]
    scoring = {
    "R": {
        "R": 0,
        "P": -1,
        "S": 1
    },
    "P": {
        "R": 1,
        "P": 0,
        "S": -1
    },
    "S": {
        "R": -1,
        "P": 1,
        "S": 0
    }
    }
else:
    history += input
    lastgames.append(scoring[output][input])
    hlen=random.randint(2,5)
    if (sum(lastgames[-hlen:]) < -1):
        offset+=2

guess=most_common(history[-HISTORY_L:-1])

if guess == "R":
	select = 1
elif guess == "P":
	select = 2
else:
	select = 0

output=RPS[(select+offset) % 3]