Thousand Card Game: Is The Game Finished?

in #utopian-io7 years ago

image.png
Image source: pixabay.com

What is this project about?

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

PR:

https://github.com/gornanization/1k/pull/32

Details:

How can we check whether finishing game logic works properly? Do we have to walk through ~20 battles and then pray a player will have enough points to observe finishing game process?

Nope we don't. We can simulate case of the last trick in the last battle. I did it, here it is:

image.png

Let's review such state, together.
Imagine we have three players: adam, alan, and pic (see players). We want pic to win the game. As you look through players.battlePoints you will notice, that he has 900 points already! So, in order to win the game, he has to be the last battle winner. In order to be a battle winner, he has to be battle leader (player who have won bidding phase). We can set his bid value as the default one, 100 points, and let the opponents stick with it and pass (see bid).

How about the last trick? Set pic as a leader (battle.leadPlayer), and put two cards on table (battle.trickCards). Let's say, A♦ and 9♦. As pic is the trick leader, A♦ card was thrown by him. Next card on the table belong to next player in turn (adam), so it appears, it's alan turn. As it's last trick, the only card which is hold by player is 10♦. And it's alan's card. (see cards). Where are remaining 21 cards? It belongs to pic (see battle.wonCards) as he won it in previous tricks.

So what happens when alan will throw a card? On the table we will have A♦ and 9♦ and 10♦. In this case, greatest rank win, so pic who throw A♦ will be the trick winner. Eventually, all cards will belong to pic which gives him total 120 points in this battle. As he was bidding 100 points, only this value is his total score for this battle, giving him 900 + 100 = 1000 points.

An basically, it is the end of the game. Within our unit test we can now:

  1. Initialize game with given state.
  2. Call action:
    thousand.throwCard(createCard('10♦'), 'alan')
  3. and observe an output.

Here is a unit test fragment:

image.png

What we have to check after game finished?

  1. Is given action (:300) performed succesfully? (:304 - :306)
  2. Does the API propagate specific events? (:307 - :314)
  3. What is the result player board? (:316 - :320)
  4. Eventually, who is the winner? (:322)

Now, we are confident, that finishing game works as expected. Coverage increased (+2.3%) to 98.116%. That's it for today.

See you soon, game winners!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @adasq I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 57978.54
ETH 2283.22
USDT 1.00
SBD 2.47