eumad_5_v00.51

Authormad
Submission date2017-05-11 08:02:04.900120
Rating5190
Matches played356
Win rate44.38

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

Source code:

import random


def scoring(out):
    reward = 0
    if ((input == "R") and (out == "R")):
        reward += 0.5
    elif ((input == "P") and (out == "P")):
        reward += 0.5
    elif ((input == "S") and (out == "S")):
        reward += 0.5
    elif ((input == "R") and (out == "P")):
        reward += 1.0
    elif ((input == "P") and (out == "S")):
        reward += 1.0
    elif ((input == "S") and (out == "R")):
        reward += 1.0
    return reward


if (input == ""):
    # Inizializzo tutte le variabili necessarie per le euristiche
    test = ""
    rewards = [0,0,0,0,0,0,0,0,0]
    scoreProb = 0
    scoreRot0 = 0
    scoreRot1 = 0
    scoreRot2 = 0
    scoreRndm = 0
    scoreAlwaysR = 0
    scoreAlwaysP = 0
    scoreAlwaysS = 0
    outHSM = random.choice(['R', 'P', 'S'])
    rewards[0] = scoreHSM = 0
    e_ta_R = 0.0
    e_ta_P = 0.0
    e_ta_S = 0.0
    v_ra_R = 0.0
    v_ra_P = 0.0
    v_ra_S = 0.0
    Pr_R = [0.0,0.0,0.0]
    Pr_R[0] = 1.0/3.0
    Pr_R[1] = 1.0/3.0
    Pr_R[2] = 1.0/3.0
    Pr_P = [0.0,0.0,0.0]
    Pr_P[0] = 1.0/3.0
    Pr_P[1] = 1.0/3.0
    Pr_P[2] = 1.0/3.0
    Pr_S = [0.0,0.0,0.0]
    Pr_S[0] = 1.0/3.0
    Pr_S[1] = 1.0/3.0
    Pr_S[2] = 1.0/3.0
    output_1 = ""
    output_2 = ""
else:
    test += input
    scoreHSM += scoring(outHSM)
    rewards[0] = scoreHSM
    for length in range(min(5, len(test)-1), 0, -1):
        trova = test[-length:]
        pos = test.rfind(trova, 0, (len(test) - length))
        if (pos == -1):
            outHSM = random.choice(['R', 'P', 'S'])
        else:
            if (test[pos+length] == "R"):
                outHSM = "P"
            elif (test[pos+length] == "S"):
                outHSM = "R"
            else:
                outHSM = "S"


if (output_2 == ""):
    outProb = random.choice(['R', 'P', 'S'])
    rewards[8] = scoreProb
else:
    scoreProb += scoring(outProb)
    if (input == "R") and (output_2 == "R"):
        e_ta_R += 1.0
        v_ra_R += 1.0
        Pr_R[0] = (1.0 + e_ta_R)/(3.0 + v_ra_R)
    elif (input == "P") and (output_2 == "R"):
        e_ta_P += 1.0
        v_ra_R += 1.0
        Pr_R[1] = (1.0 + e_ta_P)/(3.0 + v_ra_R)
    elif (input == "S") and (output_2 == "R"):
        e_ta_S += 1.0
        v_ra_R += 1.0
        Pr_R[2] = (1.0 + e_ta_S)/(3.0 + v_ra_R)
    if (input == "R") and (output_2 == "P"):
        e_ta_R += 1.0
        v_ra_P += 1.0
        Pr_P[0] = (1.0 + e_ta_R)/(3.0 + v_ra_P)
    elif (input == "P") and (output_2 == "P"):
        e_ta_P += 1.0
        v_ra_P += 1.0
        Pr_P[1] = (1.0 + e_ta_P)/(3.0 + v_ra_P)
    elif (input == "S") and (output_2 == "P"):
        e_ta_S += 1.0
        v_ra_P += 1.0
        Pr_P[2] = (1.0 + e_ta_S)/(3.0 + v_ra_P)
    if (input == "R") and (output_2 == "S"):
        e_ta_R += 1.0
        v_ra_S += 1.0
        Pr_R[0] = (1.0 + e_ta_R)/(3.0 + v_ra_S)
    elif (input == "P") and (output_2 == "S"):
        e_ta_P += 1.0
        v_ra_S += 1.0
        Pr_R[1] = (1.0 + e_ta_P)/(3.0 + v_ra_S)
    elif (input == "S") and (output_2 == "S"):
        e_ta_S += 1.0
        v_ra_S += 1.0
        Pr_R[2] = (1.0 + e_ta_S)/(3.0 + v_ra_S)
