weightedhistory

This program has been disqualified.


AuthorTom M
Submission date2011-12-10 11:32:41.761118
Rating6547
Matches played78
Win rate66.67

Source code:

# weighted output based on previous plays from both opponent and self
# if no decision is reached initially, shorten the lookback string and continue

import random
import re
import math
lookback = 5
style=1
themweight=3
usweight=2

if input == "":
    inputstring=""
    myprev=""
    Rweight = 1
    Pweight = 1
    Sweight = 1

inputstring = inputstring+input

if len(inputstring) < lookback:
    output = random.choice(["R","P","S"])
else:
    while True:
        Rweight = 1
        Pweight = 1
        Sweight = 1
        if lookback>2:
            lookback-=1
        last4 = inputstring[-lookback:]
        mylast4 = myprev[-lookback:]
        pattern = re.compile(last4+".")
        rock = pattern.search(inputstring[:-lookback])
        mypattern = re.compile(mylast4+".")
        myrock = mypattern.search(myprev[:-lookback])
        if rock:
            for x in pattern.findall(inputstring[:-lookback]):
                if x[lookback:]=="R":
                    Pweight += themweight
                if x[lookback:]=="P":
                    Sweight += themweight
                if x[lookback:]=="S":
                    Rweight += themweight

        if myrock:
            for y in mypattern.findall(myprev[:-lookback]):
                if y[lookback:]=="R":
                    Sweight += usweight
                if y[lookback:]=="P":
                    Rweight += usweight
                if y[lookback:]=="S":
                    Pweight += usweight
        selection = random.choice(["R","P","S"])
	z = random.uniform(0,200)
        if selection=="R":
		if z < math.fabs(random.gauss(0,Rweight)):
			output = "R"
			break
	elif selection=="P":
		if z < math.fabs(random.gauss(0,Pweight)):
			output = "P"
			break
	elif selection=="S":
		if z < math.fabs(random.gauss(0,Sweight)):
			output = "S"
			break

myprev = myprev+output