Files
Quadrapassel/tools/test_rules.py
T
Brian Holman d412e35c4e Implement CoCo 3 Quadrapassel and deliver build 01
Add gameplay, keyboard/joystick controls, disk-backed high scores and settings,
standard CMOC effects, and the approved C graphics renderer. Include the clearer
attributed font, title/credits updates, source-verified Modern and Classic (40.2)
scoring, meaningful regression fixtures, and recorded guest validation.

Deliver QUADPSL01.DSK with fresh high scores. Retain source, licenses and selected
guest evidence; exclude personal disks, private connections and build scratch.

Host rules/input/persistence/video checks and memory guards pass. Official
512 KB playtests pass the recorded checks; actual 128 KB/physical joystick
qualification and the normal-window buzzing retest remain pending.
2026-11-11 03:14:14 -07:00

39 lines
2.0 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Host regression tests against the repository's authoritative JSON fixtures.
These complement, and never claim to replace, CMOC/CoCo execution.
"""
import json
import math
import subprocess
from pathlib import Path
root = Path(__file__).resolve().parents[1]
out = root / 'test-output' / 'rules'
out.mkdir(parents=True, exist_ok=True)
pieces = json.loads((root / 'docs/reference/pieces.json').read_text())['pieces']
cases = json.loads((root / 'docs/reference/scoring.json').read_text())['cases']
lines = ['/* Generated from committed specification fixtures for this test only. */',
'static const Q16 reference_masks[7][4] = {']
for piece in pieces:
masks = []
for rotation in piece['rotations']:
mask = int(''.join(rotation['rows']).replace('.', '0').replace('#', '1'), 2)
assert mask == int(rotation['mask_hex'], 16)
masks.append('0x%04X' % mask)
lines.append('{' + ','.join(masks) + '},')
lines += ['};', 'typedef struct { int rule,difficulty; Q32 prior; int rows,bottom,level; Q32 points; } ScoreCase;',
'static const ScoreCase score_cases[] = {']
for c in cases:
lines.append('{%d,%d,%dUL,%d,%d,%d,%dUL},' % (
c['rule'] == 'Classic', c['difficulty'], c['prior_lines'], c['rows_cleared'],
c['includes_bottom'], c['expected_level'], c['expected_delta']))
lines += ['};', 'static const Q16 reference_gravity[100] = {',
','.join(str(math.floor(80 + 800 * .75 ** i + .5)) for i in range(100)), '};']
(out / 'reference_cases.h').write_text('\n'.join(lines) + '\n')
subprocess.run(['clang', '-std=c89', '-Wall', '-Wextra', '-Werror', '-pedantic',
'-fsanitize=address,undefined', '-g', '-DQUAD_HOST',
'-I'+str(root/'src/game'), '-I'+str(out),
str(root/'tests/rules_test.c'), str(root/'src/game/rules.c'),
'-o', str(out/'rules_test')], check=True)
subprocess.run([str(out/'rules_test')], check=True)