Skip to content

Commit

Permalink
deck: Implement unique identification of cards by assigning an id to …
Browse files Browse the repository at this point in the history
…each card

first created an id as card-type-color-value
and to uniquely identify the same type color value card, I created an card_num array that will to uniquely identify these card
finnaly created an unique id card-type-color-value-num_card[id]
  • Loading branch information
sethdivyansh committed May 28, 2024
1 parent 40be68f commit 77ea2e9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/uno-game-engine/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ export default function getShuffledCardDeck() {
*/
function makeCard(type, color, value) {
//todo: Implement unique identification of cards by assigning an id to each card
return { type, color, value };
let card_num = [];
let id = `card-${type}-${color}-${value}`

if(!card_num[id]) card_num[id] = 0
card_num[id]++ // as there are more then one card of same type, color and value
// this will help to identify the card uniquely
// by counting the number of cards of same type, color and value

let uid = `${id}-${card_num[id]}`
return { type, color, value, id: uid };
}

/**
Expand Down

0 comments on commit 77ea2e9

Please sign in to comment.