tjl_test

AuthorTennessee
Submission date2011-06-21 01:39:50.984474
Rating2836
Matches played4733
Win rate23.22

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

Source code:

import random

ROCK = 'R'
PAPER = 'P'
SCISSORS = 'S'

n_gram_length = 4
tot_rocks = 1
tot_papers = 1
tot_scissors = 1

move_history = []
their_move_history = []
last_output = None
output = ROCK

def rand_move():
   rnum = random.random()
   if rnum < (1 / tot_rocks):
       return ROCK
   elif rnum < (1 / tot_papers):
       return PAPER
   else:
       return SCISSORS

if not input:
    move_list = []
    output = rand_move()
    last_output = output

else:

    last_pair = (input, last_output)
    move_history.append(last_pair)
    their_move_history.append(input)

    if input == ROCK:
        tot_rocks += 1
    elif input == PAPER:
        tot_papers += 1
    else:
        tot_scissors += 1


    last_n = move_history[-1*n_gram_length:]

    output = rand_move()
    last_output = output