This program has been disqualified.
Author | scoppini |
Submission date | 2015-07-02 22:29:39.280259 |
Rating | 7535 |
Matches played | 215 |
Win rate | 74.42 |
import random
if not input:
results = {'RP': -1, 'RR': 0, 'RS': 1,
'PS': -1, 'PP': 0, 'PR': 1,
'SR': -1, 'SS': 0, 'SP': 1}
def get_next(throw):
return 'RPS'[('RPS'.index(throw)+1)%3]
def get_result(mine, other):
return results[mine + other]
def predict(history):
for length in range(min(len(history),8),0,-1):
last_throws = history[-length:]
occurences = []
for i in range(len(history)-length):
if history[i:i+length] == last_throws:
occurences.append(i+length)
if occurences:
return majority([history[place] for place in occurences])
return random.choice('RPS')
def majority(throws):
r, p, s = throws.count('R'), throws.count('P'), throws.count('S')
if r > max(p, s): return 'R'
elif p > max(s, r): return 'P'
elif s > max(r, p): return 'S'
elif r == p == s: return random.choice('RPS')
elif r == p: return random.choice('RP')
elif p == s: return random.choice('PS')
else: return random.choice('SR')
opp_history = ''
look_mine = [[0] for i in range(3)]
guess_mine = ['']*3
look_other = [[0] for i in range(3)]
guess_other = ['']*3
made_guess = False
output = random.choice('RPS')
my_history = output
else:
opp_history += input
if made_guess:
for i in range(3):
look_mine[i].append(get_result(guess_mine[i], input))
look_other[i].append(get_result(guess_other[i], input))
else:
made_guess = True
guess_mine[0] = predict(my_history)
guess_mine[1] = get_next(guess_mine[0])
guess_mine[2] = get_next(guess_mine[1])
guess_other[0] = predict(opp_history)
guess_other[1] = get_next(guess_other[0])
guess_other[2] = get_next(guess_other[1])
prob_throw = {'R': 0, 'P': 0, 'S': 0}
output = ''
for i in range(3):
prob_throw[guess_mine[i]] += sum(look_mine[i])
prob_throw[guess_other[i]] += sum(look_other[i])
top_throw = -2000
for throw in 'RPS':
if prob_throw[throw] > top_throw:
top_throw = prob_throw[throw]
output = throw
my_history += output