Spaces:
Running
Running
Commit ·
ea429a1
1
Parent(s): 0706ff5
Fix two bugs reported by pilot participants
Browse filesThe outcome screen could be dismissed by a stray press. A participant
harvesting against the clock is pressing SPACE rapidly and the screen arrives
mid-burst, so the next press cleared it before it could be read and they could
not tell whether they finished in time or earned nothing. That is the one thing
the screen exists to say, and losing it removes the feedback the trial depends
on. SPACE is ignored for the first 700 ms, and the prompt appears only once the
press will do something.
Stalks could be placed behind the partner bubble, where they are drawn over and
can be missed entirely. On an all-or-nothing rule that costs the whole trial.
The nine tiles the bubble covers are excluded from placement, verified over
24,000 placements.
Files changed (2)
- static/cornfield.js+27-3
- test_rest_variety.py+48-1
37 unmodified lines383940414243361 unmodified lines405406407408409410411170 unmodified lines5825835845855865875885891460 unmodified lines2050205120522053205420552056205737 unmodified linesconst W = BOARD_W, H = BOARD_H + HUD;const DEFAULT = { decisionMs: 4000, workMs: 10000, restMs: 10000, feedbackMs: 1800 };const STEP_MS = 110;const C = {361 unmodified linesif (k === " ") doRestAction();else moveStep(k);} else if (trial.phase === "feedback") {if (k === " ") emitResult(); // SPACE to continue past feedback}}170 unmodified linesreturn best;}function scatterCorn(n, player, existing) {const taken = new Set([player.c + "," + player.r]);(existing || []).forEach(k => { if (!k.done) taken.add(k.c + "," + k.r); });const cells = [];for (let r = 0; r < ROWS; r++)1460 unmodified lineswrapText(tip, W / 2, HUD + BOARD_H / 2 + 44, W - 60, 16);}}ctx.fillStyle = "#aeb6c2"; ctx.font = "14px system-ui, sans-serif";ctx.fillText("press SPACE to continue", W / 2, HUD + BOARD_H - 16);}// simple centered word-wrap for teaching tips37 unmodified lines383940414243444546361 unmodified lines408409410411412413414415416417418419420421170 unmodified lines5925935945955965975985996006016026036046056066076086091460 unmodified lines20702071207220732074207520762077207820792080208137 unmodified linesconst W = BOARD_W, H = BOARD_H + HUD;const DEFAULT = { decisionMs: 4000, workMs: 10000, restMs: 10000, feedbackMs: 1800 };//: How long the outcome screen ignores SPACE. Long enough to survive a burst//: of harvesting presses, short enough not to feel stuck.const FEEDBACK_LOCK_MS = 700;const STEP_MS = 110;const C = {361 unmodified linesif (k === " ") doRestAction();else moveStep(k);} else if (trial.phase === "feedback") {// A press cannot dismiss the outcome for the first FEEDBACK_LOCK_MS.//// A participant harvesting against the clock is pressing SPACE rapidly,// and the outcome screen arrives mid-burst: the next press cleared it// before it could be read, so they could not tell whether they finished// in time or earned nothing. That is the one thing the screen exists to// say, and losing it removes the feedback the whole trial depends on.if (k === " " && (now() - trial.feedbackStart) >= FEEDBACK_LOCK_MS) emitResult();}}170 unmodified linesreturn best;}//: Tiles the partner bubble covers in the work scene. A stalk placed here is//: drawn behind the bubble and can be missed entirely, which costs the trial//: on an all-or-nothing rule. Reported by a pilot participant.const PARTNER_TILES = (function () {const out = [];for (let c = 0; c <= 2; c++) for (let r = 7; r <= ROWS - 1; r++) out.push(c + "," + r);return out;})();function scatterCorn(n, player, existing) {const taken = new Set([player.c + "," + player.r]);PARTNER_TILES.forEach(k => taken.add(k));(existing || []).forEach(k => { if (!k.done) taken.add(k.c + "," + k.r); });const cells = [];for (let r = 0; r < ROWS; r++)1460 unmodified lineswrapText(tip, W / 2, HUD + BOARD_H / 2 + 44, W - 60, 16);}}// Only once the press will actually do something, so nobody presses into// a void during the lockout.if ((now() - t.feedbackStart) >= FEEDBACK_LOCK_MS) {ctx.fillStyle = "#aeb6c2"; ctx.font = "14px system-ui, sans-serif";ctx.fillText("press SPACE to continue", W / 2, HUD + BOARD_H - 16);}}// simple centered word-wrap for teaching tips
234 unmodified lines23523623723823924024118 unmodified lines260261262234 unmodified lines}}const consts = 'const COLS=15,ROWS=10,TILE=42,HUD=92,TARGET_STEPS_PER_STALK=5.2;let rnd=Math.random;';const f = new Function(consts + grab('pathLength') + grab('scatterCorn') +grab('scatterCornBalanced') + 'function needsFor(n){return new Array(n).fill(1);}' +'return {plain:scatterCorn, bal:scatterCornBalanced, path:pathLength};')();const p = {c:7, r:8};18 unmodified linesspread_bal = abs(got["3"]["bal_m"] - got["10"]["bal_m"])assert spread_bal < spread_rand / 3, (f"walking distance still slides with effort level: {spread_bal:.2f}")234 unmodified lines23523623723823924024124218 unmodified lines261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309234 unmodified lines}}const consts = 'const COLS=15,ROWS=10,TILE=42,HUD=92,TARGET_STEPS_PER_STALK=5.2;let rnd=Math.random;';const pt = src.match(/(const PARTNER_TILES = \(function \(\) \{[\s\S]*?\}\)\(\);)/)[1];const f = new Function(consts + pt + grab('pathLength') + grab('scatterCorn') +grab('scatterCornBalanced') + 'function needsFor(n){return new Array(n).fill(1);}' +'return {plain:scatterCorn, bal:scatterCornBalanced, path:pathLength};')();const p = {c:7, r:8};18 unmodified linesspread_bal = abs(got["3"]["bal_m"] - got["10"]["bal_m"])assert spread_bal < spread_rand / 3, (f"walking distance still slides with effort level: {spread_bal:.2f}")# --- two bugs reported by pilot participants ---------------------------------def test_outcome_screen_survives_a_burst_of_presses():"""A participant harvesting against the clock is pressing SPACE rapidly,and the outcome screen arrives mid-burst. The next press used to clear itbefore it could be read, so they could not tell whether they finished intime. That is the one thing the screen exists to say."""src = _src()assert "const FEEDBACK_LOCK_MS" in srcassert 'if (k === " " && (now() - trial.feedbackStart) >= FEEDBACK_LOCK_MS)' in src# and the prompt waits too, so nobody presses into a voidassert "if ((now() - t.feedbackStart) >= FEEDBACK_LOCK_MS) {" in srcdef test_no_stalk_is_hidden_behind_the_partner():"""A stalk drawn behind the partner bubble can be missed entirely, and onan all-or-nothing rule that costs the whole trial."""src = _src()assert "const PARTNER_TILES" in srcassert "PARTNER_TILES.forEach(k => taken.add(k));" in src@pytest.mark.skipif(DENO is None, reason="deno not installed")def test_partner_tiles_are_never_used():harness = r"""const src = await Deno.readTextFile('static/cornfield.js');function grab(n){const i=src.indexOf('function '+n+'(');let d=0,st=false;for(let j=i;j<src.length;j++){if(src[j]==='{'){d++;st=true;}else if(src[j]==='}'){d--;if(st&&d===0)return src.slice(i,j+1);}}}const pt = src.match(/(const PARTNER_TILES = \(function \(\) \{[\s\S]*?\}\)\(\);)/)[1];const f = new Function('const COLS=15,ROWS=10,TILE=42,HUD=92,TARGET_STEPS_PER_STALK=5.2;let rnd=Math.random;'+ pt + grab('pathLength') + grab('scatterCorn') + grab('scatterCornBalanced')+ 'function needsFor(n){return new Array(n).fill(1);}'+ 'return {bal:scatterCornBalanced, tiles:PARTNER_TILES};')();let hits = 0, total = 0;for (let i = 0; i < 1200; i++)for (const k of f.bal(8, {c:7, r:4})) { total++; if (f.tiles.includes(k.c+','+k.r)) hits++; }console.log(JSON.stringify({hits: hits, total: total, tiles: f.tiles.length}));"""r = subprocess.run([DENO, "eval", harness], capture_output=True, text=True, timeout=180)assert r.returncode == 0, r.stderr[-600:]got = json.loads(r.stdout)assert got["tiles"] >= 9, "partner footprint looks too small"assert got["hits"] == 0, f"{got['hits']} of {got['total']} stalks hidden behind the partner"
static/cornfield.js+27-3
test_rest_variety.py+48-1