const PLAYERS = ["0", "1", "2"] as const;
export const paperScissorsRock = defineGame({
maxPlayers: 3,
setup: ({ match }) => ({
round: 1,
scores: roster.record(match, 0),
submissions: createHiddenChoices(),
// ...
}),
initialPhase: "plan",
phases: {
plan: {
activePlayers: ({ G }) => PLAYERS.filter((id) => G.submissions[id] === null),
label: ({ G }) => `Round ${G.round}`,
},
},
moves: ({ move }) => ({
submitChoice: move<PaperScissorsRockChoice>({
run({ G, args, move, player }) {
const submissions = { ...G.submissions, [player.id]: args };
const allSubmitted = PLAYERS.every((id) => submissions[id] !== null);
if (!allSubmitted) {
return move.stay({ submissions });
}
const outcome = resolveRoundOutcome(submissions);
const scores = applyWins(G.scores, outcome.winners);
return move.endTurn({
lastOutcome: outcome,
lastRevealed: submissions,
round: G.round + 1,
scores,
submissions: createHiddenChoices(),
});
},
}),
}),
});