Thousand Card Game: Not enough points to start a battle...

in utopian-io •  last year


Image source: pixabay.com

What is this project about?

This contribution is made to gornanization/1k, gornanization/1k-table and gornanization/1k-client projects. If you would like to find more info - I strongly recommend reading this post first.

PRs:

  1. https://github.com/gornanization/1k-client/pull/4
  2. https://github.com/gornanization/1k/pull/47
  3. https://github.com/gornanization/1k-table/pull/16

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:

image.png

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).

image.png

Having such information we can now extend the state transition logic:

image.png

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:

image.png

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.

image.png

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.

image.png

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:

image.png

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!

Cheers, players!


Recent articles:

  1. Thousand Card Game: Increasing bid value!
  2. Thousand Card Game: Connecting to the game table
  3. Thousand Card Game: The battle is over...



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hey @adasq! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.gg/Pc8HG9x