Writing a round-based experiment
********************************

Many group experiments are games played over several rounds: players
are paired or grouped, decide, see the result, and are grouped again
for the next round. This page builds one such game step by step, the
"ultimatum_pairing" demo, and then shows how other games vary it. Each
class and option links to its API reference where it first appears;
Groups and barriers in detail is the reference for everything else.

In the demo, cohorts of up to four players form as players arrive.
Each round, the cohort is split into pairs, and in each pair a
proposer offers part of 10 coins while the responder says the smallest
offer they would accept. A player who is slow, closes their tab or
sits a round out never holds up the others, and nobody is failed for
it. Each player's round is one trial, and the two trials of a pair
share a round record that holds the pair's results, so the game's data
can be read back from trials and rounds.


Forming cohorts
===============

A "SimpleGrouper" forms the cohorts. It starts a cohort of four as
soon as four players are waiting, or a smaller one after a minute
("start_short_after"), and lets latecomers join a cohort that has
started ("join_existing_groups"; see "SimpleGrouper"). A latecomer is
a pending member of the cohort until the next split admits them
("use_admission_points=True"; see Admission points), so nothing waits
for them before that:

   SimpleGrouper(
       COHORT,
       initial_group_size=COHORT_SIZE,
       quorum=MIN_COHORT_SIZE,
       start_short_after=SHORT_START_SECONDS,
       join_existing_groups=True,
       # A latecomer joins at the next round's pairing, which admits
       # them, and isn't counted or waited for until then.
       use_admission_points=True,
       target_group_size=MIN_COHORT_SIZE,
       waiting_message=lobby_message,
       waiting_screen=forming_cohort,
       max_wait_time=300,
       # Once top-ups stop, a cohort that falls below its quorum is
       # dissolved; this ends the game for the players left instead of
       # failing them.
       below_quorum="continue_without_group",
   ),

A latecomer who joined after the first rounds would soon have nobody
left to play with, because the others finish their rounds and leave,
so the regrouper below closes each cohort to latecomers when its
second round starts ("stop_top_ups_after_rounds"). A latecomer still
waiting for a split then is turned away with removal reason
""not_admitted"".


Pairing players each round
==========================

A "Regrouper" at the start of each round splits the cohort into new
pairs. Each time a player reaches it, they leave last round's pair and
wait for the next split. "PairingRegrouper" is the demo's own subclass
of "Regrouper", defined in its "pairing.py" (see Rounds with changing
groups), which keeps last round's partners apart and alternates roles:

   pairing = PairingRegrouper(
       PAIR,
       within=COHORT,
       roles=["proposer", "responder"],
       deadline=ROUND_DEADLINE_SECONDS,
       left_over="sit_out",
       stop_top_ups_after_rounds=OPEN_FOR_ROUNDS,
       waiting_message=round_message,
       waiting_screen=pairing_up,
   )


