Page 1 of 2
Bug found in hanabi, please upvote
Posted: 07 October 2024, 00:35
by HanabiGrandMaster
I've noticed that, when shuffling a card (recovered by flamboyant) back into the deck, it gets put on top a disproportionate amount of times. It appears the shuffle function is broken.
Please upvote the bug report here:
https://boardgamearena.com/bug?id=141063
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 12:42
by Blacktango
Honestly, I never noticed such a behavior.
And looking into the code, here is the used algorithm:
- count the number of cards in the deck
- randomly choose a number position between 1 and the number of the card in the deck
- put the chosen card from the discard into the deck at this random position
Note that the deck is never shuffled, during the operation.
When you play IRL with the physical game, you usually shuffle it, to avoid you to know where is the card you put back in the deck, which is not required on BGA.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 14:31
by Jellby
Hmm... It doesn't really matter, but I would prefer it if the deck was actually shuffled. I don't want to know what would have happened if I hadn't put that useless card in the deck

Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 14:39
by Jellby
Blacktango wrote: ↑07 October 2024, 12:42
- count the number of cards in the deck
- randomly choose a number position between 1 and the number of the card in the deck
Shouldn't it be between 0 and the number of cards in the deck, or counting the number of cards
after the new card has been added?
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 14:49
by ufm
Jellby wrote: ↑07 October 2024, 14:39
Blacktango wrote: ↑07 October 2024, 12:42
- count the number of cards in the deck
- randomly choose a number position between 1 and the number of the card in the deck
Shouldn't it be between 0 and the number of cards in the deck, or counting the number of cards
after the new card has been added?
$deckcards = $this->cards->getCardsInLocation( 'deck' );
$nbr_cards = count( $deckcards );
$new_card_pos = bga_rand( 0, $nbr_cards );
Actually between 0 and count is correct.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 15:47
by Stroom
Jellby wrote: ↑07 October 2024, 14:31
Hmm... It doesn't really matter, but I would prefer it if the deck was actually shuffled. I don't want to know what would have happened if I hadn't put that useless card in the deck
Same. If the rules say shuffle then shuffle properly. Between 2 and 40 cards it's quite a cheap operation.
Maybe there could be some kind of probabilistic proof that it does matter, similar to Monty Hall problem, but I'm not sure. Where the odds of specific cards would be at the beginning of the game (1/50) could be somewhat different than after putting a card back and shuffling (at 10 cards, 1/10 each). Most likely it's a different scenario that makes the probabilities similar though.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 16:18
by Romain672
Just get a sample of 10, in your next game, where deck is about half full, that should be enough to tell if something is wrong or not HanabiGrandMaster.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 18:07
by Jellby
Stroom wrote: ↑07 October 2024, 15:47
Maybe there could be some kind of probabilistic proof that it does matter
It doesn't matter because the order of the remaining cards had no effect in the game up to that point, so whatever the result after shuffling, you can just pretend the cards were in that order from the beginning, with the same probability.
Say there are two cards remaining: 1 and 2. They're either 1,2 or 2,1, 50-50. Now you put the 3 back and shuffle: no matter where the 3 ends, still the 1 is either before or after the 2, still 50-50. No one could see what it was, so instead of choosing one again, just keep the old choice.
similar to Monty Hall problem
The trick with the Monty Hall problem is that Monty
knows what's behind each door and will
always open a door with a goat. If he didn't know, or if he would act randomly (or arbitrarily), there would be no benefit in changing. Same here, there's no information on the remaining deck, so no need to shuffle. In real life, you could ask an external person to secretly put the card back in a random position without shuffling, and (provided this person is truly random) it would also be the same.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 19:27
by HanabiGrandMaster
Romain672 wrote: ↑07 October 2024, 16:18
Just get a sample of 10, in your next game, where deck is about half full, that should be enough to tell if something is wrong or not HanabiGrandMaster.
My most recent games with flamboyants:
~
https://boardgamearena.com/gamereview?table=572044125 - gets put on top ( 0 cards in deck ) ~
https://boardgamearena.com/gamereview?table=572194276 - gets put on top ( 4 cards in deck)
https://boardgamearena.com/gamereview?table=572095101 - gets put on top ( 16 cards in deck )
https://boardgamearena.com/gamereview?table=572490978 - doesn't get put on top ( 3 cards in deck)
https://boardgamearena.com/gamereview?table=572121459 - doesn't get put on top ( 7 cards in deck )
https://boardgamearena.com/gamereview?table=572488290 - doesn't get put on top ( 9 cards in deck )
https://boardgamearena.com/gamereview?table=572060730 - doesn't get put on top ( 10 cards in deck )
https://boardgamearena.com/gamereview?table=572093334 - doesn't get put on top ( 13 cards in deck )
https://boardgamearena.com/gamereview?table=572455184 - doesn't get put on top ( 17 cards in deck )
https://boardgamearena.com/gamereview?table=572104608 - doesn't get put on top ( 22 cards in deck )
https://boardgamearena.com/gamereview?table=572477334 - doesn't get put on top ( 39 cards in deck )
Statistics was too long ago for me. But I feel like it's (1/4 * 1/16) is 1.5% (despite my small sample size). My teammate commented that he had a similar feeling; in general. Since it appears to happen in games with a smaller remaining deck, my suspicion is that "top" is overrepresented.
ufm wrote: ↑07 October 2024, 14:49
$deckcards = $this->cards->getCardsInLocation( 'deck' );
$nbr_cards = count( $deckcards );
$new_card_pos = bga_rand( 0, $nbr_cards );
Are we sure that $deckcards is the number-of-cards-remaining-in-draw-pile, and not the total number?
*edit: Updated with four more games.
Re: Bug found in hanabi, please upvote
Posted: 07 October 2024, 19:44
by Jellby
HanabiGrandMaster wrote: ↑07 October 2024, 19:27
Statistics was too long ago for me. But I feel like it's (1/4 * 1/16) is 1.5%
Only if you cherry-pick the two cases where it was on top (and I guess it would be 1/5*1/17): That's the probability of getting the card on top on those two particular instances. But one should be looking at something like what's the probability of it happening at least twice in your six samples (the one with 0 cards should not be counted).
The probability of it never happening (in those cases) is 4/5*16/17*7/8*10/11*13/14*22/23 = 53.2%
The probability of it happening exactly once is, if I didn't make any mistake, 36.1%
So the probability of happening twice or more is 10.7%, not as unlikely as you probably thought.
I haven't done the numbers, but I suspect if the shuffling was done wrong (by counting all cards), the probability of having it happen "only" twice in that sample would be significantly lower.
ETA: OK, I've done it now, it's around 0.7%. So it's much more likely that the shuffling is right than wrong (at least for that particular kind of wrong).
ETA2: It's 0.7% with 40 cards, but I don't know why I used 40. With 70 cards it's 0.0%