diff --git a/backend/src/types.d.ts b/backend/src/types.d.ts index a606980..0ac9c89 100644 --- a/backend/src/types.d.ts +++ b/backend/src/types.d.ts @@ -14,7 +14,7 @@ type UNOCard = { type: CardType; color: CardColor; value: CardValue; - id: undefined; + id: string; }; type Player = { diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index c25ebe0..a4aacce 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: @@ -60,8 +61,13 @@ export function makeCard( 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 }; } /**