The round starts as soon as the whole cohort ("within") is waiting, or
at the "deadline" (counted from when the first player is back) without
whoever isn't back yet, if enough players are waiting to form a pair.
A player who isn't back by then is still in the cohort, and joins the
next round. The demo's bot test starts such a round with
"regroup_now()", so it doesn't wait for the deadline. With "roles",
each pair has a proposer and a responder; the demo's regrouper gives
each role to whoever has held it least often, so each player
alternates between them. "stop_top_ups_after_rounds=OPEN_FOR_ROUNDS"
lets latecomers join the cohort only during its first round. Every
split that forms pairs in the cohort counts as one of its rounds, even
one that pairs only latecomers while the others are still playing, and
the split after that stops the cohort's top-ups. "waiting_message"
counts down to the deadline. See "Regrouper" for these options:

   [image: A waiting page saying "The next round starts in at most 25
   s."][image]

The regrouper keeps the round's bookkeeping, so the game doesn't need
to store it in participant variables:

* "pairing.rounds_played(participant)" counts the pairs the player has
  joined, including one whose partner left or that they were removed
  from;

* "pairing.rounds_sat_out(participant)" counts the rounds they sat
  out.

Each player's role in the round is on their trial, as
"sync_group_role" (below). "Regrouper" lists its other methods, such
as "sat_out" and "role".


One trial per player per round
==============================

Each round of the timeline is the regrouper followed by one trial per
player, added with "Trial.cue()", without a trial maker:

   Module(
       "game",
       while_loop(
           "rounds",
           keep_playing,
           join(
               pairing,
               switch(
                   "round",
                   round_status,
                   {
                       "paired": OfferTrial.cue({"endowment": ENDOWMENT}),
                       "sat_out": InfoPage(SIT_OUT_TEXT, time_estimate=5),
                       # The game is over; the ended-early page explains why.
                       "no_cohort": [],
                   },
               ),
           ),
           expected_repetitions=N_ROUNDS,
       ),
   ),

The trial class sets "sync_group_type", so the trials that a pair's
members cue in a round share one "SyncGroupRound"
("trial.group_round"). Each trial records the pair ("sync_group_id"),
the player's role ("sync_group_role"), the pair's round
("sync_group_round") and how the round ended for the player
("sync_group_outcome", see Explaining the outcome), and keeps them
after the pair ends. The "Module" gives the rounds a "module_id" to
find them by when exporting.

"cue" numbers each group's rounds from 0, so every pair here, new each
round, plays round 0, and a definition must not depend on the player's
own position in the loop. Rounds of cued trials explains when a cue
joins a round, a trial's two round counters ("sync_group_round" and
"position"), a fixed group's loop with "round=", and several trial
classes in one round.

The "switch" decides once, before the trial: a player in a pair gets
the trial, one who sat out gets a page instead (see Sitting out), and
one whose cohort has gone moves on to the page saying the game ended
early:

   def round_status(participant):
       """Return whether the regrouper paired the player, sat them out, or left them with no cohort."""
       if in_pair(participant):
           return "paired"
       if pairing.sat_out(participant):
           return "sat_out"
       return "no_cohort"

Once started, the trial runs to its end, where it is scored, even if
the player is removed from their pair partway, so its feedback covers
every outcome of the round. A round that is one cued trial needs no
more than this; "join(..., stop_if=...)" is for rounds of several
steps.

The trial's "show_trial" is the decision page followed by a
"GroupBarrier" for the pair:

       def show_trial(self, experiment, participant):
           return join(
               self.decision_page(participant),
               GroupBarrier(
                   id_="round_finished",
                   group_type=PAIR,
                   waiting_message="Waiting for your partner…",
                   waiting_screen=waiting_for_partner,
                   # A player is taken out 30 s after the round starts (long
                   # enough for a background tab to notice), but not while their
                   # answer to the timed decision page may still be on its way.
                   # They have probably closed their page, so they leave the
                   # cohort too, and the next split doesn't wait for them.
                   late_after=30,
                   late_action="leave_group",
                   also_leave=[COHORT],
                   on_release=self.score_pair,
               ),
           )


Making a decision
=================

The decision page reads the player's role from the trial, and its
"GroupPrompt" shows the pair. The partner gets a tick as soon as they
have decided. Players normally appear as their pseudonym's animal,
which stays the same from round to round. "names="anonymous"" draws
both players as the same grey figure instead, so that nobody
recognises a partner from an earlier round:

       def decision_page(self, participant):
           role = self.sync_group_role
           endowment = self.definition["endowment"]
           if role == "proposer":
               prompt = (
                   f"You are the proposer. How many of {endowment} coins do you offer?"
               )
           else:
               prompt = (
                   f"You are the responder. Your partner is splitting {endowment} coins. "
                   "What is the smallest offer you would accept?"
               )
           return ModularPage(
               role,
               # A tick appears once the partner has decided. Partners are anonymous,
               # so that nobody recognises a partner from an earlier round.
               GroupPrompt(
                   prompt,
                   participant=participant,
                   group=self.sync_group,
                   names="anonymous",
               ),
               PushButtonControl(
                   choices=list(range(endowment + 1)), arrange_vertically=False
               ),
               time_limit=DECISION_SECONDS,
               time_estimate=10,
           )

   [image: The responder's decision page, with a tick on the partner
   who has already decided][image]

