Feat/hand limit rework#1359
Conversation
… phase Introduces a new DISCARDING_TO_HAND_LIMIT game phase (value 6) so players can always draw or resolve moves that overflow the 8-card hand limit, then discard down immediately rather than being blocked upfront. - Draw: removed the block-at-8 validation; drawing a 9th card enters the new phase instead of incrementing turn - Five: always draws 3 cards (removed the spaceInHand cap); overflows trigger the discard phase - Nine: if the returned card pushes the targeted player over 8, they enter the discard phase before getting their turn - New discard-to-hand-limit validate/execute helpers; supports discarding 1 card (hand=9) or 2 cards (hand=10) in a single move - Frontend: DiscardToHandLimitDialog, game store computed/action wiring, socket event handler, and i18n strings - AI: generates all valid discard combinations for the new move type - Tests: updated basicMoves, 5_fives, and 9_nines specs; new handLimit.spec.js Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nd limit, triggering discard dialog for player'
itsalaidbacklife
left a comment
There was a problem hiding this comment.
Drafted, needs iterating
| const overflowCount = playerHand.length - 8; | ||
| if (overflowCount <= 0) {break;} | ||
| const getCombinations = (arr, k) => { | ||
| if (k === 1) {return arr.map((item) => [ item ]);} | ||
| const result = []; | ||
| for (let i = 0; i <= arr.length - k; i++) { | ||
| for (const rest of getCombinations(arr.slice(i + 1), k - 1)) { | ||
| result.push([ arr[i], ...rest ]); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| res = getCombinations(playerHand, overflowCount).map((combo) => ({ | ||
| moveType, | ||
| playedBy, | ||
| discardedCards: combo.map((card) => card.id), | ||
| })); | ||
| break; |
There was a problem hiding this comment.
Should investigate this from a performance perspective. Recursion smells and I could see this blowing up
| return exits.success((currentState.turn + 1) % 2); | ||
|
|
||
| case GamePhase.DISCARDING_TO_HAND_LIMIT: | ||
| return exits.success(currentState.p0.hand.length > 8 ? 0 : 1); |
There was a problem hiding this comment.
Refactor to use turn instead
| return `${player} discarded the ${getFullCardName(discardedCards[0])} ${ | ||
| discardedCards.length > 1 ? `and the ${getFullCardName(discardedCards[1])} ` : '' | ||
| }to the hand limit.`; |
There was a problem hiding this comment.
Generalize to n cards
| for (const cardId of discardIds) { | ||
| const cardIndex = player.hand.findIndex(({ id }) => id === cardId); | ||
| if (cardIndex !== -1) { | ||
| discardedCards.push(player.hand[cardIndex]); |
There was a problem hiding this comment.
Should we be this defensive. Given that validate runs first we could take discarded cards as-is. But this further ensures we sanity check which isn't crazy.
Syntactically if we're constructing discarded cards from the ones we find, I'd prefer this in three lines, splice then two pushes
| }, | ||
| }; | ||
|
|
||
| The `emitGameState()` helper is used to send the latest game state to the client. For the MVP rollout, it will emit an event that matches the current data structure used by the client in production, e.g: |
There was a problem hiding this comment.
Rename publishGameState
| case GamePhase.DISCARDING_TO_HAND_LIMIT: | ||
| return (player.value?.hand?.length ?? 0) <= 8; |
There was a problem hiding this comment.
This should check the turn instead. Could coalesce the 5 case above
| }); | ||
| const showResolveFive = computed(() => phase.value === GamePhase.RESOLVING_FIVE && isPlayersTurn.value); | ||
| const showDiscardToHandLimit = computed( | ||
| () => phase.value === GamePhase.DISCARDING_TO_HAND_LIMIT && (player.value?.hand?.length ?? 0) > 8, |
There was a problem hiding this comment.
Should use turn instead
Revises how the hand limit works so that at the end of your turn, you discard down to 8 (no other limitations on moves)
Issue number
Relevant issue number
Please check the following
Please describe additional details for testing this change