Image source: pixabay.com
What is this project about?
Here is a list of features / improvements applied within the contribution:
Not enough points in cards...
While developing thousand card game logic I have forgotten about important rule. After dealing cards, each player cards set has to have at least 18 points in cards.
An example? Sure. Over here:
['A♥', 'K♥', 'Q♥']
we have 18 points (11 + 4 + 3), but here:
['A♥', 'K♥', 'J♥']
we have 17 points (11 + 4 + 2), so it's not enough for player to start a battle. 18 points is a general rule, but we can customize it within a
shuffleAgainIfPointsCountLessThan property in a settings object:
A new function
playersHaveEnoughtCardPoints takes a game state as an argument, and returns
boolean value representing whether we can continue a game, or force re-shuffling cards (source code below).
Having such information we can now extend the state transition logic:
So, if players have enough card points, let's move to
BIDDING_START phase, othewise, move to a new state (
NOT_ENOUGHT_CARD_POINTS) which eventually forces cards to be shuffled again.
The feature has been also covered with unit tests, both on unit and integration level.
Having such logic prepared, we have to update 1k-table project to handle the a new state:
When a new state is applied, we do perform short delay and eventually move all cards back to a deck.
Player name displayed on the top of the client app
Not a big thing, but it helps me testing in-browser.
Game activity feed
Sometimes it's not easy to track current state of a game, so a new component,
Logs has been created. It displays last 7 activities, so then players can quickly find out, whose turn is it, or which of the opponents has thrown a given card. An example below.
Quick State Updater created
Quick State Updater is a simple function, which allows a table owner to update a state of a currently displayed game. We can achieve it by calling
update via Browser Dev Tools. An example of usage:
This forces the game state update. After doing so, we can refresh a page, so then a new game state will be rendered.
What is it for?
For testing purpose. Remember the first described feature, Not enough points in cards...?
The game state which you can see above does reproduce such case, so we can observe how does the game behaves.
Look at the game
phase, we have
DEALING_CARDS_FINISHED state active. As dealing cards phase is finished, we have card sets assigned to the players (see
cards property, 7 cards for each player) as well as to the deck (see
deck property, 3 cards over there).
As you can observe, player adam has following set of cards:
['9♥', '9♦', '9♣', 'J♥', 'Q♥', 'K♥', '9♠']
The total number of points is:
0 + 0 + 0 + 2 + 3 + 4 + 0 = 8
This number (8) is less than 18 (as specified in
settings.shuffleAgainIfPointsCountLessThan) so the game logic will reshuffle cards again, so we can verify, whether a new feature works properly for table client app!
More details? See PRs linked above!
- Thousand Card Game: Increasing bid value!
- Thousand Card Game: Connecting to the game table
- Thousand Card Game: The battle is over...
Posted on Utopian.io - Rewarding Open Source Contributors