Are you, in fact, a pregnant lady who lives in the apartment next door to Superdeath's parents? - Commodore

Create an account  

 
Curious Civplayer - Mysteries of the DLL

Another question from the community, this time from Cornflakes

Cornflakes Wrote:@Charriu, would you be interested in looking up the actual mechanics of deciding the dice roll for great people? It is a true proportional split between number of points invested in each type, or does some additional weighting get factored in due to the way the code is written (such as with religions favoring earlier founded cities).

So Can you trust the odds for great people creation?

Once again we look into CvCity and here into the method doGreatPeople:


Code:
        int iTotalGreatPeopleUnitProgress = 0;
        for (int iI = 0; iI < GC.getNumUnitInfos(); iI++)
        {
            iTotalGreatPeopleUnitProgress += getGreatPeopleUnitProgress((UnitTypes)iI);
        }

        int iGreatPeopleUnitRand = GC.getGameINLINE().getSorenRandNum(iTotalGreatPeopleUnitProgress, "Great Person");

        UnitTypes eGreatPeopleUnit = NO_UNIT;
        for (int iI = 0; iI < GC.getNumUnitInfos(); iI++)
        {
            if (iGreatPeopleUnitRand < getGreatPeopleUnitProgress((UnitTypes)iI))
            {
                eGreatPeopleUnit = ((UnitTypes)iI);
                break;
            }
            else
            {
                iGreatPeopleUnitRand -= getGreatPeopleUnitProgress((UnitTypes)iI);
            }
        }

This looks more complicated then expected, which is often a sign that something is up. Let's take the example of 15 points into Great Prophet, 35 into Great Artist and 50 into Great Scientist and see what the algorithm does:

  1. First we add up all the individual GreatPerson points in the first for loop. In our example this would be 15+35+50=100. Now the reason why they are doing that is, that if I stand at 99/100 GPP And add 3 more to any single Great Person I and up with 102 points for the creation algorithm and not 100.
  2. We generate a random number between 0 and the totalGreatPeoplePoints we just calculated in 1. In our example let's assume we roll the number 49.
  3. In the next for loop we iterate through all the unit types. This is done because every Great Person is a single unit type. That way we iterate across every single great person type.
  4. In this loop we check if the rolled random number is smaller then the current Great Person points. For this it is important to know in which order the Great Persons are checked and that would be Prophet->Artist->Scientist->Merchant->Engineer. If the number is smaller, then this is the Great Person to be created. If it's not then we subtract the current Great Person points from the randomly generated number and continue with the loop.
Now let's look at our example and how it behaves in the 4th step.

  1. First we check the Great Prophet. We have 15 points into that type, which is smaller then our random number of 49. Therefore we subtract  49-15=34. 34 is our new number to check against.
  2. Next we check against the Great Artist. We have 35 points into that, which is bigger then our random number of 34. Great we create a Great Artist and stop the loop.
  3. Great Scientist points are no longer checked, because we already found our Great Person to be created.
Summary


Looking at this process my first intention was: "Oh the order in which the Great Persons are checked is important and changes the odds". But looking at some examples proved that this is not the case. In fact this time the presented odds are correct and reliable. So you can trust the game with Great Person creation.
Mods: RtR    CtH

Pitboss: PB39, PB40PB52, PB59 Useful Collections: Pickmethods, Mapmaking, Curious Civplayer

Buy me a coffee
Reply



Messages In This Thread
Curious Civplayer - Mysteries of the DLL - by Charriu - April 24th, 2020, 23:20
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 13:38
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 13:53
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 18th, 2020, 08:52
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 11th, 2020, 09:58
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 12th, 2020, 03:50
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 13th, 2020, 14:40
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 14th, 2020, 09:53
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 14th, 2020, 12:51
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 15th, 2020, 13:40
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - November 7th, 2020, 02:34
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 25th, 2020, 16:37
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 27th, 2020, 15:26
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 27th, 2020, 15:53
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 27th, 2020, 17:24
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 27th, 2020, 17:58
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 3rd, 2021, 16:17
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 21st, 2021, 08:27
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 2nd, 2022, 11:53
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - August 29th, 2020, 03:32
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 10:04
RE: Curious Civplayer - Mysteries of the DLL - by superdeath - September 17th, 2020, 10:15
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 8th, 2020, 15:18
RE: Curious Civplayer - Mysteries of the DLL - by Borsche - September 6th, 2020, 22:32
RE: Curious Civplayer - Mysteries of the DLL - by T-hawk - September 6th, 2020, 23:00
RE: Curious Civplayer - Mysteries of the DLL - by Borsche - September 6th, 2020, 23:25
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 8th, 2020, 15:15
RE: Curious Civplayer - Mysteries of the DLL - by T-hawk - September 8th, 2020, 21:01
RE: Curious Civplayer - Mysteries of the DLL - by El Grillo - September 17th, 2020, 10:13
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 13:20
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 14:12
RE: Curious Civplayer - Mysteries of the DLL - by El Grillo - September 17th, 2020, 14:19
RE: Curious Civplayer - Mysteries of the DLL - by T-hawk - September 17th, 2020, 14:58
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 17th, 2020, 15:44
RE: Curious Civplayer - Mysteries of the DLL - by scooter - September 17th, 2020, 15:55
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 18th, 2020, 00:24
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 11th, 2020, 23:13
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - October 13th, 2020, 15:45
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 13th, 2020, 16:20
RE: Curious Civplayer - Mysteries of the DLL - by Bobchillingworth - October 13th, 2020, 22:38
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 13th, 2020, 23:56
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - October 14th, 2020, 09:02
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - November 7th, 2020, 17:43
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 25th, 2020, 17:45
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 25th, 2020, 18:19
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - December 27th, 2020, 18:34
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 27th, 2020, 23:58
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 28th, 2020, 01:35
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 28th, 2020, 08:15
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 3rd, 2021, 23:56
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 4th, 2021, 00:05
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 8th, 2021, 01:35
RE: Curious Civplayer - Mysteries of the DLL - by mackoti - February 8th, 2021, 01:44
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 21st, 2021, 08:11
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 24th, 2021, 04:41
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - November 23rd, 2021, 11:27
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - November 23rd, 2021, 11:29
RE: Curious Civplayer - Mysteries of the DLL - by Krill - December 12th, 2021, 17:11
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - December 12th, 2021, 17:25
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - December 12th, 2021, 18:35
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - September 4th, 2022, 10:46
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - December 2nd, 2022, 12:01
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - September 4th, 2022, 13:32
RE: Curious Civplayer - Mysteries of the DLL - by T-hawk - September 4th, 2022, 19:42
RE: Curious Civplayer - Mysteries of the DLL - by civac2 - February 20th, 2023, 15:30
RE: Curious Civplayer - Mysteries of the DLL - by Charriu - February 20th, 2023, 16:36
RE: Curious Civplayer - Mysteries of the DLL - by T-hawk - February 21st, 2023, 00:53

Forum Jump: