#!/usr/bin/env python3 """Compare Rust structure starts (chunkgen_bench --starts) with the vanilla oracle. usage: compare_structure_starts.py VANILLA RUST [--all] Pieces are compared by type, bounding box and (for jigsaw pieces) position, rotation, ground level delta and junction count. Without --all, vanilla starts of structure types Rust does not generate yet are only counted. """ import collections import sys def load(path): starts = {} current = None for line in open(path): t = line.split() if not t: continue if t[0] == 'start': current = (int(t[1]), int(t[2]), t[3]) starts[current] = [' '.join(t[4:])] elif t[0] == 'piece' and current: starts[current].append(' '.join(t[1:14])) return starts def main(): vanilla, rust = load(sys.argv[1]), load(sys.argv[2]) generated = {k[2] for k in rust} matched = 0 missing = collections.Counter() for key in sorted(vanilla): if key not in rust: missing[key[2]] += 1 if key[2] in generated or '--all' in sys.argv: print('missing', key) continue if vanilla[key] == rust[key]: matched += 1 continue v, r = vanilla[key], rust[key] print('DIFF', key, 'pieces', len(v) - 1, len(r) - 1) for i, (a, b) in enumerate(zip(v, r)): if a != b: print(' first difference at line', i, '\n vanilla', a, '\n rust ', b) break for key in sorted(set(rust) - set(vanilla)): print('extra', key) print(f'{matched} of {len(vanilla)} vanilla starts match exactly; not generated by Rust:', dict(missing)) return 0 if matched == len(rust) == sum(1 for k in vanilla if k[2] in generated) else 1 if __name__ == '__main__': sys.exit(main())