Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to uniquely identify cards #4

Closed
kuv2707 opened this issue May 27, 2024 · 3 comments · Fixed by #14
Closed

Make it possible to uniquely identify cards #4

kuv2707 opened this issue May 27, 2024 · 3 comments · Fixed by #14
Labels
area: Backend(Game Engine) Issues related to the UNO game engine in the backend. good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kuv2707
Copy link
Collaborator

kuv2707 commented May 27, 2024

Description

The makeCard function in deck.js should assign a unique id to each card to ensure each card can be uniquely identified.

Current Code Snippet

/**
 * Helper function to make a card object.
 * @param {string} type one of ['number', 'special', 'wild']
 * @param {string} color one of ['red', 'yellow', 'green', 'blue']
 * @param {string} value the numeric value as string or the special card name ("skip", "reverse", "draw2", "wild", "draw4")
 * @returns {{type: string, color: string, value: string, id: unknown}} card - An object representing an UNO card.
 */
function makeCard(type, color, value) {
    //todo: Implement unique identification of cards by assigning an id to each card
    return { type, color, value };
}

Expected Output

Each card object returned by makeCard should include a unique id property.

Some discussion is needed on the type of unique identification used. We can choose from UUID, random numbers etc.
Please propose your approach here and you will be assigned accordingly.

Notes

  • Ensure the id is unique for every card created.
  • Update the JSDoc accordingly.
@kuv2707 kuv2707 added help wanted Extra attention is needed good first issue Good for newcomers area: Backend(Game Engine) Issues related to the UNO game engine in the backend. labels May 27, 2024
@criticic
Copy link
Contributor

While UUID is not a bad option, it would probably not make sense for us, considerng there are only 108 possible options. And we'd need to save this information somewhere.

Instead we could use a certain scheme so that the id itself encodes some information, so something like red-skip, blue-reverse, green-2

@shivansh-bhatnagar18
Copy link
Owner

@kuv2707 Could you please suggest what sort of unique-id should we prefer to assign to the cards

@kuv2707
Copy link
Collaborator Author

kuv2707 commented May 30, 2024

#14 Provides a viable solution.

The problem with uuids is that they would be a little slow, and since we only have a very bounded and predictable set of 108 cards, it makes sense to use a simpler id generation scheme. Also, it saves us from adding a dependency.

sethdivyansh added a commit to sethdivyansh/multiplayer-uno that referenced this issue May 31, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
sethdivyansh added a commit to sethdivyansh/multiplayer-uno that referenced this issue May 31, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
sethdivyansh added a commit to sethdivyansh/multiplayer-uno that referenced this issue May 31, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
sethdivyansh added a commit to sethdivyansh/multiplayer-uno that referenced this issue Jun 1, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
kuv2707 pushed a commit that referenced this issue Jun 1, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes #4
sksmagr23 pushed a commit to sksmagr23/multiplayer-uno that referenced this issue Jun 2, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 2, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4

backend:deck.ts

This commit involves one preperatory commit : adding wild color to CardColors

Added deck generation function to initialize the deck according to given constraints

The function generates cards and push them the deck array generating cards of each color and also wild cards

Also have checked the deck composition with jest tests

Fixes :shivansh-bhatnagar18#1
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 2, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 2, 2024
 Added wild color for wild cards like colchange and draw4 cards

 these changes are made in types.d.ts

backend:deck.ts

This commit involves one preperatory commit : adding wild color to CardColors

Added deck generation function to initialize the deck according to given constraints

The function generates cards and push them the deck array generating cards of each color and also wild cards

Also have checked the deck composition with jest tests

Fixes :shivansh-bhatnagar18#1

deck: Assigned unique id to each card.
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 4, 2024
- Globally exposed the GameEngine type.
- Declared types pertaining to game events.

api: Implement server side of long polling.

This commit adds a handler for GET /events which
stores the response object for the client for emitting
events in the future.

engine: Implement structure for game event handling.

Created a module to deal with executing events
on the game object.

prettier: Use LF for line endings.

deck: Assigned unique id to each card.
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4

deck: Implemented Fisher-Yates shuffling algorithm to shuffle the deck
Fixes: shivansh-bhatnagar18#2

lint: Fix prettier and eslint conflict.

The two systems conflicted over indentations in
switch case.

typescript: Add some compiler options.
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 4, 2024
- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Backend(Game Engine) Issues related to the UNO game engine in the backend. good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
3 participants