diff --git a/backend/uno-game-engine/deck.ts b/backend/uno-game-engine/deck.ts index a4aacce..033a3c3 100644 --- a/backend/uno-game-engine/deck.ts +++ b/backend/uno-game-engine/deck.ts @@ -75,6 +75,11 @@ export function makeCard( * Time complexity: O(n) */ export function shuffle(deck: Array) { - //todo: Implement a generic shuffling algorithm - [deck[0], deck[1]] = [deck[1], deck[0]]; + + for (var i = deck.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var temp = deck[i]; + deck[i] = deck[j]; + deck[j] = temp; + } }