The page's "time_limit" gives each player 30 seconds. A player who
doesn't answer in time moves on with no answer ("time_limit_answer",
"None" by default), and their partner sees a grey dash instead of a
tick.


Moving slow players on
======================

The barrier after the decision page waits for both partners. A player
who hasn't reached it within "late_after" seconds of the round's start
is late. A late player has usually closed their page, so with
"late_action="leave_group"" and "also_leave=[COHORT]" they are removed
from the pair and from the cohort: their partner carries on alone, and
the next split doesn't wait for them. Without "also_leave" they leave
the pair only, so the next split would wait for them until its
deadline (see "GroupBarrier" and After leaving a group). A player on a
page with a time limit is not late before that limit has run out and
an answer sent at the deadline has had 10 seconds to arrive, so the
late limit need not be longer than the page's time limit. For example,
with a 30-second decision page and "late_after=30":

* A player who answers after 12 seconds waits at the barrier for their
  partner.

* A partner who leaves the page open without answering moves on at 30
  seconds, when the time limit runs out. The pair continues together,
  and nobody is paid.

* A partner who closes their tab partway through the page is removed
  from the pair about 40 seconds into the round: 10 seconds after the
  page's time limit.

* A partner whose tab never opened the page is removed from the pair
  30 seconds after the round started.

30 seconds is long enough for a tab in the background to notice that a
round has started. "late_after" counts from the previous barrier, so
pages without a time limit before the decision page, such as the last
round's results, count towards it: give them a time limit too, or make
"late_after" long enough for a slow reader. A player who was removed
from the pair sees "Your partner went on without you. Please
continue." on the progress bar (pass "on_arrival_message" to the
barrier to change it).

The barrier checks for late players only while their partner waits at
it, so if neither partner comes back, the next split waits for its
deadline. A late player who comes back is told that they were away,
and their game ends.

Once the cohort has stopped top-ups, removing a late player dissolves
it if that leaves it below its quorum (see Groups below quorum).
"below_quorum="fail"" would then fail the players who were on time
while the late player carries on, which the experiment rejects when it
loads, so the cohort's grouper sets
"below_quorum="continue_without_group"", and they carry on without the
cohort, which ends their game.

A player removed from their pair finishes the trial: its later group
barriers let them straight through, and its feedback tells them they
were away, because their trial's "sync_group_outcome" is ""late"".


Scoring the round
=================

The barrier's "on_release" scores the pair once both have arrived, or
once the one who is left has. It takes "trials", the members' trials,
and "group_round", the round they share, so a "@classmethod" on the
trial class can save the pair's players, offer and result in
"group_round.var" and each player's coins on their trial, where a page
reloaded later still finds them. When a partner left or ran out of
time, nobody is paid. The "left" argument lists the members who left
the pair this round, and "sync_group_removal_reason" tells a partner
who was too slow apart from one who returned the study. "trials" only
holds the trials of members still in the pair, so the players of the
round come from "group_round.trials", which also keeps the trial of a
player removed for being away:

       @classmethod
       def score_pair(
           cls,
           trials: List["OfferTrial"],
           group_round: SyncGroupRound,
           left: List[Participant],
       ):
           """Save the pair's players, offer and result on the round, and each player's coins on their trial."""
           by_role = {trial.sync_group_role: trial for trial in trials}
           decisions = {role: t.answer for role, t in by_role.items()}
           offer, minimum = decisions.get("proposer"), decisions.get("responder")
           if len(trials) < 2:
               away = any(p.sync_group_removal_reason(PAIR) == "late" for p in left)
               result = "partner_away" if away else "partner_left"
           elif offer is None or minimum is None:
               result = "timed_out"
           else:
               result = "accepted" if offer >= minimum else "rejected"
           # From all the round's trials, so a player removed for being away is kept.
           players = {t.sync_group_role: t.participant_id for t in group_round.trials}
           pair = group_round.var
           pair.proposer_id = players.get("proposer")
           pair.responder_id = players.get("responder")
           pair.offer = offer
           pair.minimum = minimum
           pair.result = result
           coins = (
               {
                   "proposer": group_round.definition["endowment"] - offer,
                   "responder": offer,
               }
               if result == "accepted"
               else {}
           )
           for role, trial in by_role.items():
               trial.var.coins = coins.get(role, 0)

