fix(client): count opponents correctly when the local seat is eliminated#5187
Open
jeffrey701 wants to merge 1 commit into
Open
fix(client): count opponents correctly when the local seat is eliminated#5187jeffrey701 wants to merge 1 commit into
jeffrey701 wants to merge 1 commit into
Conversation
Contributor
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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