diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index 6d10732..57dff70 100644 --- a/backend/uno-game-engine/deck.ts +++ b/backend/uno-game-engine/deck.ts @@ -16,6 +16,7 @@ const values = [ ]; const specialCards = ['wild', 'draw4']; const deck = []; +const sameCardCount = []; // to keep track of same cards in assigning unique id to each card /** * In a standard UNO deck, there are 108 cards. Here's the breakdown: @@ -56,8 +57,13 @@ export default function getShuffledCardDeck(): Array<UNOCard> { * @returns {UNOCard} The composed UNO card. */ function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard { - //todo: Implement unique identification of cards by assigning an id to each card - return { type, color, value, id: undefined }; + const id = `card-${type}-${color}-${value}`; + + if (!sameCardCount[id]) sameCardCount[id] = 0; + sameCardCount[id]++; // increment the count of same cards to assign unique id + + const uid = `${id}-${sameCardCount[id]}`; + return { type, color, value, id: uid }; } /** diff --git a/backend/uno-game-engine/types.d.ts b/backend/uno-game-engine/types.d.ts index 9d18a0d..82acd7e 100644 --- a/backend/uno-game-engine/types.d.ts +++ b/backend/uno-game-engine/types.d.ts @@ -20,5 +20,5 @@ type UNOCard = { type: CardType; color: CardColor; value: CardValue; - id: undefined; + id: string; };