diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index a83ebcd..f1c62ca 100644 --- a/backend/uno-game-engine/deck.ts +++ b/backend/uno-game-engine/deck.ts @@ -84,6 +84,13 @@ export function makeCard( 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 }; + 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 }; } @@ -98,4 +105,10 @@ export function shuffle(deck: Array) { const j = Math.floor(Math.random() * i); [deck[i], deck[j]] = [deck[j], deck[i]]; } +export function shuffle(deck: Array) { + // Fisher-Yates shuffle algorithm to shuffle card deck + for (let i = deck.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * i); + [deck[i], deck[j]] = [deck[j], deck[i]]; + } }