Spaces:
Running
Night watch: endowment, draws, cards and stage
Browse filesThe other player's field holds 320 credits at the start of the block and the
crows take from it, flooring at zero. A participant who always sleeps costs
them about 288 over 48 trials, so a smaller endowment could empty before the
block ends and leave the later trials with no stake.
Uncertain amounts now have a lottery behind them, in this block and in the
day-2 one. Without a draw a card reading "4 to 12" resolves to 8 every time
and a participant notices within a few rounds, at which point the range is a
label rather than a manipulation. The MODEL keeps using the stated amount or
the midpoint, since that is what they knew when they chose; the draw is what
is paid and what the outcome screen will show.
A failed watch counts as not having kept it, so the larger loss applies. The
all-or-nothing rule that protects the partner in the other blocks would here
reward failing, since trying and failing would cost them nothing.
?watch=1 turns the block on, ?dev=1&start=watch jumps to it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Files changed (6)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191"""Tuning p(work) in the uncertainty condition.
day_task_uncertainty.py left p(work) at 0.31, which wastes information: abinary choice carries p(1-p), maximal at 0.5 and vanishing at the extremes, soa block where seven choices in ten go the same way is doing about threequarters of the work it could.
Two knobs, both already in the shipped task. A lower rest credit makes workingmore attractive; higher rewards do the same. Both are swept against what theycost the parameters, because moving the whole block toward working also pushesthe easy cells toward ceiling, which is the opposite failure.
rest 2, rewards 3/6/10 what ships now rest 1, rewards 3/6/10 cheaper to refuse rest 2, rewards 4/8/12 more on offer rest 1, rewards 4/8/12 both
python analysis/day_task_uncertainty_tuning.py
ORIGINAL DOCSTRING FOLLOWS
The day task exactly as it ships, crossed with uncertainty about the reward.
Nothing new is invented. Same two cards, same rest credit, same rewards, sameeffort ladder, same beneficiary manipulation. On half the trials the reward isstated as a RANGE whose midpoint is the amount the matching certain trialsshow, so the two differ in certainty and not in expected size.
V_work = w(agent, certainty) * R - k_agent * E^2 V_rest = 2
The participant's OWN reward when stated exactly is the scale anchor at 1,since the weights, the effort cost and the choice consistency are identifiedonly up to a common scale. Three weights are read off it:
w_s_unc your own reward, as a range risk attitude for your outcomes w_o_cert the other's reward, stated the ordinary prosocial discount w_o_unc the other's reward, as a range
The hypothesis is a contrast between two differences: is the penalty for anuncertain reward larger when the reward is someone else's, (w_o_cert -w_o_unc), than when it is your own, (1 - w_s_unc)? If they match, the effectis ordinary risk attitude and nothing about it is social. The self trials arewhat make that answerable, which is why they are half the block.
Cells: 2 beneficiary x 3 rewards x 4 effort x 2 certainty = 48, one visit eachat 48 trials. Nothing is dropped and nothing is tuned per arm.
Six parameters where the shipped day task has three, so the question is whatk_self and k_other cost once three weights are also being fitted.
python analysis/day_task_uncertainty.py"""import jsonimport osimport sys
import numpy as npfrom pyem.api import EMModelfrom pyem.utils.math import calc_fval, norm2beta
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import effort_design as D # noqa: E402
N, REPS, SEED = 120, 4, 20261013W_MAX, K_MAX, BETA_MAX = 2.0, 30.0, 3.0TRIALS = 48#: name -> (rest credit, rewards). The first is what ships.CONFIGS = { "rest2_3-6-10": (2.0, [3.0, 6.0, 10.0]), "rest1_3-6-10": (1.0, [3.0, 6.0, 10.0]), "rest2_4-8-12": (2.0, [4.0, 8.0, 12.0]), "rest1_4-8-12": (1.0, [4.0, 8.0, 12.0]),}REST = float(D.REST_CREDIT)REWARDS = [float(r) for r in D.REWARDS] # 3, 6, 10EFF = np.array(D.EFFORT_FRACS, float) # .35 .50 .65 .80#: Range shown on uncertain trials. Midpoint equals the stated reward.RANGES = {3.0: (1.0, 5.0), 6.0: (3.0, 9.0), 10.0: (5.0, 15.0)}
W_S_UNC = (0.80, 0.12) # own uncertain rewards discounted a littleW_O_CERT = (0.60, 0.15) # the standard prosocial discountW_O_UNC = (0.38, 0.12) # and more when it is also vague: the hypothesisK_LO, K_HI = 6.0, 18.0BETA_LO, BETA_HI = 0.7, 2.2
NAMES = ["w_s_unc", "w_o_cert", "w_o_unc", "k_self", "k_other", "beta"]
def weight(w_s_unc, w_o_cert, w_o_unc, other, uncertain): return np.where(other == 0, np.where(uncertain == 0, 1.0, w_s_unc), np.where(uncertain == 0, w_o_cert, w_o_unc))
def p_work(w_s_unc, w_o_cert, w_o_unc, k_self, k_other, beta, other, uncertain, exp_r, eff, rest=None): w = weight(w_s_unc, w_o_cert, w_o_unc, other, uncertain) k = np.where(other == 0, k_self, k_other) r = REST if rest is None else rest return 1 / (1 + np.exp(-np.clip(beta * (w * exp_r - k * eff ** 2 - r), -30, 30)))
def unpack(par): par = np.asarray(par, float) return (norm2beta(par[0], W_MAX), norm2beta(par[1], W_MAX), norm2beta(par[2], W_MAX), norm2beta(par[3], K_MAX), norm2beta(par[4], K_MAX), norm2beta(par[5], BETA_MAX))
def make_obj(rest): def obj(par, other, uncertain, exp_r, eff, ch, prior=None, output="npl"): p = np.clip(p_work(*unpack(par), other, uncertain, exp_r, eff, rest), 1e-10, 1 - 1e-10) nll = -np.sum(ch * np.log(p) + (1 - ch) * np.log(1 - p)) return {"nll": float(nll)} if output == "all" else calc_fval(nll, par, prior=prior, output=output) return obj
def design(rng, rewards): """48 cells, one visit each. The expected reward is the stated amount on certain trials and the range midpoint on uncertain ones, which is the same number: the range is built around it.""" cells = [(o, u, r, e) for o in (0, 1) for u in (0, 1) for r in rewards for e in EFF] out = list(cells) rng.shuffle(out) a = np.array(out, float) return a[:, 0], a[:, 1], a[:, 2], a[:, 3]
def one_rep(rep, config): rest, rewards = CONFIGS[config] rng = np.random.default_rng(SEED + rep * 23) true = (np.clip(rng.normal(*W_S_UNC, N), .02, 1.9), np.clip(rng.normal(*W_O_CERT, N), .02, 1.9), np.clip(rng.normal(*W_O_UNC, N), .02, 1.9), rng.uniform(K_LO, K_HI, N), rng.uniform(K_LO, K_HI, N), rng.uniform(BETA_LO, BETA_HI, N)) data, shares = [], [] for i in range(N): cols = design(rng, rewards) p = p_work(*[t[i] for t in true], *cols, rest) shares.append(p.mean()) data.append([*cols, (rng.random(len(p)) < p).astype(float)])
est = np.asarray(EMModel(all_data=data, fit_func=make_obj(rest), param_names=NAMES).fit(verbose=0, seed=1).m) nat = np.array([unpack(est[:, i]) for i in range(est.shape[1])]) out = {nm: float(np.corrcoef(true[j], nat[:, j])[0, 1]) for j, nm in enumerate(NAMES)} out["config"] = config out["mean_p_work"] = float(np.mean(shares)) # The shipped day task's headline quantity, for comparison: it recovers at # 0.60 over 48 trials with no uncertainty crossed. out["r_k_gap"] = float(np.corrcoef(true[4] - true[3], nat[:, 4] - nat[:, 3])[0, 1]) # The hypothesis: is the uncertainty penalty bigger for the other's # rewards than for one's own? t_pen_o, t_pen_s = true[1] - true[2], 1.0 - true[0] f_pen_o, f_pen_s = nat[:, 1] - nat[:, 2], 1.0 - nat[:, 0] out["r_penalty_other"] = float(np.corrcoef(t_pen_o, f_pen_o)[0, 1]) out["r_penalty_self"] = float(np.corrcoef(t_pen_s, f_pen_s)[0, 1]) out["r_interaction"] = float(np.corrcoef(t_pen_o - t_pen_s, f_pen_o - f_pen_s)[0, 1]) return out
if __name__ == "__main__": print(f"{N} participants, {TRIALS} trials, 48 cells (one visit each)", flush=True) print(f"effort {list(EFF)}; sweeping rest credit and rewards", flush=True) print("shipped day task, no uncertainty: k_self 0.93 k_other 0.90 gap 0.60\n", flush=True) rows = [] for config in CONFIGS: for rep in range(REPS): r = one_rep(rep, config) rows.append(r) print(f"{config:<14} rep {rep}: k_self {r['k_self']:+.2f} " f"k_other {r['k_other']:+.2f} gap {r['r_k_gap']:+.2f} " f"INT {r['r_interaction']:+.2f} p(work) {r['mean_p_work']:.2f}", flush=True) print() for config in CONFIGS: sel = [r for r in rows if r["config"] == config] avg = lambda k: float(np.mean([s[k] for s in sel])) print(f"{config:<14} " + " ".join(f"{n} {avg(n):+.2f}" for n in NAMES) + f" gap {avg('r_k_gap'):+.2f} INT {avg('r_interaction'):+.2f}" + f" p(work) {avg('mean_p_work'):.2f}", flush=True) here = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(here, "day_task_uncertainty_tuning.json"), "w") as f: json.dump(rows, f, indent=2) print("\nwrote day_task_uncertainty.json", flush=True)39 unmodified lines4041424344454639 unmodified linesSTAGE_ORDER = ["Fatigue_pre", "HowToPlay", "Calibration", "Practice","Comprehension", "Ready", "Harvest1", "Break", "Harvest2","Night1", "Night2", "Night2b", "Night1b", "HarvestSpeed", "Uncertainty","QuestionnaireTransition", "Fatigue_post", "NASA_TLX", "Effort_impact","PostTask_Motivation", "PostTask_Effort2", "PostTask_TaskRating","PostTask_Belief", "PostTask_Hypothetical", "PostTask_Strategy",39 unmodified lines4041424344454639 unmodified linesSTAGE_ORDER = ["Fatigue_pre", "HowToPlay", "Calibration", "Practice","Comprehension", "Ready", "Harvest1", "Break", "Harvest2","Night1", "Night2", "Night2b", "Night1b", "HarvestSpeed", "Uncertainty", "NightWatch","QuestionnaireTransition", "Fatigue_post", "NASA_TLX", "Effort_impact","PostTask_Motivation", "PostTask_Effort2", "PostTask_TaskRating","PostTask_Belief", "PostTask_Hypothetical", "PostTask_Strategy",
226 unmodified lines227228229230231232306 unmodified lines53954054154254354454554654771 unmodified lines619620621622623624226 unmodified lines# way, by construction, and recorded so the analysis never has# to re-derive what the participant was shown.expectedReward=rew,))idx += 1return trials306 unmodified lines#: uncertainty is the same proportion of the stake throughout.WATCH_RANGES = {2: (1, 3), 4: (2, 6), 8: (4, 12)}WATCH_BLOCK = 8def watch_cells():"""32 cells: 2 sleep-losses x 2 sleep-certainty x 2 watch-certainty x 4 effort."""return [(ls, sc, wc, lvl)71 unmodified linessleepHi=None if sleep_certain else shi,workLo=None if watch_certain else wlo,workHi=None if watch_certain else whi,condition=f"WATCH/{cond}/{loss_sleep}to{WATCH_LOSS_WORK}/{lvl}",)out.append(t)226 unmodified lines227228229230231232233234235236306 unmodified lines54354454554654754854955055155255355455555655755855956056156256356456556656756856957057157271 unmodified lines644645646647648649650651652653654655656657658226 unmodified lines# way, by construction, and recorded so the analysis never has# to re-derive what the participant was shown.expectedReward=rew,# What is actually paid. An uncertain offer needs a lottery# behind it: without one a card reading "3 to 9" pays 6 every# time and the range is a label rather than a manipulation.rewardDrawn=(rew if certain else rng.randint(lo, hi)),))idx += 1return trials306 unmodified lines#: uncertainty is the same proportion of the stake throughout.WATCH_RANGES = {2: (1, 3), 4: (2, 6), 8: (4, 12)}#: What the other player's field holds at the start of the night block. The#: crows take from this, and it floors at zero.#:#: Over 48 trials a participant who always sleeps costs them about 288, so an#: endowment below that can empty before the block ends, leaving the later#: trials with no stake. 320 keeps a stake on every trial even in the worst#: case. NOTE: how this interacts with the $6 purse cap has not been checked#: against the real economy and is a decision still open.WATCH_ENDOWMENT = 320WATCH_BLOCK = 8def _draw(lo, hi, rng):"""A whole number from [lo, hi].An uncertain amount needs a lottery behind it. Without one a card reading"4 to 12" resolves to 8 on every trial and a participant notices within afew rounds, at which point the manipulation is a label and nothing else.Seeded like everything else, so a session replays identically."""return rng.randint(int(lo), int(hi))def watch_cells():"""32 cells: 2 sleep-losses x 2 sleep-certainty x 2 watch-certainty x 4 effort."""return [(ls, sc, wc, lvl)71 unmodified linessleepHi=None if sleep_certain else shi,workLo=None if watch_certain else wlo,workHi=None if watch_certain else whi,# What actually happens, drawn from the range the participant was# shown. On a stated trial it equals the stated amount. The MODEL# uses the stated amount or the midpoint, because that is what# they knew when they chose; the participant is paid the draw.lossSleepDrawn=(loss_sleep if sleep_certainelse _draw(slo, shi, rng)),lossWorkDrawn=(WATCH_LOSS_WORK if watch_certainelse _draw(wlo, whi, rng)),endowment=WATCH_ENDOWMENT,condition=f"WATCH/{cond}/{loss_sleep}to{WATCH_LOSS_WORK}/{lvl}",)out.append(t)
374 unmodified lines375376377378379380126 unmodified lines507508509510511512467 unmodified lines980981982983984985121 unmodified lines110711081109111011111112374 unmodified lines_add("self_points", credits)returnif result.get("harvestSpeed"):# The night's pay is the same whichever speed was chosen and goes to# the participant. What varies is the corn left behind, which never126 unmodified lines"rewardLo": t.get("rewardLo"),"rewardHi": t.get("rewardHi"),"certain": t.get("certain"),# harvest-speed fields (absent on day and night trials). Both cards# are work here and they cost different effort, so the JS needs both# counts and picks one when the participant chooses.467 unmodified linesHARVEST_SPEED_STAGE = "HarvestSpeed"UNCERTAINTY_STAGE = "Uncertainty"#: The uncertainty condition's two blocks, offset so its data never collides#: with the day task's 0 and 1. The analysis splits on this.UNCERTAINTY_BLOCK_OFFSET = 6121 unmodified lines# when the link does not ask for it._harvest_speed_stage(),_uncertainty_stage(),_fb("QuestionnaireTransition", credits_bridge_display),Q.fatigue_stage("post"),Q.nasa_tlx_stage(),374 unmodified lines375376377378379380381382383384385386387388389390391392393394395396397398126 unmodified lines525526527528529530531532533534535536537538539467 unmodified lines100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054121 unmodified lines1176117711781179118011811182374 unmodified lines_add("self_points", credits)returnif result.get("nightWatch"):# Sleeping pays a fixed amount and lets the crows take more; keeping# watch pays nothing extra and holds them down. A failed watch is# treated as not having kept it, so the larger loss applies: the# all-or-nothing rule that protects the partner elsewhere would here# reward failing, since trying and failing would cost them nothing.if result.get("choice") == "sleep":_add("self_points", int(result.get("restCredit", 0) or 0))lost = int(result.get("lossSleepDrawn", 0) or 0)else:lost = int(result.get("lossWorkDrawn", 0) or 0) if result.get("success") \else int(result.get("lossSleepDrawn", 0) or 0)store = app.storage.user.get("watch_store")if store is None:store = int(result.get("endowment", 0) or 0)app.storage.user["watch_store"] = max(0, store - lost)returnif result.get("harvestSpeed"):# The night's pay is the same whichever speed was chosen and goes to# the participant. What varies is the corn left behind, which never126 unmodified lines"rewardLo": t.get("rewardLo"),"rewardHi": t.get("rewardHi"),"certain": t.get("certain"),# night-watch fields. Both cards carry a loss line, and which side is# a range is the manipulation, so both ranges are sent."nightWatch": t.get("nightWatch"),"lossSleep": t.get("lossSleep"),"lossWork": t.get("lossWork"),"sleepLo": t.get("sleepLo"), "sleepHi": t.get("sleepHi"),"workLo": t.get("workLo"), "workHi": t.get("workHi"),"lossSleepDrawn": t.get("lossSleepDrawn"),"lossWorkDrawn": t.get("lossWorkDrawn"),# harvest-speed fields (absent on day and night trials). Both cards# are work here and they cost different effort, so the JS needs both# counts and picks one when the participant chooses.467 unmodified linesHARVEST_SPEED_STAGE = "HarvestSpeed"UNCERTAINTY_STAGE = "Uncertainty"NIGHT_WATCH_STAGE = "NightWatch"def night_watch_on():"""True when this session runs the night-watch block, from ?watch= in thelink. Only callable inside a request."""return bool(app.storage.user.get("night_watch"))def _night_watch_stage():"""One block of the night watch: sleep for a fixed payment and let thecrows take more, or keep watch for nothing and hold them down."""async def _display(stage, container):th = TH.current_theme()pid = app.storage.user.get("pid", "0001")n = int(app.storage.user.get("dev_trials") or 48)trials = D.make_watch_trials(get_max_boxes(), pid, n_trials=n)app.storage.user["watch_store"] = D.WATCH_ENDOWMENTpartner = app.storage.user.get("random_id", "Player 2")intro = (f"## \U0001F319 The Night Watch\n\n"f"Crows come to the fields at night. YOUR field is already "f"harvested and safe in the barn. **{partner}'s** is not: they "f"still have **{D.WATCH_ENDOWMENT} credits** of {th['target']} "f"standing.\n\n"f"Each night you choose:\n\n"f"- SLEEP. You collect **{D.WATCH_SLEEP_PAY} credits** for the "f"fallen {th['target']} by your door in the morning. The crows "f"take what they take from their field.\n"f"- KEEP WATCH. Driving the crows off takes work. They take much "f"less. You collect nothing extra.\n\n"f"\U0001F426 Both cards show what the crows would take. Some "f"nights that number is not yet known, and you will see a range "f"instead. You find out what they actually took once the night "f"is over.")res = await _run_block(stage, container, trials, practice=False,intro_md=intro, time_of_day="night")return dict(block=D.WATCH_BLOCK, label="NightWatch",endowment=D.WATCH_ENDOWMENT,store_left=app.storage.user.get("watch_store"), trials=res)return _fb(NIGHT_WATCH_STAGE, _display)#: The uncertainty condition's two blocks, offset so its data never collides#: with the day task's 0 and 1. The analysis splits on this.UNCERTAINTY_BLOCK_OFFSET = 6121 unmodified lines# when the link does not ask for it._harvest_speed_stage(),_uncertainty_stage(),_night_watch_stage(),_fb("QuestionnaireTransition", credits_bridge_display),Q.fatigue_stage("post"),Q.nasa_tlx_stage(),
561 unmodified lines5625635645655665675688 unmodified lines5775785795805815825831416 unmodified lines20002001200220032004200520062007200820092010201195 unmodified lines21072108210921102111211228 unmodified lines21412142214321442145214683 unmodified lines2230223122322233223422352236561 unmodified lines// you pick decides who is paid, not whether you work.// Harvest speed: both cards are work and they cost DIFFERENT effort, so// the choice sets how much there is to collect. workSide is the QUICK card.if (trial.harvestSpeed) {trial.choice = isWork ? "quick" : "slow";trial.required = isWork ? trial.requiredQuick : trial.requiredSlow;trial.spoiledNow = isWork ? trial.spoiled : 0;8 unmodified linesfunction startChosenPhase() {if (!trial || trial.phase !== "decision") return;if (trial.choice !== "rest") { // "slow" and "quick" are both worktrial.phase = "work"; trial.phaseStart = now();trial.corn = scatterCornBalanced(trial.required, trial.player);} else {1416 unmodified lines// The harvest-speed block pays the same whichever card is chosen, so the// day task's "THIS ROUND, YOU EARN FOR" is wrong here: what the round// decides is whose field it is, not who is paid.ctx.fillText(t.harvestSpeed ? "TONIGHT YOU ARE HARVESTING": t.night ? "🌙 YOUR PARTNER IS ASLEEP": "THIS ROUND, YOU EARN FOR", W / 2, HUD + 36);ctx.fillStyle = (t.night || t.harvestSpeed) ? "#4a5b7a" : acc;ctx.font = "bold 30px system-ui, sans-serif";ctx.fillText(t.harvestSpeed ? (isOther ? "THE OTHER PLAYER'S FIELD" : "YOUR OWN FIELD"): t.night ? (t.night === 2 ? "WHOSE POCKET?" : "RAID THE FIELD?"): (isOther ? "YOUR PARTNER" : "YOU"), W / 2, HUD + 65);const workIsLeft = t.workSide === "left";95 unmodified linesctx.restore();}function drawHarvestSpeedCard(x, y, w, h, kind, t) {const th = themeStyle(), cx = x + w / 2;const isQuick = (kind === "work"); // workSide is the QUICK card28 unmodified lines}function drawChoiceCard(x, y, w, h, kind, t) {if (t.harvestSpeed) {if (kind === "work") drawSpeedPayBanner(t); // once per screenreturn drawHarvestSpeedCard(x, y, w, h, kind, t);83 unmodified lines// round and for both cards, so "YOU ROUND" would sit above a screen whose// choice is about whose crop is left behind.const label = (t.teach ? "PRACTICE: " : "")+ (t.harvestSpeed ? "\u{1F319} NIGHT HARVEST": t.night ? "\u{1F319} NIGHT HARVEST": isOther ? "YOUR PARTNER ROUND" : "YOU ROUND");ctx.fillText(label, W / 2, HUD / 2 + 11);561 unmodified lines5625635645655665675685695705715725738 unmodified lines5825835845855865875885895905911416 unmodified lines2008200920102011201220132014201520162017201820192020202195 unmodified lines211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215628 unmodified lines218521862187218821892190219183 unmodified lines22752276227722782279228022812282561 unmodified lines// you pick decides who is paid, not whether you work.// Harvest speed: both cards are work and they cost DIFFERENT effort, so// the choice sets how much there is to collect. workSide is the QUICK card.if (trial.nightWatch) {// Keeping watch is the only option that costs effort. Sleeping pays a// fixed amount and lets the crows take the larger number.trial.choice = isWork ? "watch" : "sleep";trial.lostNow = isWork ? trial.lossWorkDrawn : trial.lossSleepDrawn;} else if (trial.harvestSpeed) {trial.choice = isWork ? "quick" : "slow";trial.required = isWork ? trial.requiredQuick : trial.requiredSlow;trial.spoiledNow = isWork ? trial.spoiled : 0;8 unmodified linesfunction startChosenPhase() {if (!trial || trial.phase !== "decision") return;if (trial.choice === "sleep") { // no effort; the crows take the resttrial.phase = "rest"; trial.phaseStart = now();buildRest(trial);} else if (trial.choice !== "rest") { // "slow" and "quick" are both worktrial.phase = "work"; trial.phaseStart = now();trial.corn = scatterCornBalanced(trial.required, trial.player);} else {1416 unmodified lines// The harvest-speed block pays the same whichever card is chosen, so the// day task's "THIS ROUND, YOU EARN FOR" is wrong here: what the round// decides is whose field it is, not who is paid.ctx.fillText(t.nightWatch ? "\u{1F426} CROWS ARE COMING": t.harvestSpeed ? "TONIGHT YOU ARE HARVESTING": t.night ? "🌙 YOUR PARTNER IS ASLEEP": "THIS ROUND, YOU EARN FOR", W / 2, HUD + 36);ctx.fillStyle = (t.night || t.harvestSpeed || t.nightWatch) ? "#4a5b7a" : acc;ctx.font = "bold 30px system-ui, sans-serif";ctx.fillText(t.nightWatch ? "TO THEIR FIELD": t.harvestSpeed ? (isOther ? "THE OTHER PLAYER'S FIELD" : "YOUR OWN FIELD"): t.night ? (t.night === 2 ? "WHOSE POCKET?" : "RAID THE FIELD?"): (isOther ? "YOUR PARTNER" : "YOU"), W / 2, HUD + 65);const workIsLeft = t.workSide === "left";95 unmodified linesctx.restore();}function drawWatchCard(x, y, w, h, kind, t) {const th = themeStyle(), cx = x + w / 2;const isWatch = (kind === "work"); // workSide is the WATCH cardctx.fillStyle = C.panel; roundRect(x, y, w, h, 12); ctx.fill();ctx.strokeStyle = isWatch ? "#8fa6c4" : "#e08a5f"; ctx.lineWidth = 3;roundRect(x, y, w, h, 12); ctx.stroke();ctx.textAlign = "center";ctx.font = "28px system-ui, sans-serif";ctx.fillText(isWatch ? "\u{1F526}" : "\u{1F634}", cx, y + 40);ctx.fillStyle = C.white; ctx.font = "bold 17px system-ui, sans-serif";ctx.fillText(isWatch ? "KEEP WATCH" : "SLEEP", cx, y + h - 98);if (isWatch) {ctx.fillStyle = "#dfe5ee"; ctx.font = "bold 18px system-ui, sans-serif";ctx.fillText(th.verbIng + " " + t.required + " " + targetWord(t.required, th),cx, y + h - 70);} else {ctx.fillStyle = C.gold; ctx.font = "bold 20px system-ui, sans-serif";ctx.fillText("+" + t.restCredit + " " + creditsWord(t.restCredit) + " for you",cx, y + h - 70);}// What the crows take. Either side can be a range, and which side is a// range is the manipulation, so both cards always carry this line.const lo = isWatch ? t.workLo : t.sleepLo;const hi = isWatch ? t.workHi : t.sleepHi;const amt = isWatch ? t.lossWork : t.lossSleep;const vague = (lo != null && hi != null);ctx.fillStyle = "#ff8f8f"; ctx.font = "bold 19px system-ui, sans-serif";ctx.fillText(vague ? ("they lose " + lo + "\u2013" + hi): ("they lose " + amt), cx, y + h - 40);ctx.fillStyle = vague ? "#e8c547" : "#9fb0c4";ctx.font = (vague ? "bold " : "") + "12px system-ui, sans-serif";ctx.fillText(vague ? "not yet known" : "for certain", cx, y + h - 18);}function drawHarvestSpeedCard(x, y, w, h, kind, t) {const th = themeStyle(), cx = x + w / 2;const isQuick = (kind === "work"); // workSide is the QUICK card28 unmodified lines}function drawChoiceCard(x, y, w, h, kind, t) {if (t.nightWatch) return drawWatchCard(x, y, w, h, kind, t);if (t.harvestSpeed) {if (kind === "work") drawSpeedPayBanner(t); // once per screenreturn drawHarvestSpeedCard(x, y, w, h, kind, t);83 unmodified lines// round and for both cards, so "YOU ROUND" would sit above a screen whose// choice is about whose crop is left behind.const label = (t.teach ? "PRACTICE: " : "")+ (t.nightWatch ? "\u{1F319} NIGHT WATCH": t.harvestSpeed ? "\u{1F319} NIGHT HARVEST": t.night ? "\u{1F319} NIGHT HARVEST": isOther ? "YOUR PARTNER ROUND" : "YOU ROUND");ctx.fillText(label, W / 2, HUD / 2 + 11);
265 unmodified lines266267268269270271238 unmodified lines510511512513514515747 unmodified lines126312641265126612671268265 unmodified lines"uncertain": {"Fatigue_pre", "HowToPlay", "Calibration", "Practice", "Comprehension", "Ready","Harvest1", "Break", "Harvest2","Night1", "Night2", "Night2b", "Night1b", "HarvestSpeed"},}238 unmodified linesdev_skip = dev_skip | {E.HARVEST_SPEED_STAGE}if not E.uncertainty_on():dev_skip = dev_skip | {E.UNCERTAINTY_STAGE}# Combined SONA study only: demographics and the TriPM describe the person,# not the task, so they run once -- for whichever of the two tasks the# participant finishes SECOND. Without this they would answer 58 TriPM items747 unmodified lineslogger.warning(f"ignoring unrecognised ?uncertain={unc_q!r}")app.storage.user.setdefault("uncertainty", False)# ?night_order=21 runs Night 2 before Night 1. Counterbalances the 'both' arm,# which otherwise always showed Night 1 first (confounding it with fatigue).# Sticky like the others: set once, never re-read mid-session.265 unmodified lines266267268269270271272273274275238 unmodified lines514515516517518519520521747 unmodified lines1269127012711272127312741275127612771278127912801281128212831284128512861287265 unmodified lines"uncertain": {"Fatigue_pre", "HowToPlay", "Calibration", "Practice", "Comprehension", "Ready","Harvest1", "Break", "Harvest2","Night1", "Night2", "Night2b", "Night1b", "HarvestSpeed"},# Straight into the night watch, past everything before it."watch": {"Fatigue_pre", "HowToPlay", "Calibration", "Practice", "Comprehension", "Ready","Harvest1", "Break", "Harvest2","Night1", "Night2", "Night2b", "Night1b", "HarvestSpeed", "Uncertainty"},}238 unmodified linesdev_skip = dev_skip | {E.HARVEST_SPEED_STAGE}if not E.uncertainty_on():dev_skip = dev_skip | {E.UNCERTAINTY_STAGE}if not E.night_watch_on():dev_skip = dev_skip | {E.NIGHT_WATCH_STAGE}# Combined SONA study only: demographics and the TriPM describe the person,# not the task, so they run once -- for whichever of the two tasks the# participant finishes SECOND. Without this they would answer 58 TriPM items747 unmodified lineslogger.warning(f"ignoring unrecognised ?uncertain={unc_q!r}")app.storage.user.setdefault("uncertainty", False)# ?watch=1 runs the night-watch block: sleep for a fixed payment and let the# crows take more from the other player, or keep watch for nothing extra and# hold the loss down, with uncertainty crossed over which side is stated.watch_q = (request.query_params.get("watch") or "").strip().lower()if watch_q and (dev_q or "night_watch" not in app.storage.user):if watch_q in ("1", "true", "yes", "on"):app.storage.user["night_watch"] = Trueelif watch_q in ("0", "false", "no", "off"):app.storage.user["night_watch"] = Falseelse:logger.warning(f"ignoring unrecognised ?watch={watch_q!r}")app.storage.user.setdefault("night_watch", False)# ?night_order=21 runs Night 2 before Night 1. Counterbalances the 'both' arm,# which otherwise always showed Night 1 first (confounding it with fatigue).# Sticky like the others: set once, never re-read mid-session.