diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index 6d10732..84ffd80 100644 --- a/backend/uno-game-engine/deck.ts +++ b/backend/uno-game-engine/deck.ts @@ -66,5 +66,9 @@ function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard { */ function shuffle(deck: Array) { //todo: Implement a generic shuffling algorithm - [deck[0], deck[1]] = [deck[1], deck[0]]; + // Fisher-Yates shuffle algorithm + for (let i = deck.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * i); + [deck[i], deck[j]] = [deck[j], deck[i]]; + } }