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

Improve card drawing logic #8

Closed
kuv2707 opened this issue May 27, 2024 · 4 comments · Fixed by #48
Closed

Improve card drawing logic #8

kuv2707 opened this issue May 27, 2024 · 4 comments · Fixed by #48
Assignees
Labels
area: Backend(Game Engine) Issues related to the UNO game engine in the backend. bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed priority: high

Comments

@kuv2707
Copy link
Collaborator

kuv2707 commented May 27, 2024

Description

The drawCardFromDeck function in engine.js should handle the scenario when the deck is empty. If the deck is empty, the thrown cards (maintained in another array) should be moved back to the deck before drawing a card for the player.

Current Code Snippet

drawCardFromDeck(player) {
    //todo: Handle the case when the deck is empty and we have to move the thrown cards back to the deck
    this.players.find(p => p.id === player.id).cards.push(this.cardDeck.pop());
}

Expected Output

  • The function should handle the case where this.cardDeck is empty.
  • When the deck is empty, the thrown cards should be shuffled and moved back to the deck.
  • The player should then be able to draw a card from the reshuffled deck.

Notes

  • Ensure that the reshuffling of the thrown cards maintains the game's integrity.
@kuv2707 kuv2707 added bug Something isn't working 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
@Abhishek-Punhani
Copy link

Can I work on this issue?

@ritwik-69
Copy link
Contributor

can i be assigned this issue?

@aayush0325
Copy link

id love to work on this issue

@criticic
Copy link
Contributor

criticic commented Jun 1, 2024

Whoever is solving this, make sure to also handle the case where there is no player with the given id, as after converting to typescript in #33 we get this warning:
Object is possibly 'undefined'.ts(2532), due to find returnign undefined if a match is not found.

Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 1, 2024
Fixed the card drawing logic which would also manage moving thrown cards to deck

Fixes:shivansh-bhatnagar18#8
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 1, 2024
Fixed the card drawing logic which would also manage moving thrown cards to deck

Before drawing the card we check that that deck has sufficient card , if not we move thrown cards back to the deck , otherwise we draw a card and push into the cards of the current player

Fixes:shivansh-bhatnagar18#8
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 1, 2024
Fixed the card drawing logic which would also manage moving thrown cards to deck

Before drawing the card we check that that deck has sufficient card , if not we move thrown cards back to the deck , otherwise we draw a card and push into the cards of the current player

Fixes:shivansh-bhatnagar18#8
@aayush0325 aayush0325 removed their assignment Jun 2, 2024
Abhishek-Punhani pushed a commit to Abhishek-Punhani/multiplayer-uno that referenced this issue Jun 2, 2024
Fixed the card drawing logic which would also manage moving thrown cards to deck

Before drawing the card we check that that deck has sufficient card , if not we move thrown cards back to the deck

 otherwise we draw a card and push into the cards of the current player

Fixes:shivansh-bhatnagar18#8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment