# switching16

This program has been disqualified.

 Author pyfex Submission date 2011-06-18 08:31:02.878030 Rating 8274 Matches played 2200 Win rate 76.55

## Source code:

``````# See http://overview.cc/RockPaperScissors for more information about rock, paper, scissors
# Switching 14, but with a more aggressive strategy selection. Once a strategy draws
# it is considered as failed.

import random

if input == "":
hist = ""
opp_played = []
beat = {'P': 'S', 'S': 'R', 'R': '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

# 150 different strategies
candidates = [output] * 150
performance = [(2,0)] * 150
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]+1, 0: 2, -1: 2}[score[c+input]],
performance[i]+score[c+input])

index = performance.index(max(performance, key=lambda x: x**3+x))

for length in range(min(10, 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 = beat[opp]
candidates = beat[beat[my]]
candidates = opp
candidates = my
candidates = beat[beat[opp]]
candidates = beat[my]
for i, a in enumerate(candidates[:6]):
for offset in range(3):
candidates[6+24*i+offset*8] = shift(offset+wins, a)
candidates[6+24*i+offset*8+1] = shift(offset+wins+ties, a)
candidates[6+24*i+offset*8+2] = shift(offset+losses+ties, a)
candidates[6+24*i+offset*8+3] = shift(offset+losses, a)
candidates[6+24*i+offset*8+4] = unshift(offset+wins, a)
candidates[6+24*i+offset*8+5] = unshift(offset+wins+ties, a)
candidates[6+24*i+offset*8+6] = unshift(offset+losses+ties, a)
candidates[6+24*i+offset*8+7] = unshift(offset+losses, a)
break
else:
candidates = [random.choice(['R', 'P', 'S'])] * 150

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