Spaces:
Running
Night 2 told everyone their partner's credits were their own
Browse filesNight 2's trials carry beneficiary="conflict" for the whole block, because
who is paid is decided by the choice rather than by the trial. Every screen
asked `beneficiary === "other"` and so answered "YOU" on both options: a
participant who left the harvest in their partner's pocket was told the
credits were theirs, on the one block whose whole question is whom you choose
to pay. _bank_credits had it right, so only the display was wrong, but the
display is what the next choice is made from.
One predicate now answers it, for the work banner, the outcome screen and the
partner's award aura alike.
Also renames the night-2 intro from "Night 2" to "Night Harvest": most
participants run one night block, and the both-nights arm is counterbalanced,
so the condition number is not the position the screen appears in.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Files changed (3)
- effort_stages.py+4-1
- static/cornfield.js+17-4
- test_night_feedback.pyAdded+115
859 unmodified lines860861862863864865866859 unmodified lines)else:intro = (f"## 🌙 Night {which} — whose pocket?\n\n"f"Another night, and again **your partner is asleep**.\n\n"f"This time you're going to their field either way — the only question is "f"**where the {th['target']} ends up**. Put it in **your own pocket**, or "859 unmodified lines860861862863864865866867868869859 unmodified lines)else:intro = (# Not "Night 2": most participants run one night block, and# the 'both' arm is counterbalanced, so the condition number is# not the position this screen appears in.f"## 🌙 Night Harvest — whose pocket?\n\n"f"Another night, and again **your partner is asleep**.\n\n"f"This time you're going to their field either way — the only question is "f"**where the {th['target']} ends up**. Put it in **your own pocket**, or "
1050 unmodified lines105110521053105410551056105745 unmodified lines1103110411051106110711081109111011111112111311141115919 unmodified lines20352036203720382039204032 unmodified lines20732074207520762077207820791050 unmodified lines// second character standing in the field.// bottom left, out of the way of the field the participant walksif (t && t.kind === "trial")drawPartnerBubble(t, 56, HUD + BOARD_H - 52, t.beneficiary === "other");}function glowActive() { return trial && trial.fx && trial.fx.glow && (now() - trial.fx.glow < 280); }45 unmodified linesctx.fillStyle = "#1c130f"; ctx.fillRect(0, 0, W, HUD);if (!isCalib) { ctx.fillStyle = accentFor(t); ctx.fillRect(0, 0, W, 6); }ctx.textAlign = "left"; ctx.fillStyle = C.white; ctx.font = "bold 18px system-ui, sans-serif";const forWho = t.beneficiary === "other" ? "your PARTNER" : "YOU";const lx = (t.teach && !isCalib) ? 116 : 18; // make room for the PRACTICE badgeconst verbCap = th.verb.charAt(0).toUpperCase() + th.verb.slice(1);ctx.fillText(isCalib ? (verbCap + " as much as you can!") : "WORK for ", lx, 28);if (!isCalib) {const lead = ctx.measureText("WORK for ").width;ctx.fillStyle = accentFor(t); ctx.fillText(forWho, lx + lead, 28);ctx.fillStyle = "#c9b8a8"; ctx.font = "13px system-ui, sans-serif";ctx.fillText("press SPACE on each " + th.targetOne + " · " + t.reward + " " + creditsWord(t.reward) + " for " +t.required + " " + th.target, 18, 50);919 unmodified lines}// ---- HUD bits --------------------------------------------------------------//: The green/blue accent means "who this round pays". At night nobody else//: is paid, so a muted night accent rather than the day task's green.function accentFor(t) {32 unmodified linesfunction drawFeedback(t) {ctx.fillStyle = "rgba(10,14,22,0.72)"; ctx.fillRect(0, HUD, W, BOARD_H);ctx.textAlign = "center";const earned = t.credits > 0, who = t.beneficiary === "other" ? "YOUR PARTNER" : "YOU";let msg;if (t.outcome === "work_fail") msg = "Didn't finish in time!";else if (t.credits === 1) msg = "+" + t.credits + " credit";1050 unmodified lines105110521053105410551056105745 unmodified lines1103110411051106110711081109111011111112111311141115919 unmodified lines203520362037203820392040204120422043204420452046204720482049205020512052205332 unmodified lines20862087208820892090209120921050 unmodified lines// second character standing in the field.// bottom left, out of the way of the field the participant walksif (t && t.kind === "trial")drawPartnerBubble(t, 56, HUD + BOARD_H - 52, paysOther(t));}function glowActive() { return trial && trial.fx && trial.fx.glow && (now() - trial.fx.glow < 280); }45 unmodified linesctx.fillStyle = "#1c130f"; ctx.fillRect(0, 0, W, HUD);if (!isCalib) { ctx.fillStyle = accentFor(t); ctx.fillRect(0, 0, W, 6); }ctx.textAlign = "left"; ctx.fillStyle = C.white; ctx.font = "bold 18px system-ui, sans-serif";const forWho = paysOther(t) ? "your PARTNER" : "YOU";const lx = (t.teach && !isCalib) ? 116 : 18; // make room for the PRACTICE badgeconst verbCap = th.verb.charAt(0).toUpperCase() + th.verb.slice(1);ctx.fillText(isCalib ? (verbCap + " as much as you can!") : "WORK for ", lx, 28);if (!isCalib) {const lead = ctx.measureText("WORK for ").width;ctx.fillStyle = whoColor(t); ctx.fillText(forWho, lx + lead, 28);ctx.fillStyle = "#c9b8a8"; ctx.font = "13px system-ui, sans-serif";ctx.fillText("press SPACE on each " + th.targetOne + " · " + t.reward + " " + creditsWord(t.reward) + " for " +t.required + " " + th.target, 18, 50);919 unmodified lines}// ---- HUD bits --------------------------------------------------------------//: Who this trial actually pays. Night 2 decides it from the CHOICE, not//: from the trial: its `beneficiary` is "conflict" for the whole block, so//: reading beneficiary === "other" made every night-2 outcome screen say//: "for YOU" even when the credits had gone to the partner -- the one thing//: that block asks about, reported backwards. The accounting in//: _bank_credits was right all along; only the screen was wrong.function paysOther(t) {if (!t) return false;if (t.night === 2) return t.choice === "work_partner";return t.beneficiary === "other";}function whoColor(t) { return paysOther(t) ? C.otherAccent : C.youAccent; }//: The green/blue accent means "who this round pays". At night nobody else//: is paid, so a muted night accent rather than the day task's green.function accentFor(t) {32 unmodified linesfunction drawFeedback(t) {ctx.fillStyle = "rgba(10,14,22,0.72)"; ctx.fillRect(0, HUD, W, BOARD_H);ctx.textAlign = "center";const earned = t.credits > 0, who = paysOther(t) ? "YOUR PARTNER" : "YOU";let msg;if (t.outcome === "work_fail") msg = "Didn't finish in time!";else if (t.credits === 1) msg = "+" + t.credits + " credit";
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115"""Night 2 has to say who was actually paid.
Its trials carry beneficiary="conflict" for the whole block, because who getsthe credits is decided by the choice rather than by the trial. Every screenthat asked `beneficiary === "other"` therefore answered "YOU" on both options,so a participant who left the harvest in their partner's pocket was told"0 credits for YOU" / "+N credits for YOU". The bank had it right; only thescreen was wrong, which on the one block that measures whom you choose to payis the worst place for it.
The test plays the real trial through deno with a recording canvas, so itreads whatever the shipped screens actually paint."""import jsonimport shutilimport subprocess
import pytest
DENO = shutil.which("deno")pytestmark = pytest.mark.skipif(DENO is None, reason="deno not installed")
HARNESS = r"""function noop() {}let texts = [];function makeFakeCtx() { return { fillRect: noop, strokeRect: noop, clearRect: noop, beginPath: noop, closePath: noop, moveTo: noop, lineTo: noop, quadraticCurveTo: noop, arcTo: noop, arc: noop, ellipse: noop, stroke: noop, fill: noop, save: noop, restore: noop, translate: noop, rotate: noop, setLineDash: noop, drawImage: noop, clip: noop, scale: noop, fillText: (t) => texts.push(String(t)), strokeText: (t) => texts.push(String(t)), measureText: () => ({ width: 0 }), createLinearGradient: () => ({ addColorStop: noop }), createRadialGradient: () => ({ addColorStop: noop }), };}function makeFakeElement() { return { width: 0, height: 0, id: "", tabIndex: 0, style: {}, innerHTML: "", appendChild: noop, focus: noop, addEventListener: noop, getBoundingClientRect: () => ({ left: 0, top: 0, width: 0, height: 0 }), getContext: () => makeFakeCtx() };}globalThis.document = { getElementById: () => makeFakeElement(), createElement: () => makeFakeElement(), addEventListener: noop };globalThis.window = globalThis;const keyHandlers = [];globalThis.addEventListener = (n, f) => { if (n === "keydown") keyHandlers.push(f); };if (!globalThis.performance || !globalThis.performance.now) { globalThis.performance = { now: () => Date.now() };}// a real animation loop, so the work phase can time out on its ownglobalThis.requestAnimationFrame = (f) => setTimeout(() => f(Date.now()), 16);globalThis.cancelAnimationFrame = (h) => clearTimeout(h);let emitted = null;globalThis.emitEvent = (name, data) => { emitted = { name, data }; };
await import("./static/cornfield.js");window.Cornfield.configure({ avatar: 0, partnerName: "P2", theme: "harvest" });window.Cornfield.mount("c");
const press = (k) => keyHandlers.forEach(f => f({ key: k, preventDefault: noop, stopPropagation: noop }));const wait = (ms) => new Promise(r => setTimeout(r, ms));
// Night 2, "left" is the work side, so ArrowLeft = your own pocket and// ArrowRight = your partner's. A 120 ms work phase runs out by itself, which// puts the trial on the outcome screen without needing to walk the field.const SPEC = { beneficiary: "conflict", workSide: "left", night: 2, reward: 8, partnerReward: 4, required: 3, restCredit: null, timeOfDay: "night", workMs: 120, seed: 5 };
const out = {};for (const [label, key] of [["own", "ArrowLeft"], ["partner", "ArrowRight"]]) { window.Cornfield.startTrial(Object.assign({ trialIndex: 0 }, SPEC)); press(key); await wait(700); // 420 ms hand-off + the 120 ms work phase texts = []; await wait(120); // one or more feedback frames out[label] = { drawn: texts.slice(), choice: emitted && emitted.name }; window.Cornfield.stop();}console.log(JSON.stringify(out));"""
@pytest.fixture(scope="module")def played(): r = subprocess.run([DENO, "run", "--allow-read", "-"], input=HARNESS, capture_output=True, text=True, timeout=120) assert r.returncode == 0, r.stderr[-1500:] return json.loads(r.stdout.strip().splitlines()[-1])
def _joined(played, key): return " | ".join(played[key]["drawn"])
def test_the_outcome_screen_is_actually_reached(played): """Without this the two tests below would pass on an empty canvas.""" for key in ("own", "partner"): assert "Didn't finish in time!" in _joined(played, key), _joined(played, key)
def test_pocketing_it_yourself_says_you(played): text = _joined(played, "own") assert "0 credits for YOU" in text, text
def test_leaving_it_with_your_partner_says_your_partner(played): text = _joined(played, "partner") assert "0 credits for YOUR PARTNER" in text, text assert "0 credits for YOU |" not in text