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

engine: improved card drawing logic. #48

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

sethdivyansh
Copy link
Contributor

@sethdivyansh sethdivyansh commented Jun 1, 2024

Fixes: #8

Description

Handles the card drawing logic from an empty cardDeck.

  • Reshuffles the thrown cards into the card deck when the card deck is empty and a player needs to draw a card.
  • Return Succes or Error based on the outcome.
  • Also added relevant unit test, in engine.test.ts, to verify this drawCardFromDeck() works correctly.

How to Test

I have created a sample test in engine.test.ts.
just run npm test

Checklist

  • I have tested these changes locally.
  • I have reviewed the code and ensured it follows the project's coding guidelines.
  • I have updated the documentation, if necessary.
  • I have assigned reviewers to this pull request.

@@ -48,10 +48,18 @@ export class GameEngine {
(this.currentPlayerIndex + this.direction) % this.players.length;
}
drawCardFromDeck(player: Player) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should report if it successfully drew card for the player, else return an error.
See the EventResult type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the changes.

Copy link
Collaborator

@kuv2707 kuv2707 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested a minor addition. Once that is done, this should be good to go.

this commit handles the drawing logic from an empty cardDeck.
- It reshuffles the thrown cards into the card deck when the card deck is empty and a player needs to draw a card.
- It returns success message if the card is drawn successfully else returns message error.
- Also added relevant unit test, in engine.test.ts, to verify this function (drawCardFromDeck) works correctly.
@kuv2707 kuv2707 merged commit ad77ddb into shivansh-bhatnagar18:master Jun 4, 2024
6 checks passed
@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 4, 2024

Merged, thanks @sethdivyansh !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve card drawing logic
2 participants