This program has been disqualified.
Author | evolvingstuff |
Submission date | 2011-06-15 21:25:42.484106 |
Rating | 6823 |
Matches played | 2401 |
Win rate | 72.26 |
from random import *
#Inspired by dllu and his evil werfer-bots, now looking for various version of history ("us", "me", "yu")
#the code is a mess, but meh..
#increased weight of random strategy
if input == "":
c_to_n = {'R':0, 'P':1, 'S':2}
cc_to_m = {'rR':0, 'rP':1, 'rS':2,
'pR':3, 'pP':4, 'pS':5,
'sR':6, 'sP':7, 'sS':8}
win_set = ['rP', 'pS', 'sR']
draw_set = ['rR', 'pP', 'sS']
lose_set = ['rS', 'pR', 'sP']
shift1 = {'R':'P', 'P':'S', 'S':'R'}
shift2 = {'R':'S', 'P':'R', 'S':'P'}
shift3 = {'R':'R', 'P':'P', 'S':'S'}
random_moves = 10
decay = 0.625
weight_random = 1
weight_0th_order_us = 1
weight_1st_order_us = 1
weight_2nd_order_us = 1
weight_0th_order_me = 1
weight_1st_order_me = 1
weight_2nd_order_me = 1
weight_0th_order_yu = 1
weight_1st_order_yu = 1
weight_2nd_order_yu = 1
prediction_0th_order_us = choice(['R','P','S'])
prediction_1st_order_us = choice(['R','P','S'])
prediction_2nd_order_us = choice(['R','P','S'])
prediction_0th_order_me = choice(['R','P','S'])
prediction_1st_order_me = choice(['R','P','S'])
prediction_2nd_order_me = choice(['R','P','S'])
prediction_0th_order_yu = choice(['R','P','S'])
prediction_1st_order_yu = choice(['R','P','S'])
prediction_2nd_order_yu = choice(['R','P','S'])
history_us = ''
history_me = ''
history_yu = ''
max_match_length = 20
output = choice(['R','P','S'])
else:
history_us += input.lower() + output
history_me += output
history_yu += input
if len(history_me) > random_moves:
weight_random *= decay
weight_0th_order_us *= decay
weight_1st_order_us *= decay
weight_2nd_order_us *= decay
weight_0th_order_me *= decay
weight_1st_order_me *= decay
weight_2nd_order_me *= decay
weight_0th_order_yu *= decay
weight_1st_order_yu *= decay
weight_2nd_order_yu *= decay
if prediction_0th_order_us == input:
weight_0th_order_us += 1
elif prediction_1st_order_us == input:
weight_1st_order_us += 1
else:
weight_2nd_order_us += 1
if prediction_0th_order_me == input:
weight_0th_order_me += 1
elif prediction_1st_order_me == input:
weight_1st_order_me += 1
else:
weight_2nd_order_me += 1
if prediction_0th_order_yu == input:
weight_0th_order_yu += 1
elif prediction_1st_order_yu == input:
weight_1st_order_yu += 1
else:
weight_2nd_order_yu += 1
if (input.lower() + output) not in win_set:
weight_random += 2
#####################################################################
suffix = ''
for d in range(max_match_length, 0, -1):
prefix = history_us[-d*2:]
i = history_us[:-2].rfind(prefix)
if i > -1:
suffix = history_us[i + d*2]
break
#make nth order predictions
if suffix != '':
assert suffix in ['r','p','s']
prediction_0th_order_us = suffix.upper()
prediction_1st_order_us = shift2[suffix.upper()]
prediction_2nd_order_us = shift1[suffix.upper()]
else:
prediction_0th_order_us = choice(['R','P','S'])
prediction_1st_order_us = choice(['R','P','S'])
prediction_2nd_order_us = choice(['R','P','S'])
#####################################################################
suffix = ''
for d in range(max_match_length, 0, -1):
prefix = history_me[-d:]
i = history_me[:-1].rfind(prefix)
if i > -1:
suffix = history_me[i + d]
break
#make nth order predictions
if suffix != '':
assert suffix in ['R','P','S']
prediction_0th_order_me = shift1[suffix]
prediction_1st_order_me = shift3[suffix]
prediction_2nd_order_me = shift2[suffix]
else:
prediction_0th_order_me = choice(['R','P','S'])
prediction_1st_order_me = choice(['R','P','S'])
prediction_2nd_order_me = choice(['R','P','S'])
#####################################################################
suffix = ''
for d in range(max_match_length, 0, -1):
prefix = history_yu[-d:]
i = history_yu[:-1].rfind(prefix)
if i > -1:
suffix = history_yu[i + d]
break
#make nth order predictions
if suffix != '':
assert suffix in ['R','P','S']
prediction_0th_order_yu = suffix
prediction_1st_order_yu = shift2[suffix]
prediction_2nd_order_yu = shift1[suffix]
else:
prediction_0th_order_yu = choice(['R','P','S'])
prediction_1st_order_yu = choice(['R','P','S'])
prediction_2nd_order_yu = choice(['R','P','S'])
#####################################################################
weights = [weight_0th_order_us, weight_1st_order_us, weight_2nd_order_us,
weight_0th_order_me, weight_1st_order_me, weight_2nd_order_me,
weight_0th_order_yu, weight_1st_order_yu, weight_2nd_order_yu,
weight_random]
responses = [shift1[prediction_0th_order_us], shift1[prediction_1st_order_us], shift1[prediction_2nd_order_us],
shift1[prediction_0th_order_me], shift1[prediction_1st_order_me], shift1[prediction_2nd_order_me],
shift1[prediction_0th_order_yu], shift1[prediction_1st_order_yu], shift1[prediction_2nd_order_yu],
choice(['R','P','S'])]
#####################################################################
for i in range(len(weights)):
if random() < weights[i] / sum(weights[i:]):
output = responses[i]
break
else:
output = choice(['R','P','S'])