reactions

AuthorKendallHopkins
Submission date2011-06-09 06:49:40.109724
Rating2231
Matches played5673
Win rate23.6

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

Source code:

import random

lose = 2
win = 1
tie = 0
unknown = -1
rpc = ['R','P','S']

if not input:
    last_outcome = unknown
    game_outcome = unknown
    grid = [[0,0,0],[0,0,0],[0,0,0]]
    output = random.choice(rpc)
else:
    if last_outcome != unknown:
        grid[last_outcome][(rpc.index( last_input )-rpc.index( input ))%3] += 1
    
    last_outcome = game_outcome
    game_outcome = (rpc.index( input ) - rpc.index( output )) % 3
    last_input = input
    
    if grid[last_outcome][0] > grid[last_outcome][1]:
        if grid[last_outcome][0] > grid[last_outcome][2]:
            output = rpc[1]
        else:
            output = rpc[0]
    else:
        if grid[last_outcome][1] > grid[last_outcome][2]:
            output = rpc[2]
        else:
            output = rpc[0]