# switching15

This program has been disqualified.

 Author pyfex Submission date 2011-06-17 23:35:21.661770 Rating 7713 Matches played 2249 Win rate 75.94

## Source code:

``````# See http://overview.cc/RockPaperScissors for more information about rock, paper, scissors
# Combination of switching11 and switching14

import random

if input == "":
hist = ""
opp_played = []
beat = {'P': 'S', 'S': 'R', 'R': 'P'}
beat2 = {'PP': 'S', 'SS': 'R', 'RR':'P', 'PS': 'S', 'PR': 'P', 'RS': 'R', 'RP': 'P', 'SP': 'S', 'SR': 'R'}
complement = {'PS': 'R', 'PR': 'S', 'RS': 'P', 'RP': 'S', 'SP': 'R', 'SR': 'P'}
score = {'RR': 0, 'PP': 0, 'SS': 0, 'PR': 1, 'RS': 1, 'SP': 1,'RP': -1, 'SR': -1, 'PS': -1,}
output = random.choice(["R", "P", "S"])

def shift(n, move):
for i in range(n%2):
move = beat[move]
return move

def unshift(n, move):
for i in range(n%2):
move = beat[beat[move]]
return move

candidates = [output] * 125
performance = [(0,0)] * 125
wins = losses = ties = 0

else:

sc = score[output+input]
if sc == 1:
wins += 1
elif sc == 0:
ties += 1
elif sc == -1:
losses += 1

hist += output.lower()+input
opp_played.append(input)

for i, c in enumerate(candidates):
performance[i] = ({1:performance[i][0]+1, 0: performance[i][0], -1: 0}[score[c+input]],
performance[i][1]+score[c+input])

index = performance.index(max(performance, key=lambda x: x[0]**3+x[1]))

for length in range(min(12, len(hist)-2), 0, -2):
search = hist[-length:]
idx = hist.rfind(search, 0, -2)
if idx != -1:
my = hist[idx+length].upper()
opp = hist[idx+length+1]
candidates[0] = beat[opp]
candidates[1] = beat[beat[my]]
candidates[2] = beat2[beat[my] + beat[beat[opp]]]
candidates[3] = beat2[beat[opp] + beat[beat[my]]]
candidates[4] = complement[''.join(sorted(set(candidates[0] + candidates[1] + candidates[3])))]
for i, a in enumerate(candidates[:5]):
for offset in range(3):
candidates[5+24*i+offset*8] = shift(offset+wins, a)
candidates[5+24*i+offset*8+1] = shift(offset+wins+ties, a)
candidates[5+24*i+offset*8+2] = shift(offset+losses+ties, a)
candidates[5+24*i+offset*8+3] = shift(offset+losses, a)
candidates[5+24*i+offset*8+4] = unshift(offset+wins, a)
candidates[5+24*i+offset*8+5] = unshift(offset+wins+ties, a)
candidates[5+24*i+offset*8+6] = unshift(offset+losses+ties, a)
candidates[5+24*i+offset*8+7] = unshift(offset+losses, a)
break
else:
candidates = [random.choice(['R', 'P', 'S'])] * 125

output = candidates[index]``````