Country Selection not Random? #235

Domphalos opened this Issue May 3, 2016 · 6 comments


None yet

3 participants


In the American Empire map i have had Texas all 4 times I have played. The probability of this occurring randomly is 1 in 10,000. I had a similar issue with Austria on the Classic map. The first 4 times I played a no chat version I got Austria all 4 times. This is not as improbable as the previous example but still pretty improbable at 1 in 2303.


Update. It is now 5 times in a row for Texas, a 1 in 100,000 chance.

kestasjk commented Jun 7, 2016

Hmm, thanks for pointing this out.. I think there actually is an issue with country selection..

The way it works is whenever you get a country your weighting for that country is halved, and your chance of being that country next time is relative to your weighting for that country. But the system has to decide who to choose a country for first, since the second person won't be able to get that country.

The system is supposed to select the most unbalanced player first, since they deserve to get the country according to their unbalanced weightings. It does this by taking the standard deviation of the country weightings, and the player with the largest standard deviation is taken as the most unbalanced, and they get the first pick of country.

Having done a few scenarios in a spreadsheet though this isn't nearly as good a measure of who is the most unbalanced as I thought.. If you start balanced and get the same country 10 times in a row you have a standard deviation of ~0.1, but if you start balanced and get five unique countries, followed by those five same countries again you get a standard deviation of ~1.4.

I think if the standard deviation code was replaced with an order based on the player who has a country with the lowest weighting it would give better results:
`foreach($chanceGrid as $userID=>$chances)
$chanceGrid[$userID] = ($chances = $this->balanceChances($chances));

$minChance = 1.0;
foreach($chances as $chance) 
    $minChance = min($minChance, $chance);

$selectionOrder[] = $userID; 
$standardDevs[] = 1.0 - $minChance; 

} `
(Of course the comments and name of the $standardDevs array would have to be changed for clarity)


There's another issue with the country selector, which is that it doesn't create entries in the weighting table for new players (so every time a new player starts a game, their country weightings are even). This has been a known issue for a while, affecting all new accounts since around 2013. I haven't gotten around to making an issue for it yet.


@Domphalos Note that this is a common misconception - any given specific sequence of countries is equally unlikely, given a fair dice for country selection.

WebDiplomacy has a bit of code designed to balance out the "fair" dice roll to encourage selection of countries that you haven't had yet, but as mentioned above it needs a bit of massaging.

kestasjk commented Jun 8, 2016

Wow I didn't realize there was a more fundamental problem with it Tim, but what do you mean that it doesn't create entries? I know that for each variant they start off being balanced, but after the first game aren't the first set of country weightings entered into the wD_VariantData table?


No, the update is an update only. There's no insert for new users who don't already have the wD_VariantData entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment