File size: 1,737 Bytes
0a3edb6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Why do entry lanes carry no inferred item? Classify each entry lane by what's
just upstream of its tile in the raster."""
import random, sys, collections
import numpy as np
import pyarrow.parquet as pq
from annotate import LANE, annotate
from corpus.convert import designs, rasterise, to_world, _MASKED, _TERRAIN
STEP = {1: (0, -1), 2: (1, 0), 3: (0, 1), 4: (-1, 0)}
c = collections.Counter()
rows = pq.read_table(sys.argv[1], columns=["string", "modded", "entity_counts"]).to_pylist()
rows = [r for r in rows if not r["modded"] and "assembling-machine" in r["entity_counts"]]
random.Random(0).shuffle(rows)
for row in rows[:120]:
r = rasterise(next(designs(row["string"])))
if r is None:
continue
w = to_world(r)
W, H = r.ent.shape
nodes, demand, supply, succ, pred = annotate(w)
tile_lanes = collections.defaultdict(list)
for i, (k, x, y, lane) in enumerate(nodes):
if k in LANE:
tile_lanes[(x, y)].append(i)
for (x, y), ls in tile_lanes.items():
if any(pred[i] for i in ls):
continue # not an entry tile
d = int(w[1, x, y])
dx, dy = STEP.get(d, (0, 0))
ux, uy = x - dx, y - dy
if not (0 <= ux < W and 0 <= uy < H):
up = "design edge"
elif r.inst[ux, uy] == _MASKED:
up = "masked entity"
elif r.inst[ux, uy] == 0:
up = "empty tile"
elif r.inst[ux, uy] == _TERRAIN:
up = "terrain"
else:
up = "known entity, not connected"
dem = set().union(*(demand[i] for i in ls))
c[(up, "has demand" if dem else "no demand")] += 1
for k, v in sorted(c.items(), key=lambda kv: -kv[1]):
print(f"{k[0]:30s} {k[1]:12s} {v}")
|