Help with expansion stability

Baldyr

"Hit It"
Joined
Dec 5, 2009
Messages
5,530
Location
Sweden
I'm working on a scenario and trying to make an exception to the 32 tile outside of your core area (or whatever, its on the stability maps anyway) rule. This is done in Stabilty.py and my code looks like this:
Code:
                        iTempExpansionThreshold = iNewBaseStability
                        iNumPlotsAbroad = max(0,self.getOwnedPlotsLastTurn(iPlayer)-32)   
                        [COLOR="Red"]if (not iPlayer == con.iMongolia):[/COLOR]
                                iNewBaseStability -= iNumPlotsAbroad*2/7
                        [COLOR="Red"]else:
                                iNewBaseStability -= iNumPlotsAbroad[/COLOR]
With the limited knowledge of Python I have, I'm trying to get the Mongols to receive a greater penalty than the standard one. If I'm reading the original code correctly, then the value of 32 is subtracted from the number of plots outside of the core area. After this the result is firstly multiplied with 2 and thereafter divided by 7.

So if one has 40 "OwnedPlotsLastTurn" tiles this gives a value of 8 for iNumPlotsAbroad. This is then multiplied by 2 and divided by 7, giving you a NewBaseStability of ~2.28, which is then - if I'm reading the code correctly - rounded down to an even (negative) 2. The base stability penalty for 40 abroad tiles is therefore -2.

As for my own additions to the code, the Mongols would be getting the full iNumPlotsAbroad as their penalty, which amounts to -8. That's would be four times the penalty.

Why aren't I testing it out for myself to see what the results are? Well, I am as a matter of fact. But it will take a considerable time to figure out if it really works as intended, and I still wouldn't know if I have done it right. (I could just be misinterpreting an unforeseen result as something else.) Can anyone conform this?

Also, I'm kinda curios about all these variants of the equal sign used in Python:

=
>=
=<
!=
==
+=
-=

Does anyone have a good link to a source on all these signs? It would help if I knew which one to use... :rolleyes:
 
Why aren't I testing it out for myself to see what the results are? Well, I am as a matter of fact. But it will take a considerable time to figure out if it really works as intended, and I still wouldn't know if I have done it right. (I could just be misinterpreting an unforeseen result as something else.) Can anyone conform this?

The code is fine, you may just find out the Mongols die too easily.

Also, I'm kinda curios about all these variants of the equal sign used in Python:
...
Does anyone have a good link to a source on all these signs? It would help if I knew which one to use... :rolleyes:

In general == != <= >= are relational operators: http://en.wikipedia.org/wiki/Relational_operator
and = += -= are assignment operators: http://en.wikipedia.org/wiki/Assignment_(computer_science)
(Python belongs to the "C-like" group)
All Python operators: http://docs.python.org/library/operator.html

It's explained there, but just to stress it, you use x = 1 to assign a value of 1 to x and x == 1 to check whether x is 1 (in an IF statement etc.)
 
The code is fine, you may just find out the Mongols die too easily.
Thank you for clearing that up! :)

Am I right then I assume that the line "iNewBaseStability -= iNumPlotsAbroad" assigns a negative value? (Didn't find any explanations for "-=" on Wikipedia.)
 
Thank you for clearing that up! :)

Am I right then I assume that the line "iNewBaseStability -= iNumPlotsAbroad" assigns a negative value? (Didn't find any explanations for "-=" on Wikipedia.)

Your usage is correct, though to be precise, it doesn't assign a negative value, it assigns a new value that is the old value reduced by what is on the right... To put it simply "x -= 1" means "substract 1 from x" and is just a shorter way of writing "x = x - 1"
 
Aha, thanks for clearing that up for me! :)

I thought the matter at hand over and am now trying this bit of code for size:
Code:
                        iTempExpansionThreshold = iNewBaseStability
                        iDiscount = 32
                        if (iPlayer == con.iMongolia):
                                iDiscount = 0
                        if (iPlayer == con.iRussia):
                                iDiscount = 50
                        iNumPlotsAbroad = max(0,self.getOwnedPlotsLastTurn(iPlayer) - iDiscount)   
                        iNewBaseStability -= iNumPlotsAbroad*2/7
Simply so that the Mongols have no discount on iNumPlotsAbroad and the Russians have a somewhat larger discount. The code looks alright to you then?

What I'm trying to accomplish here is to make the Mongols collapse sometime after 1300AD by the sheer weight of their empire. The Russians on the other hand start without any Settlers and usually only flips one city. They are on the receiving end of the Mongol spearhead (city flips and unit spawns) and have stability issues from start to boot. So as to make it easier for the Russian player to eventually turn the tide, I thought I'd cut them some slack. (I've never really liked the Russian stability map in the first place, so this should make up for some unstable areas.)

The Mongol collapse happens 9/10 times on the year 1425AD. This would be because the check for collapse is only done every ten turns (I think). So, the other alternatives (as they are collapsing almost from the get go) would be 1350AD or 1475AD. I might also change the remainder/modulo so that it hits on another turn (+/- 10 turns).
 
It looks alright. If you want the mod to be that deterministic you can always add an extra stability hit for Mongols on Russia's spawn (hitNeighboursStability in RiseAndFall.py and lOlderNeighbours in Consts.py)
 
The Mongol collapse happens 9/10 times on the year 1425AD. This would be because the check for collapse is only done every ten turns (I think). So, the other alternatives (as they are collapsing almost from the get go) would be 1350AD or 1475AD. I might also change the remainder/modulo so that it hits on another turn (+/- 10 turns).
Actually, I took another look at Stability.py and there is a "grace period" of 25 turns when a Civ is immune to collapse.:scan:

The Mongols aren't playable and since they get so much for free they really should collapse after 10-20 turns or so. (They only manage one run at Kievan Rus' whatever units they get, anyway.) But, the ideal situation would be if they - sometimes - could hang in there for longer. This would make for a more dynamic scenario, I think. (I've modded Genghis' attitudes also, so he's a real madman to have to deal with. Since I test autoplay Mongols by play testing as Turkey, I get a lot of "interesting" calls from the Big Man.:eek:)

Since I got new tools to tinker with, I better go test.:D
 
Top Bottom