feat: Enhance draft system with 4-player 'pick 2' rules, minimum player count, and fix pack duplication by ensuring unique pack instances.
All checks were successful
Build and Deploy / build (push) Successful in 1m25s
All checks were successful
Build and Deploy / build (push) Successful in 1m25s
This commit is contained in:
@@ -10,3 +10,5 @@
|
||||
- [Helm Chart Config](./devlog/2025-12-14-214500_helm_config.md): Completed.
|
||||
- [CSV Import Robustness](./devlog/2025-12-16-152253_csv_import_robustness.md): Completed. Enhanced CSV parser to dynamically map columns from headers, supporting custom user imports.
|
||||
- [Fix Socket Mixed Content](./devlog/2025-12-16-183000_fix_socket_mixed_content.md): Completed. Resolved mixed content error in production by making socket connection URL environment-aware.
|
||||
- [Draft Rules & Pick Logic](./devlog/2025-12-16-180000_draft_rules_implementation.md): Completed. Enforced 4-player minimum and "Pick 2" rule for 4-player drafts.
|
||||
- [Fix Pack Duplication](./devlog/2025-12-16-184500_fix_pack_duplication.md): Completed. Enforced deep cloning and unique IDs for all draft packs to prevent opening identical packs.
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# 2025-12-16 - Draft Rules and Logic Implementation
|
||||
|
||||
## Draft Minimum Players
|
||||
- Added backend check in `index.ts` to prevent drafting with fewer than 4 players.
|
||||
- Emit `draft_error` to room if condition is not met.
|
||||
- Added `draft_error` listener in `GameRoom.tsx` to notify users.
|
||||
|
||||
## 4-Player Draft Rules (Pick 2)
|
||||
- Modified `DraftManager.ts`:
|
||||
- Added `pickedInCurrentStep` to track picks within a single pack pass cycle.
|
||||
- Implemented logic in `pickCard`:
|
||||
- If 4 players: Require 2 picks before passing pack.
|
||||
- Else: Require 1 pick.
|
||||
- Logic handles pack exhaustion (if pack runs out before picks completed, it passes).
|
||||
|
||||
## Robustness
|
||||
- Updated `rejoin_room` handler in `index.ts` to send the current `draft` state if the room is in `drafting` status. This allows users to refresh and stay in the draft flow (critical for multi-pick scenarios).
|
||||
@@ -0,0 +1,13 @@
|
||||
# 2025-12-16 - Fix Pack Duplication in Draft
|
||||
|
||||
## Problem
|
||||
Users reported behavior consistent with "opening the same pack twice". This occurs when the pack objects distributed to players share the same memory reference. If the input source (e.g., from Frontend Generator) contains duplicate references (e.g., created via `Array.fill(pack)`), picking a card from "one" pack would seemingly remove it from "another" pack in a future round, or valid packs would re-appear.
|
||||
|
||||
## Solution
|
||||
- Modified `DraftManager.createDraft` to enforce Strict Isolation of pack instances.
|
||||
- Implemented **Deep Cloning**: Even if the input array contains shared references, we now map over `allPacks`, spreading the pack object and mapping the cards array to new objects.
|
||||
- **Unique IDs**: Re-assigned a unique internal ID to every single pack (format: `draft-pack-{index}-{random}`) to guarantee that every pack in the system is distinct, regardless of the quality of the input data.
|
||||
|
||||
## Impact
|
||||
- Ensures that every "pack" opened in the draft is an independent entity.
|
||||
- Prevents state leakage between rounds or players.
|
||||
Reference in New Issue
Block a user