Random Tilt 4bc "The Ratchet"

Authorflug
Submission date2019-06-06 20:23:56.892282
Rating5189
Matches played236
Win rate50.0

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

Source code:

#So RandomTilt4b was designed to minimize losses by switching to purely random
#response in case it started losing.  But . . . that had the effect of baking
#in any loss, and so it actually turned out to be pretty excellent "loser
#bot" by accident.
#
#So now we are trying the reverse--try to find a bit of a winning advantage
#and if we do happen to gain a small winning advantage, try to hold it in place
#through random play, like a little ratchet.
 
import random
choice1 = random.choice(["1","2","3"])

if input == "":
   saveinput = ""
   saveoutput = ""
   rounds=0
   won=0
   lost=0
   draw=0
   choice1 = random.choice(["1","2","3", "4"]) 
   winlist = []
   lastChange=0  
   lastSemiChange=0
else:
    rounds += 1;
   
if saveoutput==input:
   draw += 1
   winlist.append(0)
elif (input == "R" and saveoutput == "S") or (input == "S" and saveoutput == "P") or (input == "P" and saveoutput == "R"): 
   lost += 1
   winlist.append(-1)   
else:
    won += 1
    winlist.append(1)
    
recents = 10
minChange = 10
decisionPoint = 0
recentTot = 0

for x in range(recents):
    if (rounds-x>0):
        recentTot += winlist[rounds-x]
    
if (recentTot < decisionPoint and rounds - lastChange > minChange):
   choice2 = choice1
   while choice1 == choice2:
         choice2 = random.choice(["1","2","3"])
   lastChange=rounds
   choice1=choice2
   
#So this is a little ratchet . . . if we've won recently we switch
#to random to try to just hold it   
semirecents = 40
semiminChange = 40
semiHoldLength = 60
semidecisionPoint = 5
semirecentTot = 0


for x in range(semirecents):
    if (rounds-x>0):
        semirecentTot += winlist[rounds-x]   

#if ((rounds > semiHoldLength and rounds < lastSemiChange + semiHoldLength ) or semirecentTot > semidecisionPoint):
if (semirecentTot > semidecisionPoint):
   choice1 = 4  
   lastSemiChange = rounds         
        
       

if choice1 == "1":
   output = random.choice(["R","R","R","R","R","P","S"])
if choice1 == "2":
   output = random.choice(["R","P","P","P","P","P","S"])
if choice1 == "3":
   output = random.choice(["R","P","S","S","S","S","S"])
if choice1 == "4":
   output = random.choice(["R","P","S"])

saveinput = input  
saveoutput = output