Markov1

AuthorDavidO
Submission date2019-04-16 06:01:33.343730
Rating5667
Matches played254
Win rate53.94

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

Source code:

import random
import operator


choices = ["R","P","S"]
win = {"R":"P","P":"S","S":"R"}
transition_matrix = {"RS":0,"RP":0,"RR":0,"PR":0,"PP":0,"PS":0,"SR":0,"SP":0,"SS":0}

if len(input) <= 2 :
    output = choices[random.randint(0,2)]
else:
    for (first, second) in zip(input, input[1:]):
        transition_matrix[first + second] += 1
    output = win[max(transition_matrix.iteritems(), key=operator.itemgetter(1))[0][1]]