Testramon

AuthorTest Ramon
Submission date2017-05-20 19:13:02.606500
Rating1721
Matches played360
Win rate16.11

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

Source code:

component = {'R':{'R':0,'P':0,'S':0},'P':{'R':0,'P':0,'S':0},'S':{'P':0,'R':0,'S':0}}  # component current hit vs my last hit (key)

factor = {'R':{'R':0,'P':0,'S':0},'P':{'R':0,'P':0,'S':0},'S':{'P':0,'R':0,'S':0}}  # component current hit vs last hit(key)

game=[0,0,0]

my_history =[]
their_history=[]

def beat(move):
    if move=='R':
        return 'P'
    if move == 'P':
        return 'S'
    if move=='S':
        return 'R'

def max_d(d):
    x = 0
    a = 'P'
    for i in d:
        if d[i]>x:
            x = d[i]
            a = i
    return a

def analysis():
    global my_history,their_history
    component = {'R': {'R': 0, 'P': 0, 'S': 0}, 'P': {'R': 0, 'P': 0, 'S': 0},
                 'S': {'P': 0, 'R': 0, 'S': 0}}  # component current hit vs my last hit (key)

    factor = {'R': {'R': 0, 'P': 0, 'S': 0}, 'P': {'R': 0, 'P': 0, 'S': 0},
              'S': {'P': 0, 'R': 0, 'S': 0}}  # component current hit vs last hit(key)
    for i in range(1,len(my_history)):
        component[my_history[i-1]][their_history[i]]+=1
        factor[their_history[i-1]][their_history[i]]+=1

    com_per = component[my_history[len(my_history) - 1]][max_d(component[my_history[len(my_history) - 1]])]*1.0/len(my_history)
    fac_per = factor[their_history[len(their_history) - 1]][max_d(factor[their_history[len(their_history) - 1]])]*1.0/len(my_history)
    print(max_d(component[my_history[len(my_history) - 1]]),max_d(factor[their_history[len(their_history) - 1]]))
    if com_per > fac_per:
        return beat(max_d(component[my_history[len(my_history) - 1]]))
    else:
        return beat(max_d(factor[their_history[len(their_history) - 1]]))

def move():
    global their_history,my_history
    if len(my_history)<4:
        my_history.append(['S','R','S','P'][len(my_history)])
        return ['S','R','S','P'][len(my_history)]
    else:
        temp  =analysis()
        my_history.append(temp)
        return temp


if input=='':
    component = {'R': {'R': 0, 'P': 0, 'S': 0}, 'P': {'R': 0, 'P': 0, 'S': 0},
                 'S': {'P': 0, 'R': 0, 'S': 0}}  # component current hit vs my last hit (key)

    factor = {'R': {'R': 0, 'P': 0, 'S': 0}, 'P': {'R': 0, 'P': 0, 'S': 0},
              'S': {'P': 0, 'R': 0, 'S': 0}}  # component current hit vs last hit(key)

    game = [0, 0, 0]

    my_history = []
    their_history = []
    output=move()
elif input=='R':
    their_history.append('R')
    output = move()
elif input=='S':
    their_history.append('S')
    output = move()
elif input=='P':
    their_history.append('P')
    output = move()