TreasureHuntForTwo / docs /make_overview_doc.py
princessamygdala's picture
Claude Opus 5
Deploy: no em dashes, in the participant copy too
e8598c4
Raw History Blame Contribute Delete
16.2 kB
import re, sys
from docx import Document
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
import experiment_structure as E
QSRC = open("questionnaires.py").read()
doc = Document()
for s in doc.sections:
s.top_margin = s.bottom_margin = Inches(0.75); s.left_margin = s.right_margin = Inches(0.9)
doc.styles["Normal"].font.name = "Calibri"; doc.styles["Normal"].font.size = Pt(10.5)
NAVY = RGBColor(0x1F, 0x38, 0x64)
def H(t, lvl=1):
h = doc.add_heading(t, level=lvl)
for r in h.runs: r.font.color.rgb = NAVY
def md(par, text, size=10.5):
"""render **bold** markdown inline"""
for i, chunk in enumerate(re.split(r"\*\*(.+?)\*\*", text)):
r = par.add_run(chunk); r.bold = bool(i % 2); r.font.size = Pt(size)
def P(t, italic=False, size=10.5, style=None):
p = doc.add_paragraph(style=style); md(p, t, size)
for r in p.runs: r.italic = r.italic or italic
return p
def figure(path, caption, width=5.4):
doc.add_picture(path, width=Inches(width))
doc.paragraphs[-1].alignment = WD_ALIGN_PARAGRAPH.CENTER
c = doc.add_paragraph(); c.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = c.add_run(caption); r.italic = True; r.font.size = Pt(9); r.font.color.rgb = RGBColor(0x55,0x55,0x55)
def kvtable(rows, w=(1.9, 4.2)):
t = doc.add_table(rows=0, cols=2); t.style = "Light Grid Accent 1"
for a, b in rows:
c = t.add_row().cells; c[0].text = a; md(c[1].paragraphs[0], b)
for run in c[0].paragraphs[0].runs: run.bold = True
for cell, ww in zip(c, w): cell.width = Inches(ww)
doc.add_paragraph()
def gridtable(header, rows, widths):
t = doc.add_table(rows=1, cols=len(header)); t.style = "Light Grid Accent 1"
for c, txt, ww in zip(t.rows[0].cells, header, widths):
c.text = txt; c.width = Inches(ww)
for r in c.paragraphs[0].runs: r.bold = True
for row in rows:
cells = t.add_row().cells
for c, txt, ww in zip(cells, row, widths):
md(c.paragraphs[0], str(txt)); c.width = Inches(ww)
doc.add_paragraph()
def bullets(items):
for it in items:
P(it, style="List Bullet")
def clean(block):
return [l.strip() for l in block.strip().splitlines() if l.strip()]
# ================================================================== title
ti = doc.add_heading("Prosocial Learning Task, “Treasure Hunt for Two”", level=0)
for r in ti.runs: r.font.color.rgb = NAVY
P("Task instructions, comprehension quiz and post-task measures · 16-trial version", italic=True, size=11)
doc.add_paragraph()
kvtable([
("Task / build", "TreasureHuntForTwo (task_sl-cu-nicewebrl, 16-trial variant), NiceWebRL browser game"),
("Paradigm", "Adapted from Rhoads et al. (2025), Nature Communications, see References"),
("Population", "SONA pilot: adults, single group. Parent/child dyad features are off unless the session URL carries **?dyad_mode=yes**."),
("Platform", "Desktop or laptop browser only; physical keyboard required (arrow keys + spacebar). Full-screen."),
("Structure", "12 houses × 16 tries = 192 main trials, plus a 6-trial guided practice"),
("Response", "Mouse for setup / instructions / quiz / questionnaires; arrow keys and spacebar during gameplay"),
("Duration", "To be confirmed by piloting"),
])
# ================================================================== 1
H("1. What the task is", 1)
P("The participant is an explorer who walks around a world and enters houses. Inside each house "
"there are two treasure chests, and the participant repeatedly chooses one to open. Every chest "
"opening produces two outcomes at once: coins for the participant (“YOU”) and coins for a "
"partner (“PARTNER”). Some chests tend to pay the participant, some the partner, some both, "
"some neither.")
P("By learning which chests pay off, for themselves versus for someone else, the task measures "
"value-based reinforcement learning and how a participant weighs reward to self against reward "
"to another person. The four chest types correspond to the four outcome scenarios in the source "
"paradigm: mutually beneficial, instrumentally harmful, altruistic and mutually costly.")
P("The partner is an anonymous, fictitious stranger who does not play and is never observed. There "
"is no real second participant and no observational learning. The partner appears only as a "
"non-interactive companion figure and a four-digit “community-database” code shown during the "
"instructions.", italic=True)
H("2. Design at a glance", 1)
gridtable(["Chest profile", "For YOU", "For PARTNER", "Scenario"],
[["A", "good", "good", "mutually beneficial"],
["B", "good", "bad", "instrumentally harmful"],
["C", "bad", "good", "altruistic"],
["D", "bad", "bad", "mutually costly"]],
[1.1, 1.0, 1.2, 2.3])
P("Each house presents one pair of profiles. The six possible pairs (AB, AC, AD, BC, BD, CD) each "
"appear in two houses, giving 12 houses. Outcomes use exact counts rather than random sampling, "
"so every participant faces identical objective reward rates. Over the 16 tries in a house each "
"chest delivers, separately for the participant and for the partner:")
kvtable([("12 of 16 (75%)", "the chest's usual result (**+10** coins if good for that person, **−10** if bad)"),
("2 of 16 (12.5%)", "the opposite result"),
("2 of 16 (12.5%)", "nothing (**0** coins)")])
P("The order of those 16 outcomes is shuffled, so each individual try is unpredictable and the "
"chest simply feels roughly 75% reliable. Coins convert to money at the end (about $1 per 100 "
"coins, up to $6), paid to both the participant and the partner as a bonus.")
# ================================================================== 3 figures
doc.add_page_break()
H("3. What the participant sees", 1)
figure("docs/figures/01_overworld.png", "Figure 1. The world. The participant walks with the arrow keys and steps onto a house to go inside.")
figure("docs/figures/05_practice.png", "Figure 2. Guided practice (6 trials). The participant is told which chest to open and only that chest opens.")
figure("docs/figures/02_choice.png", "Figure 3. A choice. Left or right arrow key opens one of the two chests. The YOU and PARTNER figures stand below.")
figure("docs/figures/03_outcome.png", "Figure 4. An outcome, shown for both people at once. (Coin labels composited here. They are drawn by the browser over the game canvas.)")
figure("docs/figures/04_rating.png", "Figure 5. End-of-house rating on a 7-point preference scale, after the 16th try.")
# ================================================================== 4 instructions
doc.add_page_break()
H("4. Written instructions (verbatim)", 1)
P("Presented one screen at a time with Back/Next, each with an illustration. Text below is taken "
"directly from the running build.", italic=True, size=9.5)
H("4.1 Cover story", 2)
for t in clean(E.COVER_PART1): P(t)
doc.add_paragraph()
for t in clean(E.cover_part3("c")):
P(t[2:], style="List Bullet") if t.startswith("- ") else P(t)
doc.add_paragraph()
for t in clean(E.COVER_PART4): P(t)
H("4.2 How to play", 2)
for const in ("HOW_TO_PLAY_WALK", "HOW_TO_PLAY_CHOOSE", "HOW_TO_PLAY_FEEDBACK",
"HOW_TO_PLAY_SWAP", "HOW_TO_PLAY_IDENTITY", "HOW_TO_PLAY_VARIES"):
body = " ".join(clean(getattr(E, const)))
P(re.sub(r"^-\s*", "", body), style="List Bullet")
# ================================================================== 5 quiz
doc.add_page_break()
H("5. Comprehension quiz (verbatim)", 1)
P("Administered after the practice round. Each item is answered True or False; the participant is "
"shown feedback either way and the quiz then advances. Items missed are re-asked.", italic=True, size=9.5)
gridtable(["#", "Statement", "Correct", "Feedback shown"],
[[i + 1, s, "True" if c else "False", re.sub(r"</?b>", "", f)]
for i, (s, c, f) in enumerate(E.quiz_items("c"))],
[0.3, 2.3, 0.6, 2.6])
# ================================================================== 6 questionnaire
doc.add_page_break()
H("6. Post-task measures", 1)
P("Presented after gameplay as a single sequence of screens with Back/Next; every answer is "
"revisable. Leaving a page incomplete triggers a confirm dialog rather than a hard block. All "
"responses are stored in the participant's data file under the keys listed.", italic=True, size=9.5)
def qblock(title, scale, items, note=None):
H(title, 2)
P(f"Response scale: {scale}", italic=True, size=9.5)
if note: P(note, italic=True, size=9.5)
gridtable(["Item", "Data key"], [[p, f"`{k}`"] for k, p in items], [4.3, 1.6])
for k, p in items:
if p[:40].replace("…", "") not in QSRC and k not in QSRC:
sys.exit(f"ITEM DRIFT: {k} not found in questionnaires.py")
qblock("6.1 Strategy", "Free text",
[("strategy_text", "What strategy (or strategies) did you use during the learning task?")])
qblock("6.2 Motivation", "Slider 0–100, “Not at all motivated” → “Extremely motivated”",
[("motiv_win_self", "How motivated were you to win points for YOURSELF?"),
("motiv_win_partner", "How motivated were you to win points for YOUR PARTNER (#NNNN)?"),
("motiv_avoid_self", "How motivated were you to avoid losing points for YOURSELF?"),
("motiv_avoid_partner", "How motivated were you to avoid losing points for YOUR PARTNER (#NNNN)?")])
qblock("6.3 Effort", "Slider 0–100, “Required no effort” → “Required a lot of effort”",
[("effort_win_self", "How much effort did you exert to win points for YOURSELF?"),
("effort_win_partner", "How much effort did you exert to win points for YOUR PARTNER (#NNNN)?"),
("effort_avoid_self", "How much effort did you exert to avoid losing points for YOURSELF?"),
("effort_avoid_partner", "How much effort did you exert to avoid losing points for YOUR PARTNER (#NNNN)?")])
qblock("6.4 About the task", "Slider 0–100, anchors per item",
[("task_difficulty", "How easy or difficult was the task? (“Very easy” → “Very difficult”)"),
("task_interest", "How boring or interesting was the task? (“Very boring” → “Very interesting”)")])
qblock("6.5 Belief check (manipulation check)", "Yes / No, answer locks on submit",
[("believed_partner_paid",
"Did you believe that the other person would receive the money you earned for them?")])
H("6.6 Hypothetical other, DYAD MODE ONLY", 2)
P("These 14 items are presented only when the session is launched with **?dyad_mode=yes**. In "
"that mode the target is the participant's counterpart: children are asked about “your "
"parent”, parents about “your child”. For the SONA pilot dyad mode is off, so this whole "
"section is skipped and the questionnaire runs 6 pages / 13 items instead of 9 / 27.", size=9.5, italic=True)
qblock("Items (shown in dyad mode only)", "Slider 0–100, “Not at all” → “Extremely / a lot”",
[("hyp_motiv_win_self", "How motivated do you think [OTHER] would be to win points for themselves?"),
("hyp_motiv_win_partner", "How motivated do you think [OTHER] would be to win points for their partner?"),
("hyp_motiv_win_you", "How motivated do you think [OTHER] would be to win points for YOU?"),
("hyp_motiv_avoid_self", "How motivated do you think [OTHER] would be to avoid losing points for themselves?"),
("hyp_motiv_avoid_partner", "How motivated do you think [OTHER] would be to avoid losing points for their partner?"),
("hyp_motiv_avoid_you", "How motivated do you think [OTHER] would be to avoid losing points for YOU?"),
("hyp_effort_win_self", "How much effort do you think [OTHER] would exert to win points for themselves?"),
("hyp_effort_win_partner", "How much effort do you think [OTHER] would exert to win points for their partner?"),
("hyp_effort_win_you", "How much effort do you think [OTHER] would exert to win points for YOU?"),
("hyp_effort_avoid_self", "How much effort do you think [OTHER] would exert to avoid losing points for themselves?"),
("hyp_effort_avoid_partner","How much effort do you think [OTHER] would exert to avoid losing points for their partner?"),
("hyp_effort_avoid_you", "How much effort do you think [OTHER] would exert to avoid losing points for YOU?"),
("hyp_difficulty", "How easy or difficult do you think [OTHER] would find the task?"),
("hyp_interest", "How boring or interesting do you think [OTHER] would find the task?")],
note="Preceded by: “In the meantime, [OTHER] played the same game. How do you think they did? "
"There are no right or wrong answers here, just your best guess.”")
qblock("6.7 Questions about the future",
"5-point Likert: Strongly disagree / Disagree / Neutral / Agree / Strongly agree",
[("future_clear_goal", "When I think about my future, I can see clearly what I want to achieve."),
("future_imagine", "I can imagine what my future will be like."),
("future_unclear", "I can't get a clear picture of my future even when I try.")],
note="Third item is reverse-keyed.")
# ================================================================== 7
doc.add_page_break()
H("7. What changed in this version", 1)
kvtable([
("Trials per house", "16 (was 20). Total main trials 192 (was 240)."),
("Outcome split", "75% / 12.5% / 12.5%, exact counts 12 / 2 / 2 per chest, per person, per house (was 15 / 3 / 2)."),
("Attention check", "Removed, the previous “press LEFT” trial was too transparent to discriminate."),
("Progress display", "Removed from the participant's view (recorded as before, see below)."),
("Partner label", "The per-trial outcome now reads PARTNER rather than YOUR PARTNER."),
("Dyad mode", "New **?dyad_mode=yes** URL flag. Off by default: the experimenter's parent/child "
"role picker is hidden and the 14 hypothetical-other items are skipped. "
"On: both return, unchanged. The flag is recorded with the questionnaire responses."),
])
P("**Progress is recorded but not shown.** The “Houses cleared: n / 12” counter and the "
"“Inside the <house>, Try n / 16” line have both been removed, along with the instruction "
"slide describing the try counter. This is a display change only: every trial is still recorded "
"with house index, trial index, chosen chest, both outcomes, running totals and reaction time.")
H("8. Open items before the SONA pilot", 1)
bullets([
"**References for sections 6.2–6.4 and 6.7.** The item sources are not recorded anywhere in the repository and are not in Rhoads et al. (2025); they need to be supplied or the items marked as study-specific.",
"**Bonus scaling.** With 16 trials, perfect play yields 800 coins rather than 960, so the $6 cap now requires 75% of optimal play rather than 62.5%. Decision pending.",
])
H("References", 1)
P("Rhoads, S. A., Gan, L., Berluti, K., O'Connell, K., Cutler, J., Lockwood, P. L., & Marsh, A. A. "
"(2025). Neurocomputational basis of learning when choices simultaneously affect both oneself "
"and others. Nature Communications, 16, 9350. https://doi.org/10.1038/s41467-025-64424-9")
P("Source paradigm for the learning task: the four outcome scenarios (mutually beneficial, "
"instrumentally harmful, altruistic, mutually costly), the YOU / PARTNER outcome framing and the "
"block structure follow this paper. Note its own post-task battery (QCAE and other trait "
"measures) is not the battery used here.", italic=True, size=9.5)
doc.add_paragraph()
P("Sections 6.2–6.4 and 6.7, source not recorded in the repository; to be supplied.", italic=True, size=9.5)
doc.save("2.P17._3.9._ProsocialLearningTask_TreasureHuntForTwo_Instructions_08-26-2026.docx")
print("wrote 2.P17._3.9._ProsocialLearningTask_TreasureHuntForTwo_Instructions_08-26-2026.docx")