The barrier is inside "show_trial", so the trials have not ended yet
when "on_release" runs: "trial.answer" holds each member's answer so
far, which here is their decision, or "None" if their page ran out of
time.


Explaining the outcome
======================

The trial ends after the barrier, so its feedback can read what was
stored during the round rather than work it out from the player's
groups:

* "self.sync_group_outcome" says how the round ended for this player:
  ""stayed"" once the barrier released the pair with them in it, or
  why they left the pair before then, here ""late"" for a player taken
  out for being away (see round outcomes for every value);

* "self.answer" is their own decision, "None" if they ran out of time;

* "self.group_round.var" holds what "on_release" saved for the pair.

A partner's outcome is on their trial in "self.group_round.trials".
"outcome" turns these into one key of "OUTCOME_TEXTS":

       def outcome(self):
           """Return the key in ``OUTCOME_TEXTS`` that describes the round for this player."""
           if self.sync_group_outcome == "late":
               return "away"
           # From the dashboard; the round may not have been scored yet.
           if self.sync_group_outcome == "removed_by_experimenter":
               return "removed_by_experimenter"
           if self.group_round.var.result == "timed_out" and self.answer is None:
               return "own_time_out"
           return self.group_round.var.result

"show_feedback" shows that text, and when the pair made a deal, passes
both answers to the prompt as speech bubbles:

       def show_feedback(self, experiment, participant):
           outcome = self.outcome()
           pair = self.group_round.var
           text = OUTCOME_TEXTS[outcome].format(
               offer=pair.get("offer"), coins=self.var.get("coins")
           )
           if outcome not in ("accepted", "rejected"):
               return InfoPage(text, time_estimate=5)
           return ModularPage(
               "outcome",
               GroupPrompt(
                   text,
                   participant=participant,
                   group=self.sync_group,
                   answers={
                       pair.proposer_id: f"I offer {pair.offer}",
                       pair.responder_id: f"I accept {pair.minimum}+",
                   },
                   names="anonymous",
               ),
               time_estimate=5,
           )

   [image: The results page, with "I offer 6" and "I accept 4+" speech
   bubbles][image]

   [image: The results page of a player who ran out of time: "You ran
   out of time, so nobody was paid."][image]A player whose time ran
   out.

To pay a bonus as well, return a score from "score_answer" and the
bonus from "compute_performance_reward", as the "public_goods" demo
does; both run when the trial ends, after "on_release". For example,
to pay each player's coins and an extra bonus to the round's winner,
mark the winner where "on_release" scores the round:

   COIN_VALUE = 0.01
   WINNER_BONUS = 0.05

   class OfferTrial(Trial):
       @classmethod
       def score_pair(cls, trials, group_round, left):
           ...  # Save each player's coins on their trial, as above.
           best = max(trial.var.coins for trial in trials)
           for trial in trials:
               # Ties all win; nobody wins a round in which nobody was paid.
               trial.var.won = best > 0 and trial.var.coins == best

       def score_answer(self, answer, definition):
           return self.var.get("coins", 0)

       def compute_performance_reward(self, score):
           bonus = WINNER_BONUS if self.var.get("won") else 0
           return COIN_VALUE * score + bonus

"var.get" covers a trial whose round was not scored, such as that of a
player who left before the barrier.


Sitting out
===========

With three players in a cohort, one of them has no partner. The player
who has played the most rounds sits the round out; with
"left_over="sit_out"" they move on without a pair instead of waiting
(see "Regrouper"), so the "switch" gives them a page instead of a
trial that round. A player who was paired but removed from the pair
before submitting their decision has a trial, and the first checks in
"outcome" above tell them that they were away or were removed from the
pair.

   [image: A page saying "You sit out this round without a partner. If
   you sit out 2 rounds, the game ends early for you."][image]


Ending the game
===============

The rounds loop runs while "game_over_reason" returns "None". The
function names each way a player's game can end: they played their
rounds, sat out too often, were removed for being late or by the
experimenter on the dashboard, or their cohort is down to one player.
(A player removed from just their pair is told so on that round's
results page.)

   def game_over_reason(participant):
       """Return why the player's game is over, or ``None`` while they keep playing."""
       # The pairs the regrouper has put the player in, including one they were
       # removed from; rounds they sat out don't count.
       if pairing.rounds_played(participant) >= N_ROUNDS:
           return "played_all_rounds"
       if pairing.rounds_sat_out(participant) >= MAX_SIT_OUTS:
           return "sat_out_too_often"
       # Being late takes a player out of their pair and their cohort; the
       # experimenter can remove them from the cohort on the dashboard; and a
       # latecomer is turned away if the cohort closes before pairing them.
       reason = participant.sync_group_removal_reason(COHORT)
       if reason in ("late", "removed_by_experimenter", "not_admitted"):
           return reason
       cohort = cohort_of(participant)
       if cohort is None or cohort.n_active_participants < 2:
           return "too_few_players"
       return None

Players who finish leave the cohort with "leave_group(COHORT)", so
that the regrouper doesn't wait for them in later rounds. It removes
them with "reason="finished"", which doesn't dissolve the closed
cohort by itself, so players who finish first don't end the round of
those still playing. The cohort's next barrier, here the regrouper's
next split, can still dissolve it if it is below its quorum then (see
Groups below quorum).

After that, a "switch" on "game_over_reason" shows a page for each
early end that still needs explaining. A player removed for being late
has already been told on their round's results page, so they get none.


Exporting the rounds
====================

The results stay on the trials and rounds, so "get_basic_data" builds
a table with one row per player and round from the trials, including
each player's "sync_group_outcome", and one with a row per pair from
the rounds. Rounds a player sat out have no trial, so a third table
counts them with the regrouper (see Basic data):

       @classmethod
       def get_basic_data(cls, context=None, **kwargs):
           """Return one row per player per round from the trials, one per pair from the rounds, and one per player."""
           trials = OfferTrial.query.order_by(OfferTrial.id).all()
           pairs = SyncGroupRound.query.filter_by(module_id="game").order_by(
               SyncGroupRound.id
           )
           players = Participant.query.order_by(Participant.id).all()
           return {
               "player_round": [
                   {
                       "pair_id": t.sync_group_id,
                       "participant_id": t.participant_id,
                       "trial_id": t.id,
                       # The player's own round; pairs change every round.
                       "round": t.position,
                       "role": t.sync_group_role,
                       # False while the trial runs or if the player left it; the
                       # decision is then the answer so far.
                       "complete": t.complete,
                       # "stayed" if the player was in the group when the round
                       # was scored; otherwise "late" if they were taken out
                       # before that for being away, or "removed_by_experimenter" if the
                       # experimenter removed them on the dashboard.
                       "outcome": t.sync_group_outcome,
                       # None if the player was away and never sent a decision.
                       "decision": t.answer,
                       "coins": t.var.get("coins"),
                   }
                   for t in trials
               ],
               "pair": [
                   {
                       "pair_id": r.sync_group_id,
                       "round_id": r.id,
                       "proposer_id": r.var.get("proposer_id"),
                       "responder_id": r.var.get("responder_id"),
                       "offer": r.var.get("offer"),
                       "minimum": r.var.get("minimum"),
                       "result": r.var.get("result"),
                   }
                   for r in pairs
               ],
               "player": [
                   {
                       "participant_id": p.id,
                       "rounds_played": pairing.rounds_played(p),
                       "rounds_sat_out": pairing.rounds_sat_out(p),
                   }
                   for p in players
               ],
           }


Variations
==========

**New groups from everyone waiting.** Without "within", a regrouper
splits everyone waiting, not one cohort, so how many play together
depends on how busy the experiment is. With "every=10" it splits them
every 10 seconds into groups of up to "group_size". Each group is new,
so its trials are all in round 0, and a group can mix players at
different rounds of the game; number each player's own trials as their
round in the export ("trial.position"). Pass
"max_wait_action="continue_without_group"" and follow the regrouper
with a "conditional()" on "participant.in_sync_group(...)", so that a
player left with nobody to play with, such as a latecomer whose last
round comes after everyone else has finished, carries on without a
group instead of being failed:

   for_loop(
       label="rounds",
       iterate_over=range(N_ROUNDS),
       logic=join(
           Regrouper(
               "room",
               group_size=8,
               smallest_group=2,
               every=10,
               waiting_message=round_message,
               max_wait_time=60,
               max_wait_action="continue_without_group",
           ),
           conditional(
               "in_room",
               lambda participant: participant.in_sync_group("room"),
               PickTrial.cue({"numbers": [1, 2, 3, 4, 5]}),
               InfoPage("Nobody else was left to play this round with.", time_estimate=5),
           ),
       ),
       time_estimate_per_iteration=PickTrial.time_estimate + 5,
   )

**A draw per group.** "definition" can also be a function, for example
"lambda group: {"target": random.choice(TARGETS)}". It is called once
per group and round, when the first member's cue creates the round, so
the whole group plays the same draw. A player who is in no group of
that type when the trial starts gets an ungrouped trial if the trial
class sets "sync_group_optional = True", with "sync_group_id" set to
"None" (otherwise the cue raises an error); "show_trial" can check
"self.sync_group is None" to give them a solo version. The
"crowd_estimate" demo does this in a fixed group's loop of questions,
cued with "round=question", and exports each round's
"sync_group_outcome" for each player.

**A fixed team that plays on with dropouts.** The "public_goods" demo
forms teams of three once, with a "SimpleGrouper" and "quorum=2", and
plays its rounds as a loop of cued trials with the loop value as
"round=" (see a fixed group's loop). Its barrier removes a late player
with "late_action="leave_group"", the others share the pot between
fewer players, and "score_answer" pays each player by their trial's
"sync_group_outcome" (see round outcomes), including the last player
of a team that dissolves.

**Turns one after the other.** In games such as a trust game, the
investor decides before the trustee. With cued trials, the role pages
and the barriers between turns all go in the "show_trial" of one trial
class. Put each role's page in a "conditional()" on the role, followed
by a "GroupBarrier" for the pair: the other player waits at the
barrier while it is not their turn. A "waiting_screen" on the barrier
tells them whose turn it is; a "GroupPrompt" with
"show_progress=False" shows the pair there without the waiting
player's own tick. In bot tests, "advance_past_wait_pages(bots,
stop_at="investor_sent")" leaves the bots waiting at that barrier, so
the test can take the investor's turn first. Once the investor's
answer releases the barrier, the same call moves the trustee on:
"stop_at" holds only bots the barrier hasn't released yet. The first
turn's barrier closes the round to newcomers: a player who joins the
pair after it starts the next round rather than joining a round whose
first turn is over.

**Turns in a fixed group.** In the "story_chain" demo, a group of
three writes a story one sentence at a time. Each turn is one cued
round in the group's loop, "StoryTurn.cue(turn_definition,
round=turn)" (see a fixed group's loop). The definition function runs
only at the turn's first cue, so it chooses the writer once, by seat
with "group_seats()", and the round's definition stores their ID for
every member's trial and for the export:

   def choose_writer(group, turn: int) -> int:
       """Return the ID of the member in seat ``turn % GROUP_SIZE``.

       If that member has left, return the member in the next seat still in the
       group.
       """
       seats = group_seats(group)
       by_seat = sorted(seats, key=seats.get)
       start = turn % GROUP_SIZE
       present = {participant.id for participant in group.active_participants}
       return next(pid for pid in by_seat[start:] + by_seat[:start] if pid in present)

The writer gets the writing page and then a code block that stores
their sentence in "group_round.var", before the turn's barrier; the
others go straight to the barrier, whose "waiting_screen" shows them
the story so far. The barrier closes the round:

       def show_trial(self, experiment, participant):
           barrier = GroupBarrier(
               id_=TURN_BARRIER,
               group_type=GROUP,
               waiting_message="Waiting for this turn to finish…",
               waiting_screen=waiting_for_writer,
               late_after=LATE_AFTER,
               late_action="leave_group",
           )
           if not self.is_writer:
               return barrier
           return join(
               self.write_page(participant), CodeBlock(self.save_sentence), barrier
           )

The sentence is stored in the writer's own request, so it is there
before the barrier lets the others go on, and it is kept if the group
dissolves while the writer is still writing. A writer the barrier has
already removed for being late stores nothing. The barrier never
removes a member while their own request is in progress, so the check
needs no lock:

       def save_sentence(self, participant):
           """Store the writer's sentence on the turn's round, if the turn is still theirs.

           A writer removed from the group, for example as late, stores nothing,
           because the others have finished the turn without them. The sentence
           is ``None`` if they ran out of time.
           """
           # A writer whose group dissolved while they wrote is the last one
           # left, so their sentence still ends the story.
           if in_group(participant) or self.sync_group_outcome == "group_dissolved":
               self.group_round.var.sentence = participant.answer

A turn can also end without a sentence, when the writer is late or
leaves. Each member's trial stores "None" when it finishes if the turn
has no sentence yet, so every finished turn has one, whether the
barrier released or the group dissolved:

       def on_finalized(self):
           """Store ``None`` as the sentence if the turn ended without one.

           That happens when the writer was late or left.
           """
           super().on_finalized()
           if not self.group_round.var.has("sentence"):
               self.group_round.var.sentence = None

When the sentence is "None", the writer trial's "sync_group_outcome"
says why: ""stayed"" if they ran out of time, or why they left the
group, such as ""late"" if the barrier took them out or
""left_experiment"" if they returned the study. With
""group_dissolved"", the writer was the last one left and ran out of
time or returned the study. If the chosen writer leaves between the
turn's first cue and their own, they have no trial for the turn at
all, and the export's "writer_outcome" is "None". The export has one
row per turn, from the rounds and the writers' trials, and its
"finished" column tells a turn that stored "None" from one that never
finished. Each member stores their group's ID when the group forms, so
the last page can read the story with "SyncGroup.rounds("story")" even
after the group has ended.

**Your own grouping.** "form_groups" replaces the default grouping,
for example to pair players by their earlier answers, and
"assign_roles" replaces the default random roles. The demo's regrouper
overrides both, to keep last round's partners apart and to alternate
roles (see Rounds with changing groups). With roles, each group needs
one member per role. See "Regrouper" for this and the other settings.

**A trial maker.** A trial maker with "sync_group_type", as in the
"create_rate_sync" demo, gives a group's members their trials together
and numbers the group's rounds from 0 in "sync_group_round". Cued
trials suit games whose groups change every round, or whose rounds are
a plain loop in the timeline.
