codegard1 / blackjack

Nonstandard blackjack game implemented with React and Fluent UI 1
https://ciaervo-blackjack.netlify.app/
0 stars 0 forks source link

PlayerStore and DeckContext both track player hands redundantly #75

Open codegard1 opened 3 months ago

codegard1 commented 3 months ago

PlayerStore is over-engineered for what it needs to do. We use it as a class because then we can call methods directly from instances of Player, but this overlaps too much with GameContext and DeckContext, which is where all of the effort in game logic has gone so far. It would be better to reduce PlayerStore to a type and to manage players directly as plain objects in the gameState, so that there is no confusion about where player hands are being managed and evaluated.

codegard1 commented 3 months ago

Counterpoint to the original comment:

codegard1 commented 3 months ago

This issue will be resolved when all logic referring to player hands is consistent in its data source.

codegard1 commented 3 months ago

We want to avoid making Players a class of their own because then it becomes less straightforward to save and load their state from localStorage. We can use a class (PlayerStore) to manage objects of the Player type instead, localizing functions that are specific to players in the Store while the players themselves are just plain objects. Hence we should deconstruct the Player class and move its class methods up into PlayerStore, and then update any references to the Player class to refer to PlayerStore instead, or to modify the player object directly instead. Also, we'll need to consolidate the Player type and the interface IPlayer to reduce redundancy. If there is no Player class then we don't need an interface for IPlayerState, for example.