def run(seed=1, ticks=100): print('#', seed) rseed(seed) w = o(now=0) while w.now < ticks: alive = False for machine in shuffle(Machine.Factory): if not machine.here.stop(): alive = True w.now += 1 machine.step(w) Machine.report(machine.name) break if not alive: break return w
def scores(i): def p(y) : return int(100*y + 0.5) def n(y) : return int(y) pd = pf = pn = prec = g = f = acc = 0 out = {} for x in i.known: a= i.a[x]; b= i.b[x]; c= i.c[x]; d= i.d[x] if (b+d) : pd = d / (b+d) if (a+c) : pf = c / (a+c) if (a+c) : pn = (b+d) / (a+c) if (c+d) : prec = d / (c+d) if (1-pf+pd): g = 2*(1-pf)*pd / (1-pf+pd) if (prec+pd): f = 2*prec*pd/(prec+pd) if (i.yes + i.no): acc= i.yes/(i.yes+i.no) out[x] = o(db=i.db, rx=i.rx, yes= n(b+d), all=n(a+b+c+d), a=n(a), b=n(b), c=n(c), d=n(d), acc=p(acc), pd=p(pd), pf=p(pf), prec=p(prec), f=p(f), g=p(g),x=x) return out
def scores(i): def p(y): return int(100 * y + 0.5) def n(y): return int(y) pd = pf = pn = prec = g = f = acc = 0 out = {} for x in i.known: a = i.a[x] b = i.b[x] c = i.c[x] d = i.d[x] if (b + d): pd = d / (b + d) if (a + c): pf = c / (a + c) if (a + c): pn = (b + d) / (a + c) if (c + d): prec = d / (c + d) if (1 - pf + pd): g = 2 * (1 - pf) * pd / (1 - pf + pd) if (prec + pd): f = 2 * prec * pd / (prec + pd) if (i.yes + i.no): acc = i.yes / (i.yes + i.no) out[x] = o(db=i.db, rx=i.rx, yes=n(b + d), all=n(a + b + c + d), a=n(a), b=n(b), c=n(c), d=n(d), acc=p(acc), pd=p(pd), pf=p(pf), prec=p(prec), f=p(f), g=p(g), x=x) return out
def transistion(here,gaurd,there): "No methods inside T. just use 'o'" return o(here=here,gaurd=gaurd,there=there)
def T(i,here,gaurd,there): i.trans(o(here=here, gaurd=gaurd,there=there))
def __init__(i, my=o(max=256), n=0, s=""): i.n, i.at, i.txt, i._all = 0, n, s, [] i.old, i.max, i.lo, i.hi = True, my.max, 1E32, -1E32 i.w= -1 if "-" in s else 1
def trans(i, go,gaurd,end): tran.here.out += [o(here = i.find(go), gaurd = gaurd, there = i.find(end))]