text_plain_output_1.png
import random
rng = random.SystemRandom()
hash1 = 0
hash2 = 0
hash3 = 0
map1 = {}
map2 = {}
map3 = {}
Jmin = 10
Jmax = 20
J = rng.randrange(Jmin, Jmax + 1)
D = 2
G = 3
R = 0.6
B = 0
def add(map1, hash1, A):
    if hash1 not in map1:
        map1[hash1] = {'S': 0}
    d = map1[hash1]
    if A not in d:
        d[A] = 1
    else:
        d[A] += 1
    d['S'] += 1
def match(map1, hash1, S):
    global B
    global J
    if hash1 not in map1:
        return
    d = map1[hash1]
    if d['S'] >= G:
        for A in range(S):
            if A in d and d[A] >= d['S'] * R:
                B = (A + 1) % S
                J = rng.randrange(Jmin, Jmax)
def agent(observation, configuration):
    global B
    global J
    global hash1
    global hash2
    global hash3
    T = observation.step
    S = configuration.signs
    if T > 0:
        A = observation.lastOpponentAction
    if T > D:
        add(map1, hash1, A)
        add(map2, hash2, A)
        add(map3, hash3, A)
    if T > 0:
        hash1 = hash1 // S + A * S ** (D - 1)
        hash2 = hash2 // S + B * S ** (D - 1)
        hash3 = hash3 // S ** 2 + (A + S * B) * S ** (2 * D - 1)
    B = rng.randrange(0, S)
    if J == 0:
        match(map1, hash1, S)
        match(map2, hash2, S)
        match(map3, hash3, S)
    else:
        J -= 1
    return B