Skip to content

fix(game-states): resolve targetCard jack ownership when parsing multiple jacks (#1210) - #1446

Open
rajpreetcodes wants to merge 1 commit into
cuttle-cards:mainfrom
rajpreetcodes:fix/target-card-jack-ownership
Open

rajpreetcodes wants to merge 1 commit into
cuttle-cards:mainfrom
rajpreetcodes:fix/target-card-jack-ownership

Conversation

@rajpreetcodes

Copy link
Copy Markdown
Contributor

Issue number

Relevant issue number

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

Root Cause

When packing gameState.targetCard or gameState.oneOffTarget into a GameStateRow, packGamestate converted the card object without specifying the player who controlled the target card prior to the move. In concatAttachtToId, when an even number of jacks was attached, cardOwner was evaluated as undefined, leading to serialized strings like TS(JD-undefined,JH-p0) instead of TS(JD-p1,JH-p0).

Changes

  1. In api/helpers/game-states/pack-gamestate.js:
    • Compute targetOwner as the opponent of gameState.playedBy (gameState.playedBy === 0 ? 'p1' : 'p0') when packing targetCard or oneOffTarget.
    • Pass targetOwner to convertCardToStr(value, targetOwner) so attachments on targeted cards know which player was targeted.
  2. In api/helpers/game-states/convert-card-to-str.js:
    • Guard concatAttachtToId so cardOwner defaults safely to 'p0'.
    • Ensure playerNum is guaranteed to resolve to 'p0' or 'p1', preventing any possibility of -undefined appearing in card string outputs.
  3. In tests/unit/specs/sails/game-state.spec.js:
    • Added unit test suite covering targetCard with even (2) jacks, odd (1) jack, and omitted cardOwner safety.

Validation

  • npm run lint: 0 errors
  • npm run test:unit: All 108 tests passing (100 sails + 8 client)
  • npm run build: built cleanly in production

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: gamestaterow.targetCard incorrectly parses ownership of the first jack when there are an even number of jacks

1 participant