Prepare Capital Quest public edition and player manual
This commit is contained in:
1 parent
46f4b9cae0
commit
afa6f3c2a0
40 files changed
+1072
-106
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""Check progress colors in actual guest frames, including enlarged map views."""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
LIGHT = (85, 170, 170)
|
||||
DARK = (85, 85, 170)
|
||||
RED = (255, 85, 85)
|
||||
YELLOW = (255, 255, 0)
|
||||
NORTHEAST = {6, 7, 18, 19, 20, 28, 29, 31, 37, 38, 44}
|
||||
SOURCE = (ROOT / 'src/map_data.c').read_text()
|
||||
|
||||
|
||||
def numbers(pattern):
|
||||
return list(map(int, re.search(pattern, SOURCE)[1].replace('\n', '').split(',')))
|
||||
|
||||
|
||||
GEOMETRY = {
|
||||
view: (numbers(view + r'_spans\[\] = \{\s*([\d,\s]+)'),
|
||||
numbers(view + r'_offsets\[51\] = \{([\d,]+)'))
|
||||
for view in ('national', 'northeast', 'hawaii')
|
||||
}
|
||||
|
||||
|
||||
def check_map_colors(screen, current, outcomes):
|
||||
"""outcomes maps answered state IDs to correctness; None selects title mode."""
|
||||
views = [('national', 6, 33)]
|
||||
if current in NORTHEAST:
|
||||
views.append(('northeast', 211, 42))
|
||||
elif current == 10:
|
||||
views.append(('hawaii', 211, 53))
|
||||
checked = {}
|
||||
for view, ox, oy in views:
|
||||
spans, offsets = GEOMETRY[view]
|
||||
pixels = 0
|
||||
for state in range(50):
|
||||
expected = LIGHT
|
||||
if current is not None:
|
||||
if state == current:
|
||||
expected = YELLOW
|
||||
elif state in outcomes:
|
||||
expected = DARK if outcomes[state] else RED
|
||||
for k in range(offsets[state], offsets[state + 1], 3):
|
||||
y, x, count = spans[k:k + 3]
|
||||
for dx in range(count):
|
||||
xx, yy = ox + x + dx, oy + y
|
||||
# Labels and the northeast overview marker cover map pixels.
|
||||
if view == 'national':
|
||||
if 134 <= yy < 142 and (8 <= xx < 20 or 62 <= xx < 74):
|
||||
continue
|
||||
if current in NORTHEAST and (
|
||||
(xx in (158, 199) and 44 <= yy <= 88) or
|
||||
(yy in (44, 88) and 158 <= xx <= 199)
|
||||
):
|
||||
continue
|
||||
actual = screen.guest(xx, yy)
|
||||
assert actual == expected, (view, state, current, xx, yy, actual, expected)
|
||||
pixels += 1
|
||||
checked[view] = pixels
|
||||
return checked
|
||||
@@ -2,9 +2,10 @@ import os
|
||||
from pathlib import Path
|
||||
import sys,runpy,json,re
|
||||
sys.path.insert(0,str(Path(__file__).parent));from framebuffer import Screen,ROOT,shuffle,EVIDENCE
|
||||
from map_colors import check_map_colors
|
||||
c=runpy.run_path(str(Path(__file__).with_name('playtest_support.py')));run=json.load(open(os.environ['CAPITAL_TEST_STATE']))['run']['run_id']
|
||||
rows=[x.split('\t') for x in (ROOT/'data/states.tsv').read_text().splitlines()]
|
||||
order,_=shuffle();evidence=[];score=0;pos=[0]*4
|
||||
order,_=shuffle();evidence=[];score=0;pos=[0]*4;outcomes={};previous_correctpos=None
|
||||
c['key'](run,'1',8,600)
|
||||
for q,state in enumerate(order):
|
||||
name=f'mc-q{q+1:02d}-{rows[state][0]}'
|
||||
@@ -12,15 +13,19 @@ for q,state in enumerate(order):
|
||||
heading=scr.text(8,19,45);prompt=scr.text(8,145,50)
|
||||
assert heading==f'Question {q+1} of 50 Score {score}',(q,heading,score)
|
||||
assert prompt==f'{rows[state][1]}: what is its capital?',(q,prompt,rows[state])
|
||||
check_map_colors(scr,state,outcomes)
|
||||
opts=[scr.text(8+(i%2)*156,157+(i//2)*12,25)[2:] for i in range(4)]
|
||||
assert len(set(opts))==4 and rows[state][2] in opts,(q,opts)
|
||||
correctpos=opts.index(rows[state][2]);pos[correctpos]+=1
|
||||
assert correctpos!=previous_correctpos,(q,correctpos,previous_correctpos)
|
||||
previous_correctpos=correctpos
|
||||
# Confirm selected state's actual framebuffer mask has the expected gold fill.
|
||||
src=(ROOT/'src/map_data.c').read_text();d=list(map(int,re.search(r'national_spans\[\] = \{\s*([\d,\s]+)',src)[1].replace('\n','').split(',')));off=list(map(int,re.search(r'national_offsets\[51\] = \{([\d,]+)',src)[1].split(',')))
|
||||
points=[(6+x,33+y) for k in range(off[state],off[state+1],3) for y,x0,n in [d[k:k+3]] for x in range(x0,x0+n)]
|
||||
gold=sum(scr.guest(x,y)==(255,255,0) for x,y in points)
|
||||
assert gold>=len(points)*.8,(q,rows[state][0],gold,len(points))
|
||||
right=q%7!=0;selection=correctpos if right else (correctpos+1)%4
|
||||
outcomes[state]=right
|
||||
if right:score+=1
|
||||
# Read the feedback as soon as it appears, before its automatic timeout.
|
||||
held=[str(selection+1)] if q==0 else []
|
||||
@@ -58,7 +63,9 @@ for page in range(3):
|
||||
cap=next(x[2] for x in rows if x[0]==m['code'])
|
||||
assert s.text(8,61+i*43,48)==f'Capital: {cap}'
|
||||
if page<2:c['key'](run,'n',8,500)
|
||||
c['key'](run,'b',8,500);c['key'](run,'p',8,500);c['capture'](run,'replay-title');c['key'](run,'q',8,200);final=c['capture'](run,'mc-exit')
|
||||
c['key'](run,'b',8,500);c['key'](run,'p',8,500);c['capture'](run,'replay-title')
|
||||
check_map_colors(Screen(str(EVIDENCE)+'/replay-title.png'),None,outcomes)
|
||||
c['key'](run,'q',8,200);final=c['capture'](run,'mc-exit')
|
||||
assert 'screen_text' in final or final.get('screen_text_unavailable') is None,final
|
||||
json.dump(dict(score=score,positions=pos,questions=evidence,run_id=run,artifact=result['artifact_id'],exit=final),open(str(EVIDENCE)+'/mc-report.json','w'),indent=2)
|
||||
print('PASS complete multiple-choice quiz, all 50 masks, automatic feedback advance without Space, held-key protection, 42/50, review, replay, exit.',flush=True)
|
||||
|
||||
@@ -3,10 +3,11 @@ from pathlib import Path
|
||||
import runpy,json,sys,uuid
|
||||
from pathlib import Path
|
||||
sys.path.insert(0,str(Path(__file__).parent));from framebuffer import Screen,ROOT,shuffle,EVIDENCE
|
||||
from map_colors import check_map_colors
|
||||
c=runpy.run_path(str(Path(__file__).with_name('playtest_support.py')));state=json.load(open(os.environ['CAPITAL_TEST_STATE']))
|
||||
r=c['call']('start_playtest',dict(project_id=state['cap']['project_id'],revision=state['cap']['revision'],artifact_id=state['artifact']['artifact_id'],request_id=str(uuid.uuid4())))
|
||||
run=r['run_id'];state['typed_run']=r;Path(os.environ['CAPITAL_TEST_STATE']).write_text(json.dumps(state))
|
||||
rows=[x.split('\t') for x in (ROOT/'data/states.tsv').read_text().splitlines()];order,_=shuffle();report=[];score=corrections=0
|
||||
rows=[x.split('\t') for x in (ROOT/'data/states.tsv').read_text().splitlines()];order,_=shuffle();report=[];score=corrections=0;outcomes={}
|
||||
|
||||
def press(k,hold=4,settle=12):return c['key'](run,k,hold,settle)
|
||||
def settle():c['inp'](run,[{'keys':[],'fields':600},{'keys':[],'fields':300}])
|
||||
@@ -24,15 +25,17 @@ settle();c['key'](run,'2',8,600);settle();c['inp'](run,[dict(keys=['shift','0'],
|
||||
# First alias in mixed case. Capture input before submission to verify the real keys.
|
||||
type_text('sT pAuL');s=cap('typed-alias-input');print('input=',s.text(8,158,45),flush=True)
|
||||
assert s.text(8,158,45)=='sT pAuL_',s.text(8,158,45)
|
||||
check_map_colors(s,order[0],outcomes)
|
||||
press('enter',8,600);s=cap('typed-alias-feedback');assert s.text(8,158,30)=='CORRECT!',s.text(8,158,30)
|
||||
c['inp'](run,[dict(keys=[],fields=300)]);s=cap('typed-feedback-waits')
|
||||
assert s.text(8,19,45)=='Question 1 of 50 Score 1'
|
||||
assert s.text(8,183,48)=='Release your key, then SPACE to continue.'
|
||||
score=1;report.append(dict(question=1,code='MN',answer='sT pAuL',correct=True,correction=False));c['key'](run,'space',8,600);settle()
|
||||
score=1;outcomes[order[0]]=True;report.append(dict(question=1,code='MN',answer='sT pAuL',correct=True,correction=False));c['key'](run,'space',8,600);settle()
|
||||
for q in range(1,50):
|
||||
st=order[q];code,name,capital=rows[st];s=cap(f'typed-q{q+1:02d}-{code}')
|
||||
assert s.text(8,19,45)==f'Question {q+1} of 50 Score {score}',(q,s.text(8,19,45),score)
|
||||
assert s.text(8,145,50)==name+': what is its capital?'
|
||||
check_map_colors(s,st,outcomes)
|
||||
spelling=False;right=True
|
||||
if q==1 or code=='CO':
|
||||
# Adjacent transpositions, followed by a real Backspace correction.
|
||||
@@ -64,6 +67,7 @@ for q in range(1,50):
|
||||
assert s.text(8,170,50)==f'The capital is {capital}.'
|
||||
if right:score+=1
|
||||
if spelling:corrections+=1
|
||||
outcomes[st]=right
|
||||
report.append(dict(question=q+1,code=code,answer=answer,correct=right,correction=spelling))
|
||||
c['key'](run,'space',8,600)
|
||||
if q!=49:settle()
|
||||
|
||||
+21
-7
@@ -5,19 +5,33 @@
|
||||
static unsigned index_of(const char *code){unsigned i;for(i=0;i<50;++i)if(!strcmp(states[i].code,code))return i;assert(0);return 0;}
|
||||
int main(void)
|
||||
{
|
||||
unsigned seed,i,j,p,positions[4]={0},last[50],changes=0;
|
||||
unsigned seed,i,j,p,slot,previous,positions[4]={0},first[4]={0};
|
||||
unsigned transitions[4][4]={{0}},last[50],changes=0;
|
||||
U8 first_options[4];
|
||||
char a[160],b[ANSWER_SIZE];
|
||||
for(seed=1;seed<=2000;++seed){
|
||||
unsigned seen[50]={0};quiz_start(seed);
|
||||
unsigned seen[50]={0};quiz_start(seed);previous=4;
|
||||
for(i=0;i<50;++i){
|
||||
assert(order[i]<50);++seen[order[i]];quiz_options(order[i]);p=0;
|
||||
for(j=0;j<4;++j){unsigned k;assert(options[j]<50);if(options[j]==order[i]){++p;++positions[j];}for(k=0;k<j;++k)assert(options[k]!=options[j]);}
|
||||
assert(p==1);if(seed>1 && last[i]!=order[i])++changes;last[i]=order[i];
|
||||
assert(order[i]<50);++seen[order[i]];quiz_options(order[i]);p=0;slot=4;
|
||||
for(j=0;j<4;++j){unsigned k;assert(options[j]<50);if(options[j]==order[i]){++p;++positions[j];slot=j;}for(k=0;k<j;++k)assert(options[k]!=options[j]);}
|
||||
assert(p==1 && slot!=previous);
|
||||
if(i)++transitions[previous][slot];else ++first[slot];
|
||||
previous=slot;
|
||||
if(seed>1 && last[i]!=order[i])++changes;last[i]=order[i];
|
||||
}
|
||||
for(i=0;i<50;++i)assert(seen[i]==1);
|
||||
}
|
||||
for(i=0;i<4;++i)assert(positions[i]>20000);
|
||||
for(i=0;i<4;++i){
|
||||
assert(positions[i]>20000 && first[i]>300);
|
||||
for(j=0;j<4;++j)assert(i==j?transitions[i][j]==0:transitions[i][j]>6000);
|
||||
}
|
||||
assert(changes>90000);
|
||||
/* Replaying a seed must reset the remembered slot as well as the answers. */
|
||||
for(seed=1;seed<=32;++seed){
|
||||
quiz_start(seed);quiz_options(order[0]);memcpy(first_options,options,4);
|
||||
for(i=1;i<50;++i)quiz_options(order[i]);
|
||||
quiz_start(seed);quiz_options(order[0]);assert(!memcmp(first_options,options,4));
|
||||
}
|
||||
for(i=0;i<50;++i){
|
||||
assert(classify(i,states[i].capital)==2);
|
||||
strcpy(a,states[i].capital);
|
||||
@@ -43,6 +57,6 @@ int main(void)
|
||||
for(i=0;i<50;++i)assert(answered[i]==1);
|
||||
quiz_start(2710);assert(score==0 && corrections==0);
|
||||
for(i=0;i<50;++i)assert(!answered[i] && !responses[i][0]);
|
||||
printf("PASS: 2000 shuffles, 100000 option sets, all casing / known-wrong capitals, aliases, distance, bounds, scoring, reset.\n");
|
||||
printf("PASS: 2000 shuffles, 100000 option sets with no repeated correct slot, all 12 allowed slot transitions, replay reset, all casing / known-wrong capitals, aliases, distance, bounds, scoring, reset.\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user