So, I'm trying to simulate history

Vaguely inspired by this thread and some thoughts I had while writing up my Butterfly Effect post.

Ideally I'd like to have a program that runs something vaugely looking like history, but right now I'm just settling for succession in France. My current best run of the program looks something like this:

Year 1605: Louis had a son called Francis
Year 1614: Louis died!
Year 1614: Louis was succeeded by Francis.
Year 1618: Francis died!
Year 1618: Succession crisis!

Which looks decent enough but most of the other runs are embarrassing - King Louis has some random number of sons, all called Francis (don't ask) and there can only be one succession event before the program thinks it's run out of heirs.

Year 1620: Louis had a son called Francis
Year 1633: Louis had a son called Francis
Year 1659: Francis died!
Year 1659: Louis had a son called Francis
Year 1666: Louis had a son called Francis
Year 1669: Francis died!
Year 1674: Louis died!
Year 1674: Louis was succeeded by Francis.
Year 1717: Francis died!
Year 1717: Succession crisis!
Year 1750: Francis died!

(As you can see, there's a succession crisis despite a younger brother being alive for another 33 years.)

So it's going pretty well, all told - I only started yesterday. But if anyone has suggestions on how to properly implement primogenature in Objective C, I'd be glad to hear it.

EDIT: while waiting for the serverload to clear up, I fiddled around some more and now there's a giant recursive swarm of spawn, all called Francis (I've started tagging them with DOB). Still no progress on a reasonable primogenature system, though.

Year 1603: Louis had a son called Francis 1603
Year 1651: Louis had a son called Francis 1651
Year 1651: Francis 1603 died!
Year 1692: Louis died!
Year 1692: Succession crisis!
Year 1713: Francis 1651 had a son called Francis 1713
Year 1716: Francis 1651 died!
Year 1736: Francis 1713 had a son called Francis 1736
Year 1739: Francis 1713 had a son called Francis 1739
Year 1748: Francis 1736 died!
Year 1775: Francis 1713 died!
Year 1778: Francis 1739 died!

(This was actually a smaller run; normally they outbreed the death rate and make it all the way to the end-of-sim in 1800. The fact that you occasionally get creepy stuff like

Year 1738: Francis 1719 had a son called Francis 1738
Year 1738: Francis 1738 had a son called Francis 1738
Year 1738: Francis 1738 had a son called Francis 1738

doesn't hurt either. :eek:)
 
Last edited:
You know, if all the sons were called Louis instead of Francis, that would be quite close to OTL :p

Quiet you. :p (Ideally I want a list of names drawn from at random, but currently they're just hard-coded in, hence one Louis and all the Francises. You're right in that I probably should have done it the other way around.)

...And I think I've solved primogenature via lots and lots of pointers:

Year 1624: Louis had a son called Francis 1624
Year 1644: Louis had a son called Francis 1644
Year 1652: Francis 1644 had a son called Francis 1652
Year 1663: Francis 1624 had a son called Francis 1663
Year 1668: Francis 1624 died!
Year 1689: Louis died!
Year 1689: Louis was succeeded by Francis 1663.
Year 1698: Francis 1644 died!
Year 1703: Francis 1652 had a son called Francis 1703
Year 1717: Francis 1703 had a son called Francis 1717
Year 1724: Francis 1663 died!
Year 1724: Francis 1663 was succeeded by Francis 1652.
Year 1726: Francis 1652 had a son called Francis 1726
Year 1736: Francis 1652 died!
Year 1736: Francis 1652 was succeeded by Francis 1703.
Year 1797: Francis 1703 died!
Year 1797: Francis 1703 was succeeded by Francis 1726.

It's heavily edited for size (there're about three different cadet lines that never come into the succession) but you can see how the succession works now: Louis is succeeded, not by his still-living second son Francis 1644, but by his dead first son's son, Francis 1663. When Francis 1663 dies without issue, the throne is passed on to the line of the second son of Louis, Francis 1644; 1644 himself has died in the interim as well, but 1663's cousin 1652 is alive, and inherits. 1652's sons then inherit, first 1703 and then (when 1703 dies without issue) 1703's younger brother 1726.

Louis
---|-------|
1624 --- 1644
---|-------|
1663 --- 1652
-----------|--------|
---------1703 --- 1726

(I really need to get that naming system up and running. :eek: But you get the point; I think that's the accurate implementation of Salic Primogenature, right?)
 
Last edited:
What program are you writing this in?, I think i might give this a go

Objective-C in the Mac Xcode dev environment. I'm actually just dumping the info to console right now, so a typical line really looks more like

2010-01-17 15:16:22.157 History[13133:10b] Year 1641: Francis 1641 had a son called Francis 1641
 
Grrr... having trouble calibrating the birthrates. The big issue is that it's hard to make it so that Louis has a reasonable number of living descendants a century later, whereas as it stands it's a crapshoot between having 0 and having 147.
 

Susano

Banned
Simulating "history", eh? So you define history as dynastics, successions and succession crisises?

...as member of this forums Early Modern Cabal and general HRE fanboy, I thoroughly approve! :D
 
Simulating "history", eh? So you define history as dynastics, successions and succession crisises?

...as member of this forums Early Modern Cabal and general HRE fanboy, I thoroughly approve! :D

Well, not really - this is just stage one. I'm having enough trouble just keeping the Bourbons from outbreeding China as it is.
 

Susano

Banned
Well, not really - this is just stage one. I'm having enough trouble just keeping the Bourbons from outbreeding China as it is.

...Thats a truely frightening concept indeed!
In that case, you shouldve chosen Habsburg as example dynasty :p
 
...Thats a truely frightening concept indeed!
In that case, you shouldve chosen Habsburg as example dynasty :p

Yeah, well, I think I've gotten it mostly balanced now*. Next step, I need to give them actual names.

*About 40% of the time, the male line is gone in 200 years; most of the rest of the time it has 10 - 40 living descendants. That seem about right?
 
Grrr... having trouble calibrating the birthrates. The big issue is that it's hard to make it so that Louis has a reasonable number of living descendants a century later, whereas as it stands it's a crapshoot between having 0 and having 147.

Would it help if the likely hood of having a child would be proportional to his age. I.e. he's most likely to have a child say 20-30, and less likely as he gets older, might help...

E.g. (written in javaesqe)

public boolean canHaveChild
{
if (randomNumber(100) < 100 - ((age - 20)^2) && (age > 16))
{
return true;
}
else
{
return false;
}
}
 
Would it help if the likely hood of having a child would be proportional to his age. I.e. he's most likely to have a child say 20-30, and less likely as he gets older, might help...

E.g. (written in javaesqe)

public boolean canHaveChild
{
if (randomNumber(100) < 100 - ((age - 20)^2) && (age > 16))
{
return true;
}
else
{
return false;
}
}

Hmmm... that's a clever way of doing it. Mine just looks like:

if ((age > 20) && !(random() % 5) && (age < 40))
{
havekids()
}

So each person has a one-in-5 chance of having a kid every year between the age of 20 and 40, but having a quadratic drop-off is a good idea.
 
Looks very intriguing Zyzzyva. I've thought of making a program to simulate history as well, but never got around to start with any actual programming. Can't wait to see more.

And now you know why Crusader Kings file sizes grow exponentially. :p
 
Goddamnit primogenature, why are you so hard to implement? Why? :mad::(

EDIT: Which is of course my cue to get it fixed. :rolleyes::eek:

1605: King Louis had a son called Robert 1605
1607: Robert 1605 died!
1617: King Louis had a son called Francis 1617
1619: King Louis had a son called Philippe 1619
1620: King Louis had a son called Jean 1620
1641: Philippe 1619 had a son called Jean 1641
1642: Philippe 1619 had a son called Jean 1642
1642: Jean 1620 had a son called Jean 1642
1643: Philippe 1619 had a son called Philippe 1643
1643: Jean 1642 died!
1644: Jean 1620 died!
1645: Philippe 1619 died!
1647: Philippe 1643 died!
1651: King Louis died!
1651: Francis 1617 had a son called Philippe 1651
1651: King Louis was succeeded by Francis 1617.
1653: Philippe 1651 died!
1664: Jean 1642 had a son called Philippe 1664
1666: Philippe 1664 died!
1668: Jean 1641 had a son called Robert 1668
1670: Robert 1668 died!
1671: Jean 1641 had a son called Louis 1671
1674: King Francis 1617 died!
1674: King Francis 1617 was succeeded by Jean 1641.
1676: King Jean 1641 had a son called Louis 1676
1678: Louis 1676 died!
1691: Louis 1671 died!
1697: Jean 1642 died!
1717: King Jean 1641 died!
1717: Succession crisis!
 
Last edited:
Goddamnit primogenature, why are you so hard to implement? Why? :mad::(
Computers are the very vanguard of revolution, being oppresses by us, their human users. It is only natural that they should bring out their anti-monarchical sentiments in whatever small spiteful ways they can.
 
Not sure how you're doing it right now. "A lot of pointers" are going to be necessary for this sort of thing. For any sort of family tree, implement it as a tree data structure. I assume you're writing some sort of person class. I don't know Objective C, but if there's not a tree class included, you can probably either find one pretty easily or write one yourself; it's pretty simple. You'll pretty much just need to make a treeNode that binds together one current node, two pointers to parent nodes, and an array of pointers. The current node represents a person, the array of pointers represents that person's children, the parent nodes represent, of course, the father and mother. Possibly bind in a husband/wife node, as well.

That way, you just need to do a simple depth first search to find an heir. Look at the eldest son, and if he's alive, then he's the heir. If he's not alive, find his heir (recursively). If that search returns false, look at the next eldest son, and so forth. If there are no heirs, then return false.

Yeah, well, I think I've gotten it mostly balanced now*. Next step, I need to give them actual names.

*About 40% of the time, the male line is gone in 200 years; most of the rest of the time it has 10 - 40 living descendants. That seem about right?

For names, the easiest way would be to do it as an array (or vector or whatever). Just say something along the lines of:

nameVector = { "Henri";
"Francois";
"Louis";
}

and then you can write a function like

string getName(array nameVector) {
number = getRandom(0,sizeof(nameVector) - 1)
return nameVector[number]
}

You could even do something like having different cultures once you have more than one dynasty going. Have an array for frenchNames and germanNames and englishNames, so you don't have King James of France and King Louis of England.
 
Not sure how you're doing it right now. "A lot of pointers" are going to be necessary for this sort of thing. For any sort of family tree, implement it as a tree data structure. I assume you're writing some sort of person class. I don't know Objective C, but if there's not a tree class included, you can probably either find one pretty easily or write one yourself; it's pretty simple. You'll pretty much just need to make a treeNode that binds together one current node, two pointers to parent nodes, and an array of pointers. The current node represents a person, the array of pointers represents that person's children, the parent nodes represent, of course, the father and mother. Possibly bind in a husband/wife node, as well.

That way, you just need to do a simple depth first search to find an heir. Look at the eldest son, and if he's alive, then he's the heir. If he's not alive, find his heir (recursively). If that search returns false, look at the next eldest son, and so forth. If there are no heirs, then return false.

Although if you think about it that doesn't quite work - you need to be able to run even further up the tree than your start point to pass the throne on to the king's brother or uncle or cousin or whatever.

My implementation is everybody has a pointer to their father and a pointer to their youngest living son. At the same time they're part of a doubly-linked list of everybody in succession order. When someone dies, they're snipped out of the succession list (and if necessary their father's youngest-son pointer is moved back up the list of succession until it hits the next living person to share that father). When someone is born, they're stitched into the succession list in between the last person you reach by taking the father's previous youngest son's youngest son's youngest... and that person's successor, and then moving the father's youngest son pointer to the new guy. The succession list makes succeeding people easy; the last-child pointer lets you keep track of where any given person's newest child goes (eg, between the last descendant of any of his older brothers, and the first person descended from someone later on the list than dad). It's not a pretty kludge, but AFAICT it implements primogeniture perfectly. :eek:

For names, the easiest way would be to do it as an array (or vector or whatever). Just say something along the lines of:

nameVector = { "Henri";
"Francois";
"Louis";
}

and then you can write a function like

string getName(array nameVector) {
number = getRandom(0,sizeof(nameVector) - 1)
return nameVector[number]
}

You could even do something like having different cultures once you have more than one dynasty going. Have an array for frenchNames and germanNames and englishNames, so you don't have King James of France and King Louis of England.

That's how my latest version (with Louis, Robert, Philippe, Francis, and Jean) works, actually pretty much verbatim, albeit with only the one array for French people only.

I'll probably post the source at some point.
 
Last edited:
Top