Nailah

AuthorAntoinePassemiers
Submission date2017-06-01 16:58:04.064500
Rating4659
Matches played359
Win rate44.29

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

Source code:

# author : Antoine Passemiers

import random

WIN_RATE_RESOLUTION = 50

N_SYMBOLS = 3
SYMBOLS = ["R", "P", "S"]
SYMBOLS_DICT = { symbol : i for i, symbol in enumerate(SYMBOLS) }

oppsymbol = input

if not oppsymbol:
    cp = 0     # Round counter
    H = list() # History
    O = list() # Opponent history
    H.append(random.choice(range(N_SYMBOLS)))
    O.append(random.choice(range(N_SYMBOLS)))
    H.append(random.choice(range(N_SYMBOLS)))
    O.append(random.choice(range(N_SYMBOLS)))
    scores = [[[0] * N_SYMBOLS for i in range(N_SYMBOLS)] for i in range(N_SYMBOLS)]

if cp % WIN_RATE_RESOLUTION == 0:
    scores = [[[0] * N_SYMBOLS for i in range(N_SYMBOLS)] for i in range(N_SYMBOLS)]

def argmax(l):
    best_index, best_value = 0, 0
    for i in range(N_SYMBOLS):
        if l[i] > best_value:
            best_value, best_index = l[i], i
    return best_index

if oppsymbol:
    most_probable_oppindex = argmax(scores[H[-1]][O[-1]])
    symbol = SYMBOLS[(most_probable_oppindex + 1) % 3]
    H.append(SYMBOLS_DICT[symbol])
    O.append(SYMBOLS_DICT[oppsymbol])
    scores[H[-2]][O[-2]][O[-1]] += 1

    output = symbol
else:
    output = random.choice(SYMBOLS)
cp += 1