Problem statement
Sushi Go's round-end and game-over overlays display incorrect AI scores: the end-of-game pudding bonus/penalty is not being applied to the AI's displayed totals.
Users
- Players (human testers and QA): need overlays to show accurate final scores and breakdowns so they can trust game results and debugging information.
- Developers/Maintainers: need a reproducible bug report, tests, and a minimal, well-scoped fix to ensure scoring logic and presentation remain correct.
User stories
- As a player, when the game ends I want the final totals shown in the overlay to equal the actual computed final scores so I can see an accurate winner.
- As a QA engineer, I want unit tests that assert pudding scoring and score aggregation so regressions are prevented.
- As a developer, I want the overlay to display canonical computed values (not duplicated ad-hoc sums) so presentation bugs are avoided.
Success criteria
- Pudding bonus/penalty is correctly applied to player.totalScore at game end for all players (measurable by unit tests asserting final totalScore changes when puddingBonuses are non-zero).
- The round-end and game-over overlays display totals and breakdowns that exactly match the canonical computed values (result and session state) in all observed cases (verified by tests or deterministic reproduction steps).
- Add unit tests that cover scorePudding and scoreRound behavior for representative cases including tie-splitting and fewest/most pudding scenarios; tests must pass in CI.
- All related documentation and code comments that describe pudding scoring and overlay display behavior are updated accordingly.
- Full project test suite must pass with the new changes.
Constraints
- Keep changes localized to Sushi Go example game code (example-games/sushi-go) unless evidence shows a core engine contract is broken.
- Changes must preserve existing public APIs and data structures used by tests and other example games.
- Avoid UI-only workarounds that duplicate scoring logic in the overlay; overlay display should read canonical computed values.
Existing state
- scorePudding(puddingCounts) exists and returns per-player bonuses (example-games/sushi-go/SushiGoScoring.ts).
- scoreRound(session) accumulates puddingCount per player and, at final round, computes puddingBonuses and adds them to players[i].totalScore.
- SushiGoOverlayManager.showRoundScoreOverlay and showGameOverOverlay assemble displayed lines from result.* fields and session.player totals. The overlay references result.puddingBonuses only in game-over overlay when present, but the reported bug indicates the AI's displayed total does not include the pudding bonus/penalty.
- Tests exist for scoring logic (tests/sushi-go/SushiGoScoring.test.ts) and overlay browser tests (tests/sushi-go/SushiGoOverlay.browser.test.ts).
Likely root causes (inference)
- Overlay code may be reading stale/uncalculated values (e.g., using result.roundScores or session.totalScore before puddingBonuses are applied), or a mismatch between when scoreRound updates session.totalScore and when overlay is rendered.
- Possible off-by-one where puddingBonuses are applied after overlay construction, or overlay displays result.roundScores rather than session.totalScore for final totals.
Desired change
- Audit scoreRound and game flow to confirm puddingBonuses are computed and applied to players[].totalScore before overlays render.
- Ensure overlay rendering uses the canonical session.players[i].totalScore (after puddingBonuses are applied) and, where appropriate, also shows the per-player pudding bonus value from result.puddingBonuses to make the change explicit in the UI.
- Add unit tests that prove pudding bonuses are computed and applied, and that overlays display totals matching session state.
- If a timing/order bug is discovered, fix the order so scoring updates happen before overlays are constructed.
Related work (manual discovery)
- example-games/sushi-go/SushiGoScoring.ts — Scoring helpers and functions: scoreTableau, scoreTableauBreakdown, countPudding, scorePudding, scoreMaki. Primary reference for scoring logic.
- example-games/sushi-go/SushiGoGame.ts — Game orchestration and scoreRound() which invokes scoring functions and updates player.totalScore including pudding bonuses at game end.
- example-games/sushi-go/scenes/SushiGoOverlayManager.ts — Overlay rendering for round end and game over; reads RoundResult and session player totals to display scores. Primary suspect for presentation mismatch.
- example-games/sushi-go/scenes/SushiGoTableauRenderer.ts — Uses scoreTableauBreakdown for tableau display (may affect breakdown numbers shown in UI).
- tests/sushi-go/SushiGoScoring.test.ts — Unit tests validating scoring functions, including scorePudding behavior.
- tests/sushi-go/SushiGoOverlay.browser.test.ts — Browser overlay test that exercises the game-over overlay; useful to extend to assert displayed totals match computed values.
Related work (automated report)
- CG-0MP1MVHB3000X9I0 — This work item (Scores are incorrect in the Sushi Go round end overlay). It reports pudding bonus likely missing from display.
- example-games/sushi-go/SushiGoScoring.ts — Contains scorePudding implementation (most/fewest split, tie handling) used by game logic.
Relevance: scoring logic already implemented and tested; any fix should reuse these functions.
- example-games/sushi-go/SushiGoGame.ts (scoreRound) — Calls scorePudding at game end and adds bonuses to players[i].totalScore.
Relevance: this is the canonical place where pudding is applied; verify ordering relative to overlay rendering.
- example-games/sushi-go/scenes/SushiGoOverlayManager.ts — Builds overlay lines using result and session state; likely location where displayed totals diverge from session total.
Relevance: fix may be in ensuring overlay reads session.players[i].totalScore after pudding application and/or uses result.puddingBonuses for clarity.
- tests/sushi-go/SushiGoScoring.test.ts — Contains tests covering scorePudding expectations; useful to extend for failing cases if found.
Appendix: Clarifying questions & answers
- Q: "Scope: Where have you observed the incorrect scores?" — Answer (user): "A - confirmed it is the pudding bonus/penalty that is missing". Source: interactive reply. Final: yes.
- Q: "Fix target: Should this work strictly correct a presentation bug in SushiGoOverlayManager (i.e., display wrong value), or should it include verifying and, if necessary, fixing the underlying scoring flow and adding tests?" — Answer (user): "C - Both presentation + scoring audit + tests". Source: interactive reply. Final: yes.
- Q: "Tests to add: Which tests do you require?" — Answer (user): "A - Unit tests (extend tests/sushi-go/SushiGoScoring.test.ts and add unit test for scoreRound behavior)". Source: interactive reply. Final: yes.
Open questions
- None remain; user confirmed scope and requirements.
CHANGELOG: planned code changes
- Audit and, if required, fix ordering in scoreRound/session update so puddingBonuses are applied prior to overlay rendering.
- Update SushiGoOverlayManager to display canonical totals and explicit pudding bonus lines in game-over overlay.
- Add unit tests verifying scorePudding and scoreRound final total application.
- Update any relevant docs or comments describing scoring and overlay behavior.
Problem statement
Sushi Go's round-end and game-over overlays display incorrect AI scores: the end-of-game pudding bonus/penalty is not being applied to the AI's displayed totals.
Users
User stories
Success criteria
Constraints
Existing state
Likely root causes (inference)
Desired change
Related work (manual discovery)
Related work (automated report)
Relevance: scoring logic already implemented and tested; any fix should reuse these functions.
Relevance: this is the canonical place where pudding is applied; verify ordering relative to overlay rendering.
Relevance: fix may be in ensuring overlay reads session.players[i].totalScore after pudding application and/or uses result.puddingBonuses for clarity.
Appendix: Clarifying questions & answers
Open questions
CHANGELOG: planned code changes