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

gameEvent: Implement Throw Card Event #50

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

criticic
Copy link
Contributor

@criticic criticic commented Jun 2, 2024

Description

adds the throw card handler

Fixes #44

Motivation and Context

[Explain the motivation behind these changes and provide any relevant context.]

How to Test

[Describe the steps to test the changes made in this pull request.]

Related Issues

[If applicable, mention any related issues or pull requests.]

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.

Screenshots (if applicable)

[If your changes include any visual updates, provide screenshots here.]

@criticic criticic marked this pull request as ready for review June 3, 2024 07:52
@criticic criticic force-pushed the feat/event-throw-card branch from 96835ef to 5656cd6 Compare June 3, 2024 07:56
@criticic criticic changed the title throw card DRAFT gameEvent: Implement Throw Card Event Jun 3, 2024
@criticic criticic force-pushed the feat/event-throw-card branch from 5656cd6 to 273d3d5 Compare June 3, 2024 07:58
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.

This seems promising, but is blocked by other issues currently.

ARCHITECTURE.md Outdated
"data": {
"cardID": "red-5"
"card": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd want to use the CardID here
We'd have to be able to retrieve all cards by id.
Can you do that in a commit before the actual changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do it in a moment, rest of the things, i feel i have done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there much to do in this PR, apart from the documentation change, I guess the api handler will have a get card from card id function

Copy link
Collaborator

@kuv2707 kuv2707 Jun 12, 2024

Choose a reason for hiding this comment

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

You should address all the feedback so far first.

backend/uno-game-engine/engine.ts Outdated Show resolved Hide resolved
return player.cards.find((c) => c.id === cardId);
}

export function throwCard(game: GameEngine, event: GameEvent): EventResult {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some minor changes need to be made to the logic when the drawCard function is completed. I'll review it once that is done.

@kuv2707 kuv2707 added under review There have been some rounds of review on the code changes in the PR. area: Backend(Game Engine) Issues related to the UNO game engine in the backend. labels Jun 3, 2024
@criticic criticic force-pushed the feat/event-throw-card branch from 273d3d5 to 334ad0a Compare June 3, 2024 13:57
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.

Looks great!
Posted few comments.

backend/uno-game-engine/events/throwCard.ts Outdated Show resolved Hide resolved
backend/uno-game-engine/events/throwCard.ts Outdated Show resolved Hide resolved
@criticic criticic force-pushed the feat/event-throw-card branch from 334ad0a to 6993e75 Compare June 7, 2024 08:46
Copy link

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
multiplayer-uno ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 2:17pm

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.

Posted some comments.
Mainly, we'd need to work on:

  • tests for the logic
  • keeping special and wild separate.

@@ -1,7 +1,7 @@
// We declare those types which are used throughout the application here.
// For types that are used only in one file, we can declare them in that file itself.

type CardType = 'number' | 'special' | 'wild';
type CardType = 'number' | 'special';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for removing the wild type?
It made logical sense to separate special from wild, since some of the game rules (like DRAW4CHALLENGE) depend on counting the number of wild cards the user has. I think we'd want to keep them separate from special cards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reasoning was that wild cards are just colorless special card, in the sense that they do soemthing to the game state, instead of just getting added to the pile.

i not aware of the draw4challenge rule, whenever i have played it before, we never had it, Though i guess uno is popular for everyone having their own rules, if its a official/popular rule, I'll add it back ig

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wasn't aware of it either. But the rules we are following (link in ARCHITECTURE.md) mention it and it seems fun to implement.
Even if that weren't the case, it is a good idea to model the types after the actual game objects/properties.

backend/src/uno-game-engine/engine.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd need to add tests for all the logic here. This seems to be a crucial part of the game logic with many imaginable corner cases and bugs, so we'd need to look out for them in the tests.

@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 7, 2024

@criticic Please prioritize this PR over any new work as this will help further work on the engine.

@kuv2707 kuv2707 force-pushed the master branch 3 times, most recently from 4dd6ce4 to 7bc3d56 Compare June 8, 2024 19:10
@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 11, 2024

@criticic Are you working on it or should I close it?

@criticic
Copy link
Contributor Author

criticic commented Jun 11, 2024 via email

Adds the throw card event handler.

Fixes shivansh-bhatnagar18#44

Signed-off-by: Sagnik Mandal <[email protected]>
@criticic criticic force-pushed the feat/event-throw-card branch from 937e3a0 to 435d475 Compare June 12, 2024 14:16
}
"type": "THROW_CARD",
"playerId": "1",
"cardId": "card-number-red-5",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd want to go with the data object here.

return { type: 'ERROR', message: 'Player not found' };
}

const card = findCard(player, event.data.card.id);
Copy link
Collaborator

@kuv2707 kuv2707 Jun 12, 2024

Choose a reason for hiding this comment

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

It seems unnecessary to send the whole card object from the client when we can use id. I had earlier mentioned that we must setup a function to retrieve cards by id. In accordance with that, we will only be sending the card id from the frontend.

Copy link
Collaborator

Choose a reason for hiding this comment

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

These provide foundational tests for the game engine, which is good to have.

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.

The logic needs some minor reworking. For the record, the THROW_CARD event object will have cardId as the only attribute in its data.
Also:

  • We should shift the getting-card-by-id function to deck.ts.
  • As mentioned earlier, it is very important to have tests for the throw-card logic because of subtle corner cases.

I think we can defer the tests for now, given that we are a little behind the schedule, but please be motivated to follow up on this with the tests. (you can open a PR for that even without any issue).

Despite some minor issues, I think we can merge it as it is good enough for the time being. I'll make some of the amendments in subsequent commits.

Some general suggestions:

  • Respond to all feedback, even with an emoji reaction. This lets the maintainer know that the particular feedback has been addressed.
  • Tag the maintainer if you want another review.

@kuv2707 kuv2707 merged commit 0b74c25 into shivansh-bhatnagar18:master Jun 12, 2024
8 checks passed
@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 12, 2024

Merged, thanks @criticic

@criticic
Copy link
Contributor Author

criticic commented Jun 12, 2024 via email

@criticic
Copy link
Contributor Author

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. priority: high under review There have been some rounds of review on the code changes in the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a game event handler for the "THROW_CARD" event.
2 participants