fix: 手气卡回牌堆匿名化与斗地主先手误设#48
Conversation
resetKnownToUnknown 仅 isKnown=false 会在牌堆留下正 ID 未知槽, 后续暗摸会原样绑成正 ID 独占暗手并破坏 discardKnown 物化。
Type 44 只是叫分操作回包,不是最终地主结果;误用其 SeatID 设置先手。
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough本次变更新增已定位牌身份匿名化和未知状态回收流程,接入明牌回牌堆逻辑并补充暗摸验证;同时移除叫分结果处理中基于 Changes已定位牌身份匿名化
手气卡结果处理
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant moveKnownCardsForContext
participant Room
participant CardCounter
participant TrackerTest
moveKnownCardsForContext->>Room: anonymizeLocatedIdentity(card)
Room->>CardCounter: releaseLocatedIdentityToUnknown(card, previousCardID)
CardCounter-->>Room: 更新 UNKNOWN 状态
Room-->>moveKnownCardsForContext: 返回 previousCardID
moveKnownCardsForContext->>TrackerTest: 验证负 ID 匿名牌
TrackerTest->>TrackerTest: 执行暗摸并检查未知状态
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Type 44/45 不再调用 setTrackerFirstHand,更新 roleSpellOptRep 回归。
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/tracker/Room.ts (1)
521-530: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win建议用
setLocationCandidates()替代直接赋值locationCandidates,避免owner字段滞留旧值。
card.locationCandidates = []绕过了setLocationCandidates()(代码库中清空候选的既有写法,参见本文件materializeExistingIdentityAtTarget的existing.setLocationCandidates([], 'materialize:interop:known'))。此时card.location还未被重置(card.reset()是调用方在这之后才执行的),若不经过setLocationCandidates/syncOwnerFromSeats,card.owner会暂时保留旧座位,card.seatsgetter 在locationCandidates为空时会回退到该旧owner,而不是真正清空。当前唯一调用点因为紧跟card.reset()且不在resolveConstraints()循环内(resolveTouchedSeats为null)而没有暴露问题,但作为新增的公共 Room 方法,建议收紧写法以避免未来复用时出现隐蔽的座位不一致。♻️ 建议的修改
- card.locationCandidates = [] + card.setLocationCandidates([], reason)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tracker/Room.ts` around lines 521 - 530, 在 Room 中处理匿名实体 ID 分配的代码里,将直接赋值 card.locationCandidates = [] 改为调用 card.setLocationCandidates,并传入表示清空候选位置的现有上下文标识。确保该流程同步清理 owner,避免 card.seats 在 location 尚未重置时回退到旧座位。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/handler/CGsRoleSpellOptRep.js`:
- Around line 17-18: Update the Type 44 regression test in roleSpellOptRep to
assert that setTrackerFirstHand is not called, reflecting the removed side
effect, and rename the test to describe the new behavior.
---
Nitpick comments:
In `@src/tracker/Room.ts`:
- Around line 521-530: 在 Room 中处理匿名实体 ID 分配的代码里,将直接赋值 card.locationCandidates =
[] 改为调用 card.setLocationCandidates,并传入表示清空候选位置的现有上下文标识。确保该流程同步清理 owner,避免
card.seats 在 location 尚未重置时回退到旧座位。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d4c0dbfc-f0cd-4d72-92fa-b65f4490b69a
📒 Files selected for processing (5)
src/handler/CGsRoleSpellOptRep.jssrc/tracker/CardCounter.tssrc/tracker/Room.tssrc/tracker/roomMovement.tstests/tracker/trackerController.test.ts
直接清空 locationCandidates 不会同步 owner,seats 会回退旧座位。
摘要
变更说明
1. 手气卡回牌堆真正匿名化
根因:
resetKnownToUnknown只把isKnown=false写回牌堆,实体仍保留正 ID。后续未知摸牌会把该实体bind成正 ID 独占暗手,导致discardKnown物化目标只剩匿名槽时第二张解析失败。修复:
Room.anonymizeLocatedIdentity:拆掉cardIndex、身份回到unlocatedIdentities、实体换负 IDCardCounter.releaseLocatedIdentityToUnknown同步计数桶2. 斗地主先手
CGsRoleSpellOptRepType 44 是叫分操作回包,不是最终地主结果;原先用其SeatID调用setTrackerFirstHand会误设先手。现已移除该路径;Type 45 为系统播报地主结果但当前协议侧无法可靠取地主座位,仅作注释占位。验证
pnpm exec vitest run tests/tracker/trackerController.test.ts tests/tracker/handCountObservation.test.ts tests/tracker/anonymousPileSpike.test.ts(45 passed)提交
fix(tracker): 手气卡回牌堆真正匿名化fix(doudizhu): 不再用叫分结果误设先手Summary by CodeRabbit
功能改进
问题修复