Skip to content

Commit

Permalink
Merge branch 'shivansh-bhatnagar18:master' into fix/issue-#20
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwik-69 authored Jun 1, 2024
2 parents 2314476 + f05595c commit 09ad92c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type UNOCard = {
type: CardType;
color: CardColor;
value: CardValue;
id: undefined;
id: string;
};

type Player = {
Expand Down
10 changes: 8 additions & 2 deletions backend/uno-game-engine/deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 };
}

/**
Expand Down

0 comments on commit 09ad92c

Please sign in to comment.