if (output_1 == "R"):
    max_Pr_R = 0
    maxIndex_Pr_R = 0
    for i in range(len(Pr_R)):
        if Pr_R[i] > max:
            max = Pr_R[i]
            maxIndex_Pr_R = i
    if (maxIndex_Pr_R == 0):
        outProb = "R"
    elif (maxIndex_Pr_R == 1):
        outProb = "P"
    elif (maxIndex_Pr_R == 2):
        outProb = "S"
elif (output_1 == "P"):
    max_Pr_P = 0
    maxIndex_Pr_P = 0
    for i in range(len(Pr_P)):
        if (Pr_P[i] > max):
            max = Pr_P[i]
            maxIndex_Pr_P = i
    if (maxIndex_Pr_P == 0):
        outProb = "R"
    elif (maxIndex_Pr_P == 1):
        outProb = "P"
    elif (maxIndex_Pr_P == 2):
        outProb = "S"
elif (output_1 == "S"):
    max_Pr_S = 0
    maxIndex_Pr_S = 0
    for i in range(len(Pr_S)):
        if (Pr_S[i] > max):
            max = Pr_S[i]
            maxIndex_Pr_S = i
    if (maxIndex_Pr_S == 0):
        outProb = "R"
    elif (maxIndex_Pr_S == 1):
        outProb = "P"
    elif (maxIndex_Pr_S == 2):
        outProb = "S"


if (input == ""):
    outRot0 = random.choice(['R', 'P', 'S'])
    rewards[1] = scoreRot0 = 0
else:
    outRot0 = {'R':'R', 'P':'P', 'S':'S'}[input]
    scoreRot0 += scoring(outRot0)
    rewards[1] = scoreRot0


if (input == ""):
    outRot1 = random.choice(['R', 'P', 'S'])
    rewards[2] = scoreRot1 = 0
else:
    outRot1 = {'R':'P', 'P':'S', 'S':'R'}[input]
    scoreRot1 += scoring(outRot1)
    rewards[2] = scoreRot1


if (input == ""):
    outRot2 = random.choice(['R', 'P', 'S'])
    rewards[3] = scoreRot2 = 0
else:
    outRot2 = {'R':'S', 'P':'R', 'S':'P'}[input]
    scoreRot2 += scoring(outRot2)
    rewards[3] = scoreRot2


outRndm = random.choice(['R', 'P', 'S'])
scoreRndm += scoring(outRndm)
rewards[4] = scoreRndm


outAlwaysR = 'R'
scoreAlwaysR += scoring(outAlwaysR)
rewards[5] = scoreAlwaysR


outAlwaysP = 'P'
scoreAlwaysP += scoring(outAlwaysP)
rewards[6] = scoreAlwaysP



outAlwaysS = 'S'
scoreAlwaysS += scoring(outAlwaysS)
rewards[7] = scoreAlwaysS


max = 0
maxIndex = 0
for i in range(len(rewards)):
    if rewards[i] > max:
        max = rewards[i]
        maxIndex = i
if (maxIndex == 0):
    output = outHSM
elif (maxIndex == 1):
    output = outRot0
elif (maxIndex == 2):
    output = outRot1
elif (maxIndex == 3):
    output = outRot2
elif (maxIndex == 4):
    output = outRndm
elif (maxIndex == 5):
    output = outAlwaysR
elif (maxIndex == 6):
    output = outAlwaysP
elif (maxIndex == 7):
    output = outAlwaysS
elif (maxIndex == 8):
    output = outProb

output_2 = output_1
output_1 = output