Comp Thinking 5

Authorseb
Submission date2019-10-16 12:47:29.300802
Rating5367
Matches played203
Win rate52.71

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

Source code:

import random


def getNextMove(string):
    for i in range(len(string) - 1, 0, -1):
        temp = string[-i:]

        if string.find(temp) + i < len(string):
            return string[i]

    return ""


previous = input

if previous == "":
    pattern = "RPS"


def beat(choise):
    if choise == "R":
        return "P"
    elif choise == "P":
        return "S"
    else:
        return "R"


if previous != "":
    pattern += previous

nextMove = getNextMove(pattern[-10:])
if nextMove == "":
    output = beat(random.choice(pattern))
else:
    output = beat(nextMove)