Skip to content

Commit

Permalink
engine: resolved temporary eslint error
Browse files Browse the repository at this point in the history
  • Loading branch information
RashiJyotishi committed Jun 2, 2024
1 parent 1991a09 commit b12b0c4
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions backend/uno-game-engine/deck.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const colors: Array<CardColor> = ['red', 'yellow', 'green', 'blue'];
const values = [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'skip',
'reverse',
'draw2',
];
const specialCards = ['wild', 'draw4'];
const deck = [];
// const colors = ['red', 'yellow', 'green', 'blue'];
// const values = [
// '0',
// '1',
// '2',
// '3',
// '4',
// '5',
// '6',
// '7',
// '8',
// '9',
// 'skip',
// 'reverse',
// 'draw2',
// ];
// const specialCards = ['wild', 'draw4'];
// const deck = [];
const sameCardCount = []; // to keep track of same cards in assigning unique id to each card

/**
Expand Down Expand Up @@ -74,7 +74,11 @@ export function makeCard(
* This function shuffles the elements of the given array *in place* . The function behaves in a type-agnostic way.
* Time complexity: O(n)
*/
export function shuffle(deck: Array<any>) {
//todo: Implement a generic shuffling algorithm
[deck[0], deck[1]] = [deck[1], deck[0]];
// elint-disable-next-line
export function shuffle(deck: Array<UNOCard>) {
// 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]];
}
}

0 comments on commit b12b0c4

Please sign in to comment.