jes da best

AuthorJames Stanley
Submission date2018-05-24 18:35:53.020440
Rating4901
Matches played288
Win rate48.96

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

Source code:

# http://jes.xxx/
import random

markov = {}
state = ['$', '$']

def str_state(state):
    return ' '.join(state)

def play():
    moves = ['R', 'P', 'S']
    if str_state(state) in markov:
        moves = markov[str_state(state)]
    expect = random.choice(moves)

    response_to = {
        'R': 'P',
        'P': 'S',
        'S': 'R',
    };

    return response_to[expect]

if len(input):
    if str_state(state) in markov:
        markov[str_state(state)].append(input)
    else:
        markov[str_state(state)] = [input]
    state.append(input)
    while len(state) > 2:
        state.pop(0)

output = play()