Random Tilt 5

Authorflug
Submission date2019-06-03 07:10:29.925039
Rating4309
Matches played249
Win rate41.77

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

Source code:

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  
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 = -1
recentTot = 0
origChoice = choice1

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 the failsafe .  . . if we're losing too badly we just switch
#to random   
semirecents = 50
semiminChange = 50
semidecisionPoint = -15
semirecentTot = 0

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

if (semirecentTot < semidecisionPoint and rounds - lastChange > minChange):
   choice2 = origChoice
   while origChoice == choice2:
         choice2 = random.choice(["5","6","7"])
   lastChange=rounds
   choice1=choice2
   
##OR if we have a decent little lead, we just try to hold it   
if (won > lost + 15):
   choice1 = 4
   
           
    
switch = random.choice([0,1,1,1,1,1,1,1])        
       

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

   
saveinput = input  
saveoutput = output