Skip to content

Feat/hand limit rework#1359

Open
itsalaidbacklife wants to merge 10 commits into
mainfrom
feat/hand-limit-rework
Open

Feat/hand limit rework#1359
itsalaidbacklife wants to merge 10 commits into
mainfrom
feat/hand-limit-rework

Conversation

@itsalaidbacklife
Copy link
Copy Markdown
Contributor

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

  • Resolves #

Please check the following

  • Do the tests still pass? (see Run the Tests)
  • Is the code formatted properly? (see Linting (Formatting))
  • For New Features:
    • Have tests been added to cover any new features or fixes?
    • Has the documentation been updated accordingly?

Please describe additional details for testing this change

itsalaidbacklife and others added 2 commits May 2, 2026 12:26
… 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>
@itsalaidbacklife itsalaidbacklife added version-major A large update that warrants changing the MAJOR version of the app e.g. (4.0.0 => 5.0.0) backend Requires changes to the (node) backend webserver frontend Requires changes to the frontend (vue) client rules change Adjustment to the rules of the game labels May 2, 2026
Copy link
Copy Markdown
Contributor Author

@itsalaidbacklife itsalaidbacklife left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drafted, needs iterating

Comment on lines +144 to +161
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;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to use turn instead

Comment on lines +124 to +126
return `${player} discarded the ${getFullCardName(discardedCards[0])} ${
discardedCards.length > 1 ? `and the ${getFullCardName(discardedCards[1])} ` : ''
}to the hand limit.`;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread api/helpers/game-states/moves/discard-to-hand-limit/validate.js
Comment thread docs/game-state-api.md
},
};

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:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename publishGameState

Comment thread src/stores/game.js
Comment on lines +222 to +223
case GamePhase.DISCARDING_TO_HAND_LIMIT:
return (player.value?.hand?.length ?? 0) <= 8;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check the turn instead. Could coalesce the 5 case above

Comment thread src/stores/game.js
});
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,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use turn instead

Comment thread src/plugins/sockets/inGameEvents.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Requires changes to the (node) backend webserver frontend Requires changes to the frontend (vue) client rules change Adjustment to the rules of the game version-major A large update that warrants changing the MAJOR version of the app e.g. (4.0.0 => 5.0.0)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant