Assess shuffle randomless

Game development with Board Game Arena Studio
Post Reply
User avatar
Woodruff
Posts: 138
Joined: 08 March 2014, 00:53

Assess shuffle randomless

Post by Woodruff » 08 September 2019, 08:17

Hi everybody :)

I don't want to be polemic here whatsoever, but I have some doubts about the "randomless quality" of the shuffle method on a Deck component.
(If that ever means anything, true randomless cannot be achieved on a computer science).
Indeed, I feel that unbalanced distribution tends to occur more often than it would in reality (won't say it's impossible though, still proba).

For example in these two card-based games:
  • French Tarot: when a bout happens to be in the Kitty, I have the impression (and not just me) that this has great odds to occur again in the same game.
  • Tock (not published officially yet, currently in alpha mode): I have reports that in 5 or 6 player games, some players did not receive an Ace nor a King in their hands 4, 5, 6 up to 7 times a row (4 cards being picked at each round by each player, all cards being gathered and shuffled when the deck is empty). This situation is quite rare, if ever seen, IRL.
I would like to run some programmatic tests using the Studio in order to assess the results given by the method simulating a great number of shuffles, to know if there is any bias or if that is just my idea. But I could not find on the web relevant algorithms I could apply in that situation. Would you have any ideas of some experiments I could run to have objective figures?

Thanks a lot! Do not hesitate if I am not clear...
Cheers,

Woodruff


User avatar
sourisdudesert
Administrateur
Posts: 3849
Joined: 23 January 2010, 22:02

Re: Assess shuffle randomless

Post by sourisdudesert » 08 September 2019, 12:39

At first, please check:
https://boardgamearena.com/faq?anchor=f ... ing_random

As you can see, for the specific case of cards shuffling, we are using PHP "shuffle" function, which is used by most Poker service.

The randomness of this function is not suitable for "cryptographic" applications, but is totally adapted for gaming services.

Feel free to register on the Studio to check by yourself. You can even get an access to the sourcecode of French Tarot and make a copy of it.

Spoiler: the PHP shuffle function is quite good and is widely used, so there are chances that your conclusion will be that it is working as expected. If you have doubts, I would suggest you to start by doing the maths (probabilities) and compare this to the actual results. I'm pretty sure that this will save you a lot of programming effort :)

User avatar
eoc
Posts: 102
Joined: 11 January 2017, 20:10

Re: Assess shuffle randomless

Post by eoc » 08 September 2019, 13:10

sourisdudesert wrote:
08 September 2019, 12:39
Feel free to register on the Studio to check by yourself. You can even get an access to the sourcecode of French Tarot
You might want to check the history of Woodruff's account name for background info on why that probably already happened ;)

How's the entropy? https://phpsecurity.readthedocs.io/en/l ... alues.html

User avatar
Woodruff
Posts: 138
Joined: 08 March 2014, 00:53

Re: Assess shuffle randomless

Post by Woodruff » 16 September 2019, 11:41

Hello,

Thanks for your answers!
sourisdudesert wrote:
08 September 2019, 12:39
At first, please check:
https://boardgamearena.com/faq?anchor=f ... ing_random
Thank you, I did not see that thread. That reassures me on the strongness of the generator.
I take it then, and especially it would take time to run tests myself anyway, since I am not an expert in probabilities (I thought there might have been more straightforward solutions).
Feel free to register on the Studio to check by yourself. You can even get an access to the sourcecode of French Tarot and make a copy of it.
In fact I am the dev of the Tarot :) (I was formerly Tchebychev).
So I thought the problem, if any, could lies on my code, not the code of shuffle. I doubled checked, and I see nothing that can question the random behaviour brought by shuffle, the code dealing with that is tiny, here's an extract:

Code: Select all

// Take back all cards (from any location => null) to deck and shuffle
$this->cards->moveAllCardsInLocation(null, "deck");
$this->cards->shuffle('deck');

// Deal 13 cards to each players (and signal the UI to clean-up)
self::notifyAllPlayers('cleanUp', clienttranslate('${player_name} deals a new hand.'), array('player_name' => $dealer_name, 'dealer_id' => $dealer_id));

// Create deck, shuffle it and give initial cards
$players = self::loadPlayersBasicInfos();
$invalid_hand = false;
$trump_1_found = false;
foreach($players as $player_id => $player) {
       $hand = $this->cards->pickCards(self::getGameStateValue('card_number_for_each_player'), 'deck', $player_id );
       
       // Notify player about his cards
       self::notifyPlayer($player_id, 'newHand', clienttranslate('-- Your cards are:&nbsp;<br />${cards}'), array(
            'cards' => self::listCardsForNotification($hand),
            'hand' => $hand,
       ));
            
       // [...] here some checks to reject the hand if the player has the 1 of Trumps with no other Trump
       // This is not related to the shuffling mechanism itself
}

// The remaining cards in the deck location form the Kitty, even if that differs from the IRL way to do, it is equivalent IMHO

Post Reply

Return to “Developers”