Complete Bone Quest high-resolution anatomy quiz
This commit is contained in:
1 parent
3cc37be5fb
commit
2ceb44a48c
62 files changed
+3204
-1301
No files matched your search
+73
-36
@@ -4,6 +4,7 @@ Requires explicitly supplied private ROMs; does not operate the personal emulato
|
||||
"""
|
||||
import argparse,ast,base64,hashlib,json,re,struct,subprocess,zlib
|
||||
from pathlib import Path
|
||||
from check_assets import read_views
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
|
||||
def png(path):
|
||||
@@ -30,11 +31,11 @@ def png(path):
|
||||
|
||||
class Screen:
|
||||
def __init__(self,path,font):self.w,self.h,self.ch,self.rows=png(path);self.font=font
|
||||
def guest(self,x,y):return tuple(self.rows[50+y*2][x*2*self.ch:x*2*self.ch+3])
|
||||
def guest(self,x,y):return tuple(self.rows[16+y*2][x*self.ch:x*self.ch+3])
|
||||
def text(self,x,y,n):
|
||||
bg=self.guest(x+5,y);out=''
|
||||
bg=self.guest(x+10,y);out=''
|
||||
for j in range(n):
|
||||
bits=[self.guest(x+j*6+c,y+r)!=bg for r in range(8) for c in range(5)]
|
||||
bits=[self.guest(x+j*12+c*2,y+r)!=bg for r in range(8) for c in range(5)]
|
||||
scores=[]
|
||||
for k in range(32,127):
|
||||
expected=[not(self.font[(k-32)*8+r]&(128>>c)) for r in range(8) for c in range(5)]
|
||||
@@ -48,7 +49,7 @@ def main():
|
||||
p.add_argument('--rom',type=Path,required=True);p.add_argument('--disk-rom',type=Path,required=True)
|
||||
p.add_argument('--evidence',type=Path,default=ROOT/'test-output/playtest')
|
||||
p.add_argument('--cpu',choices=['6809','6309','both'],default='both');args=p.parse_args();out=args.evidence.resolve();out.mkdir(parents=True,exist_ok=True)
|
||||
rows=json.loads((ROOT/'data/bones.json').read_text());binary=ROOT/'build/BONEQ.bin';disk=ROOT/'build/BONEQ.dsk';sha=hashlib.sha256(disk.read_bytes()).hexdigest()
|
||||
rows=json.loads((ROOT/'data/bones.json').read_text());count=len(rows);binary=ROOT/'build/BONEQ.bin';disk=ROOT/'build/BONEQ.dsk';sha=hashlib.sha256(disk.read_bytes()).hexdigest()
|
||||
mp=binary.with_suffix('.map').read_text();symbols={n:int(a,16) for n,a in re.findall(r'Symbol: _(\w+) .*?= ([0-9A-Fa-f]+)',mp)}
|
||||
blob=binary.read_bytes();memory={};i=0
|
||||
while i<len(blob):
|
||||
@@ -56,8 +57,8 @@ def main():
|
||||
if kind==255:break
|
||||
memory.update((a+j,b) for j,b in enumerate(blob[i:i+n]));i+=n
|
||||
font=bytes(memory[symbols['font5x8']+i] for i in range(768))
|
||||
src=(ROOT/'src/map_data.c').read_text();arrays={name:[int(v) for v in re.findall(r'\d+',body)] for name,body in re.findall(r'(?:unsigned char|unsigned)\s+(\w+)\s*\[[^]]*\]\s*=\s*\{([^{}]*)\}',src)}
|
||||
spans=arrays['bone_spans'];offsets=arrays['bone_offsets'];colors={3:(85,170,170),4:(85,85,170),5:(255,85,85),6:(255,255,0)}
|
||||
views,arrays=read_views();colors={0:(0,0,0),1:(255,255,255),2:(255,255,0),3:(255,0,0)}
|
||||
manifest=json.loads((ROOT/'data/geometry-manifest.json').read_text())
|
||||
b64=lambda path:base64.b64encode(path.read_bytes()).decode();reports=[]
|
||||
for cpu in (('6809','6309') if args.cpu=='both' else (args.cpu,)):
|
||||
proc=subprocess.Popen([str(args.app/'Contents/Helpers/vcc-playtest')],stdin=subprocess.PIPE,stdout=subprocess.PIPE,text=True)
|
||||
@@ -65,7 +66,7 @@ def main():
|
||||
proc.stdin.write(json.dumps(dict(op=op,**kw))+'\n');proc.stdin.flush();r=json.loads(proc.stdout.readline());assert 'error' not in r,r;return r['result']
|
||||
def read(name,n=1):return call('read_memory',address=symbols[name],count=n)['bytes']
|
||||
def step(n=600):return call('input',steps=[dict(mask=0,fields=n)])
|
||||
def press(mask,settle=600,hold=8):return call('input',steps=[dict(mask=mask,fields=hold),dict(mask=0,fields=settle)])
|
||||
def press(mask,settle=600,hold=8):return call('input',steps=[dict(mask=mask,fields=hold)]+([dict(mask=0,fields=settle)] if settle else []))
|
||||
def key(bit,settle=600,hold=8):return press(1<<bit,settle,hold)
|
||||
def type_text(s):
|
||||
steps=[]
|
||||
@@ -78,40 +79,69 @@ def main():
|
||||
r=call('capture');path=out/(cpu+'-'+name+'.png');path.write_bytes(base64.b64decode(r.pop('png_base64')))
|
||||
(out/(cpu+'-'+name+'.json')).write_text(json.dumps(r,indent=2)+'\n');return Screen(path,font)
|
||||
def check_map(s,current,outcomes):
|
||||
checked=0
|
||||
for bone in range(25):
|
||||
col=6 if bone==current else 4 if outcomes.get(bone) is True else 5 if bone in outcomes else 3
|
||||
for j in range(offsets[bone],offsets[bone+1],3):
|
||||
y,x,n=spans[j:j+3]
|
||||
for xx in range(x,x+n):
|
||||
assert s.guest(22+xx,30+y)==colors[col],(cpu,bone,current,xx,y,s.guest(22+xx,30+y),colors[col]);checked+=1
|
||||
assert checked>1000
|
||||
def check_view(view,ox,oy,scale=1,cx=0,cy=0,cw=None,ch=None):
|
||||
w=view['width'];h=view['height'];cw=w if cw is None else cw;ch=h if ch is None else ch
|
||||
expected=[None]*(w*h)
|
||||
for bone,pixels in enumerate(view['layers']):
|
||||
col=0 if bone==count+1 else 2 if bone==current else 3 if outcomes.get(bone) is False else 1
|
||||
for pos in pixels:expected[pos]=colors[col]
|
||||
checked=0
|
||||
for y in range(cy,cy+ch):
|
||||
for x in range(cx,cx+cw):
|
||||
value=expected[y*w+x]
|
||||
if value is None:continue
|
||||
for yy in range(scale):
|
||||
for xx in range(scale):
|
||||
actual=s.guest(ox+(x-cx)*scale+xx,oy+(y-cy)*scale+yy)
|
||||
assert actual==value,(cpu,current,view['name'],x,y,actual,value)
|
||||
checked+=1
|
||||
assert checked>0
|
||||
check_view(views[0],8+(200-views[0]['width'])//2,30)
|
||||
if current is None:return
|
||||
detail=arrays['bone_detail_view'][current]
|
||||
if detail:
|
||||
view=views[detail];check_view(view,224+(400-view['width'])//2,34+(98-view['height'])//2)
|
||||
else:
|
||||
x,y,w,h=manifest['overviewBoxes'][rows[current]['code']]
|
||||
if x>2:x-=2;w+=2
|
||||
else:x=0
|
||||
if y>2:y-=2;h+=2
|
||||
else:y=0
|
||||
w+=2;h+=2;w=min(w,views[0]['width']-x);h=min(h,views[0]['height']-y)
|
||||
scale=max(1,min(4,98//h))
|
||||
if w*scale>400:scale=400//w
|
||||
check_view(views[0],224+(400-w*scale)//2,34+(98-h*scale)//2,scale,x,y,w,h)
|
||||
def ready(phase,q=None):
|
||||
for _ in range(120):
|
||||
if read('phase')==[phase] and (q is None or read('question')==[q]):return
|
||||
step(30)
|
||||
raise AssertionError(('Screen did not finish',cpu,phase,q,read('phase'),read('question')))
|
||||
def sound(name):
|
||||
r=call('audio_capture',fields=120);wav=base64.b64decode(r['audio_wav_base64']);(out/(cpu+'-'+name+'.wav')).write_bytes(wav)
|
||||
assert any(wav[44:]),'No guest audio samples'
|
||||
call('init',system_rom=b64(args.rom),disk_rom=b64(args.disk_rom),disk=b64(disk),cpu=cpu,boot_keys=[1<<b for b in (4,15,19,48)])
|
||||
step();check_map(capture('title'),None,{})
|
||||
key(3);s=capture('credits');assert s.text(8,42,45)=='Skeleton: Mariana Ruiz Villarreal';key(31);key(33)
|
||||
step();ready(0);s=capture('title');check_map(s,None,{});assert s.text(224,35,34)==f'{count} STRUCTURES'
|
||||
key(3);s=capture('credits');assert s.text(16,42,45)=='Skeleton: Mariana Ruiz Villarreal';key(31);key(33)
|
||||
outcomes={};slots=[];visited=[]
|
||||
for q in range(25):
|
||||
assert read('phase')==[1] and read('question')==[q]
|
||||
for q in range(count):
|
||||
ready(1,q);assert read('phase')==[1] and read('question')==[q]
|
||||
bone=read('current_bone')[0];s=capture('mc-%02d-%s'%(q+1,rows[bone]['code']));check_map(s,bone,outcomes)
|
||||
assert s.text(8,19,45)==f'Question {q+1}/25 Score {sum(outcomes.values())}'
|
||||
opts=[s.text(112,132+i*11,34)[2:] for i in range(4)];assert len(set(opts))==4 and rows[bone]['name'] in opts,(q,opts)
|
||||
assert s.text(16,19,45)==f'Question {q+1}/{count} Score {sum(outcomes.values())}'
|
||||
opts=[s.text(224,168+i*11,34)[2:] for i in range(4)];assert len(set(opts))==4 and rows[bone]['name'] in opts,(q,opts)
|
||||
slot=opts.index(rows[bone]['name']);assert not slots or slot!=slots[-1];slots.append(slot);visited.append(bone)
|
||||
right=q%5!=0;selection=slot if right else (slot+1)%4
|
||||
right=q not in (0,5,10,15,20);selection=slot if right else (slot+1)%4
|
||||
if q==0:
|
||||
# Hold through feedback and the next question; only one answer.
|
||||
press(1<<(33+selection),600,600);assert read('question')==[1];step(16)
|
||||
else:key(33+selection)
|
||||
outcomes[bone]=right
|
||||
if q%5==0:print(cpu,'multiple choice',q+1,flush=True)
|
||||
assert len(set(visited))==25 and read('phase')==[4]
|
||||
s=capture('mc-results');check_map(s,None,outcomes);assert s.text(112,55,34)=='20 / 25 correct 80%'
|
||||
key(18);s=capture('mc-review');assert s.text(8,39,45)==rows[visited[0]]['name'];key(14);capture('mc-review-next');key(2);key(16);check_map(capture('replay-title'),None,{})
|
||||
ready(4);assert len(set(visited))==count and read('phase')==[4]
|
||||
s=capture('mc-results');check_map(s,None,outcomes);assert s.text(224,55,34)==f'{count-5} / {count} correct {(count-5)*100//count}%'
|
||||
key(18);ready(6);s=capture('mc-review');assert s.text(16,39,45)==rows[visited[0]]['name'];key(14);capture('mc-review-next');key(2);key(16);ready(0);check_map(capture('replay-title'),None,{})
|
||||
key(34);press((1<<55)|(1<<32),16);outcomes={};typed=[];corrections=0
|
||||
for q in range(25):
|
||||
assert read('phase')==[1] and read('question')==[q]
|
||||
for q in range(count):
|
||||
ready(1,q);assert read('phase')==[1] and read('question')==[q]
|
||||
bone=read('current_bone')[0];name=rows[bone]['name'];s=capture('typed-%02d-%s'%(q+1,rows[bone]['code']));check_map(s,bone,outcomes)
|
||||
right=q not in (2,3,4,5,6)
|
||||
if q==0:
|
||||
@@ -122,26 +152,33 @@ def main():
|
||||
elif q==1:
|
||||
type_text(rows[bone]['aliases'][0] if rows[bone]['aliases'] else name);capture('typed-alias')
|
||||
elif q==3:
|
||||
key(50)
|
||||
pass # Blank Enter now reveals; Break is a global quit key.
|
||||
elif q==4:
|
||||
type_text('X'*33);type_text('XXXXXX');step();s=capture('input-limit');assert s.text(112,132,34)=='X'*33+'_'
|
||||
type_text('X'*33);type_text('XXXXXX');step();s=capture('input-limit');assert s.text(224,168,34)=='X'*33+'_'
|
||||
elif q==5:pass
|
||||
elif q in (2,6):
|
||||
other=rows[(bone+1)%25];type_text(other['aliases'][0] if q==6 and other['aliases'] else other['name'])
|
||||
other=rows[(bone+1)%count];type_text(other['aliases'][0] if q==6 and other['aliases'] else other['name'])
|
||||
else:
|
||||
text=' '.join(name.split());text=(' '+text.replace(' ',' ')+' ') if q%3==0 else text.lower() if q%3==1 else text.upper();type_text(text)
|
||||
if q!=3:key(48)
|
||||
if q in (0,2):
|
||||
key(48,0)
|
||||
for _ in range(1200):
|
||||
if read('phase')==[3]:break
|
||||
step(1)
|
||||
assert read('phase')==[3]
|
||||
sound('correct-feedback' if right else 'incorrect-feedback');step()
|
||||
else:key(48)
|
||||
s=capture('typed-feedback-%02d'%(q+1));assert read('phase')==[3]
|
||||
assert s.text(112,134,30)==('CORRECT!' if right else 'NOT THIS TIME.'),(q,name,s.text(112,134,30))
|
||||
assert s.text(224,170,30)==('CORRECT!' if right else 'NOT THIS TIME.'),(q,name,s.text(224,170,30))
|
||||
outcomes[bone]=right;typed.append(bone);assert read('score')==[sum(outcomes.values())]
|
||||
key(31)
|
||||
if q%5==0:print(cpu,'typed',q+1,flush=True)
|
||||
assert len(set(typed))==25 and read('phase')==[4]
|
||||
s=capture('typed-results');check_map(s,None,outcomes);assert s.text(112,55,34)=='20 / 25 correct 80%';assert s.text(112,77,34)=='1 spelling corrections'
|
||||
key(18);s=capture('typed-review');assert s.text(8,39,45)==rows[typed[2]]['name'];key(2);key(17)
|
||||
ready(4);assert len(set(typed))==count and read('phase')==[4]
|
||||
s=capture('typed-results');check_map(s,None,outcomes);assert s.text(224,55,34)==f'{count-5} / {count} correct {(count-5)*100//count}%';assert s.text(224,77,34)=='1 spelling corrections'
|
||||
key(18);ready(6);s=capture('typed-review');assert s.text(16,39,45)==rows[typed[2]]['name'];key(50)
|
||||
s=capture('exit');r=call('capture');assert 'THANKS FOR PLAYING BONE QUEST!' in r.get('screen_text','')
|
||||
final=call('stop');final.pop('disk_base64',None);proc.wait(timeout=10)
|
||||
assert final['disk_writes']==0 and final['disk_sha256']==sha
|
||||
reports.append(dict(cpu=cpu,ramKB=512,multipleChoice=25,typed=25,score=20,spellingCorrections=1,mapPixelsChecked=True,noRepeatedCorrectSlots=True,heldKey=True,review=True,replay=True,exit=True,diskSHA256=sha,diskWrites=0))
|
||||
reports.append(dict(cpu=cpu,ramKB=512,multipleChoice=count,typed=count,score=count-5,spellingCorrections=1,mapPixelsChecked=True,detailPixelsChecked=True,feedbackAudio=True,noRepeatedCorrectSlots=True,heldKey=True,review=True,replay=True,exit=True,diskSHA256=sha,diskWrites=0))
|
||||
(out/'report.json').write_text(json.dumps(reports,indent=2)+'\n');print('PASS',cpu,'complete quizzes, map/colors/choices/input/review/replay/exit',flush=True)
|
||||
if __name__=='__main__':main()
|
||||
Reference in new issue
Block a user