CDTRKsimple1

AuthorCorey White
Submission date2011-06-10 13:43:57.881818
Rating3830
Matches played5153
Win rate39.3

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

Source code:

import random

def randPlay():
    return random.choice(["R","P","S"])

def beats(x):
    if x == "R":
        return "P"
    elif x == "P":
        return "S"
    elif x == "S":
        return "R"
    else:
        return randPlay()

if not input: # initialize variables for the first round
    oppMoves = ""
    output = randPlay()
    myMoves = output
else:
    oppMoves += input
    
    if len(myMoves) <= 1:
        output = beats(beats(oppMoves[0]))
        myMoves += output
    elif oppMoves[-1] == beats(myMoves[-1]) and oppMoves[-2] == beats(myMoves[-2]):
        output = randPlay()
        myMoves +=output
    elif oppMoves[-1] == oppMoves[-2]:
        output = beats(oppMoves[-1])
        myMoves +=output