text_plain_output_1.png
import secrets
import math
Jmax = 2
J = Jmax - int(math.sqrt(secrets.randbelow((Jmax + 1) ** 2)))
Dmin = 2
Dmax = 5
Hash = []
Map = []
MyMap = []
for D in range(Dmin, Dmax + 1):
    Hash.append([0, 0, 0])
    Map.append([{}, {}, {}])
    MyMap.append([{}, {}, {}])
G = 2
R = 0.4
V = 0.8
VM = 0.95
B = 0
DT = 200
def add(map1, hash1, A, T):
    if hash1 not in map1:
        map1[hash1] = {'S': []}
    d = map1[hash1]
    if A not in d:
        d[A] = [T]
    else:
        d[A].append(T)
    d['S'].append(T)
def rank(A, T):
    return len([a for a in A if a > T - DT])
def match(map1, hash1, S, T):
    global B
    global J
    if hash1 not in map1:
        return
    d = map1[hash1]
    if rank(d['S'], T) >= G:
        for A in range(S):
            if A in d and rank(d[A], T) >= rank(d['S'], T) * R + (1 - R) * G and (secrets.randbelow(1001) < 1000 * V):
                if secrets.randbelow(1001) < 1000 * VM:
                    B = (A + 1) % S
                else:
                    B = A % S
                J = Jmax - int(math.sqrt(secrets.randbelow((Jmax + 1) ** 2)))
def agent(observation, configuration):
    global B
    global J
    T = observation.step
    S = configuration.signs
    if T > 0:
        A = observation.lastOpponentAction
    BA = (B + 1) % S
    B = secrets.randbelow(S)
    for D in range(Dmin, Dmax + 1):
        if T > D:
            add(Map[D - Dmin][0], Hash[D - Dmin][0], A, T)
            add(Map[D - Dmin][1], Hash[D - Dmin][1], A, T)
            add(Map[D - Dmin][2], Hash[D - Dmin][2], A, T)
            add(MyMap[D - Dmin][0], Hash[D - Dmin][0], BA, T)
            add(MyMap[D - Dmin][1], Hash[D - Dmin][1], BA, T)
            add(MyMap[D - Dmin][2], Hash[D - Dmin][2], BA, T)
        if T > 0:
            Hash[D - Dmin][0] = Hash[D - Dmin][0] // S ** 2 + (A + S * B) * S ** (2 * D - 1)
            Hash[D - Dmin][1] = Hash[D - Dmin][1] // S + A * S ** (D - 1)
            Hash[D - Dmin][2] = Hash[D - Dmin][2] // S + B * S ** (D - 1)
        if J == 0:
            match(Map[D - Dmin][0], Hash[D - Dmin][0], S, T)
            match(Map[D - Dmin][1], Hash[D - Dmin][1], S, T)
            match(Map[D - Dmin][2], Hash[D - Dmin][2], S, T)
        if J == 0:
            match(MyMap[D - Dmin][0], Hash[D - Dmin][0], S, T)
            match(MyMap[D - Dmin][1], Hash[D - Dmin][1], S, T)
            match(MyMap[D - Dmin][2], Hash[D - Dmin][2], S, T)
    if J > 0:
        J -= 1
    return B