fix(client): count opponents correctly when the local seat is eliminated - #5187
fix(client): count opponents correctly when the local seat is eliminated#5187jeffrey701 wants to merge 2 commits into
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
The resumable-match summary computed opponentCount as Math.max(0, liveCount - 1), where liveCount already excludes eliminated players. The -1 assumes the local human (seat 0) is always alive; if seat 0 is eliminated but the match is still resumable (multi-seat local/FFA), seat 0 isn't in liveCount, so subtracting 1 undercounts opponents. Extract the pure counting into countLiveOpponents (unit-tested) and only subtract the local seat when it is alive.
456c7c5 to
1af899c
Compare
Resolve the maintainer-caused persisted public-state refactor while preserving the contributor’s local-seat elimination calculation.\n\nCo-authored-by: Jeff <jeffreyconradtucker@gmail.com>
|
Deferred by maintainer intake policy — not ignored. This current head ( A maintainer must explicitly take this PR or add a local frontend-review exception before it can receive substantive review. The defer label is a routing marker only, not a verdict on the change. |
2 similar comments
|
Deferred by maintainer intake policy — not ignored. This current head ( A maintainer must explicitly take this PR or add a local frontend-review exception before it can receive substantive review. The defer label is a routing marker only, not a verdict on the change. |
|
Deferred by maintainer intake policy — not ignored. This current head ( A maintainer must explicitly take this PR or add a local frontend-review exception before it can receive substantive review. The defer label is a routing marker only, not a verdict on the change. |
Problem
useResumables(client/src/hooks/useResumables.ts) builds a resumable-match summary and computes:liveCountalready excludes eliminated players, and the- 1removes the local human (seat 0). But that assumes seat 0 is always alive. In a still-resumable multi-seat / FFA match where seat 0 has been eliminated, seat 0 isn't part ofliveCount, so subtracting 1 undercounts the opponents by one. Example —players = [{id:0,eliminated}, {id:1,live}, {id:2,live}]→ reports 1 opponent, should be 2.Fix
Extract the counting into a pure, unit-tested
countLiveOpponentshelper (client/src/hooks/liveOpponents.ts) that only subtracts the local seat when it is itself alive, and call it from the hook. (Extracting the logic is what makes it testable without standing up the whole async hook — matching how the repo keeps other pure logic, e.g.gridBandMath, in dedicated tested modules.)Tests
Adds
liveOpponents.test.ts: seat 0 alive → live-others count; seat 0 eliminated → not decremented (the old formula returned 1, the fix returns 2 — discriminating); eliminated opponents excluded; degenerate all-eliminated / lone-survivor cases → 0.Self-contained: only
useResumables.ts, a new pure helper, and its test; no engine/Rust/protocol changes.Model: claude-opus-4-8