New Improvement Tags: <FeatureChange> & <BonusChange>

Thunderbrd

C2C War Dog
Joined
Jan 2, 2010
Messages
29,813
Location
Las Vegas
Opening up a new thread here to open discussion on this topic. There's probably numerous new things we could do and a number of things we were trying to do via python or by proxy that these new tags open up the ability to make much easier.

So to back up and explain, I've implemented two new tags for improvements, FeatureChange and BonusChange. To use, simply specify the feature or bonus:
<FeatureChange>FEATURE_FOREST</FeatureChange>
<BonusChange>BONUS_SALT</BonusChange>

When this is set on an improvement, what will happen is when the improvement is placed on the plot, be it from a build or an upgrade or ANY other event that places an improvement, in the process of that placement, the plot will be checked to see if the feature or bonus can be placed there and if it can, it will.

Very simple. Lots of potential. Any questions? I've provided examples of its use on the Tree Nursery and Salt Quarry improvements (which was the whole reason I did this in the first place was to fix the process on these) if you'd like to take a look in code.

So I was wondering how YOU would like to further utilize the new functionality here? I was also wondering how well the current terraforming improvements work and if they should ALL be updated to utilize this feature? This will certainly make the eventual multi-map terraforming much easier to implement.


Oh... sidenote: To get an improvement to be able to upgrade, even if an upgrade is setup properly, it MUST have a defined build, even if that build will never be given to a worker to utilize... this is just a prerequisite of the recent upgrade process modifications.
 
Not sure I see how this could apply to global warming effects really.

But it might be interesting to start a deeper discussion on processes for earth changes...

EDIT: Is it not possible for improvements to be auto-added or removed based on pollution property? If so, perhaps this could be used for something along these lines.
 
1) The terriform and tree planting can certainly use it and we can possibly use it for burnt forests.

Does it place the improvement as well as the bonus/feature? Can the be a boolean to stop it placing the improvement?

The terriform planting of forest, jungle and bamboo place an improvement of that name. The python removes the improvement and places the feature of that name so that the workers will improve the feature after it is planted.

Does it place the correct version of the feature? eg forest has three different types based on latitude.

2) Salt Quarry is this a new improvement? Or have you changed the old? Thinking on it I can see no need for this improvement at all unless we want to use hrochland art instead of the normal art.

The Salt Gatherer upgrades to a Quarry if Salt or Natron is discovered on the plot after the improvement is added. Natron is a very very rare map resource, finding it in a Salt Gatherer is supposed to be more likely.

The Salt Gatherer allows a building that provides Salt. We have far to many of these as it is. It has almost reached the stage where we should remove salt from the game and all places it is required since it is every where.
 
Let us work through some examples which should work with this.

1. Beacons and Lighthouses"

Coral Reefs and Reefs slow and damage ships that travel through the plot they are on. The beacon and lighthouse improvements currently only provide a yield change but were intended to reduce the slowing and damage effects of them.

Beacon upgrades to Lighthouse.

Since improvements can't change sped and damage I made four new features "Coral Reef with Beacon", "Coral Reef with Lighthouse", "Reef with Beacon" and "Reef with Lighthouse".

My questions are:-

Can change the Beacon improvement to replace "Coral Reef" with "Coral Reef with Beacon" with the Beacon improvement on the plot also?

If the Beacon is pillaged will the feature also revert?

Similarly if the lighthouse is pillaged will the feature go from "Coral Reef with Lighthouse" back to "Coral Reef with Beacon"?

2. Terriform terrain

The terriform functions as we inherited placed an improvement with the same name as the feature being terriformed to but that improvement could not be further improved like the feature could. Python was added to remove the improvement "Forest" and replace it with the latitude correct version of the feature "Forest"

The improvement is not needed after completion here as it will stop workers improving the plot if the "Workers leave old improvements" option is selected.

3. Great Farmer and Animals placing herds

We can't quite replace the Great Farmer etc. python with this because of the restriction that says there must be no resources even revealed ones on the plot first.
 
1) The terriform and tree planting can certainly use it and we can possibly use it for burnt forests.

Does it place the improvement as well as the bonus/feature? Can the be a boolean to stop it placing the improvement?
It does place the improvement as well. I can put a boolean in to stop the placement of the improvement (and not stop the removal of one that may be upgrading.) I can see how that would be helpful.

The terriform planting of forest, jungle and bamboo place an improvement of that name. The python removes the improvement and places the feature of that name so that the workers will improve the feature after it is planted.
Ok, so the bool would help there.

Does it place the correct version of the feature? eg forest has three different types based on latitude.
I noticed a latitude check to validate and included that but this being the reason for it indicates I should probably change the feature tag to a multi-tag so we can indicate multiple types and whichever one is valid will be placed. Sorry for that oversight but it can be easily corrected.

2) Salt Quarry is this a new improvement? Or have you changed the old? Thinking on it I can see no need for this improvement at all unless we want to use hrochland art instead of the normal art.
Based on what we were reading, my wife and I's understanding of this may have been flawed - it appeared it was supposed to give the plot a salt resource once it upgraded and it wasn't doing as advertised.

So what I did here was have the Salt Gatherer upgrade to a (new) Salt Quarry, which also adds the salt resource if it can on that plot.

The Salt Gatherer upgrades to a Quarry if Salt or Natron is discovered on the plot after the improvement is added. Natron is a very very rare map resource, finding it in a Salt Gatherer is supposed to be more likely.
So yeah I may have messed up the intention here - sorry. It was to provide an example of the process more than anything. If you want it to stay this way then it can be easily reverted.

The Salt Gatherer allows a building that provides Salt. We have far to many of these as it is. It has almost reached the stage where we should remove salt from the game and all places it is required since it is every where.
I don't mind it being common - it still benefits other buildings like the tannery so is important to try to reach out to get which does take some player focus so there really is still a point to salt. I know in some eras for some cultures salt was valuable but it really is terribly common on Earth. We might still be able to improve that model. This particular improvement line is only available on salt flats which isn't all that common in the game really.

Let us work through some examples which should work with this.

1. Beacons and Lighthouses"

Coral Reefs and Reefs slow and damage ships that travel through the plot they are on. The beacon and lighthouse improvements currently only provide a yield change but were intended to reduce the slowing and damage effects of them.

Beacon upgrades to Lighthouse.

Since improvements can't change sped and damage I made four new features "Coral Reef with Beacon", "Coral Reef with Lighthouse", "Reef with Beacon" and "Reef with Lighthouse".

My questions are:-

Can change the Beacon improvement to replace "Coral Reef" with "Coral Reef with Beacon" with the Beacon improvement on the plot also?​

We can have the Beacon improvement replace the coral reef feature with the Coral Reef with Beacon feature. This is valid under the current structure of the programming - just put the coral reef with beacon feature in the <FeatureChange> tag on the Beacon improvement.

If the Beacon is pillaged will the feature also revert?
No - that would be the only problem. Easily solved though... I can add another tag <FeaturePillage> to designate what the feature becomes if the improvement is removed.

Similarly if the lighthouse is pillaged will the feature go from "Coral Reef with Lighthouse" back to "Coral Reef with Beacon"?
Actually yes. If the Coral Reef with Beacon feature is established as the FeatureChange on the Beacon improvement then when the Lighthouse is pillaged and it becomes a beacon it's another re-establishment of the beacon so it would replace the feature to become a Coral Reef with Beacon again too.

2. Terriform terrain

The terriform functions as we inherited placed an improvement with the same name as the feature being terriformed to but that improvement could not be further improved like the feature could. Python was added to remove the improvement "Forest" and replace it with the latitude correct version of the feature "Forest"

The improvement is not needed after completion here as it will stop workers improving the plot if the "Workers leave old improvements" option is selected.
So with the boolean to remove the feature this would make a perfect way to handle this. Easily done.

3. Great Farmer and Animals placing herds

We can't quite replace the Great Farmer etc. python with this because of the restriction that says there must be no resources even revealed ones on the plot first.
We haven't added that restriction capability to any improvements yet BUT the improvement won't place the bonus with the <BonusChange> tag if any bonuses already exist since that would make it invalid.

In this way the farmer may be made to be less revealing - he'd have to make the improvement, the improvement would reveal if it works or not once placed.​
 
Based on what we were reading, my wife and I's understanding of this may have been flawed - it appeared it was supposed to give the plot a salt resource once it upgraded and it wasn't doing as advertised.

So what I did here was have the Salt Gatherer upgrade to a (new) Salt Quarry, which also adds the salt resource if it can on that plot.


So yeah I may have messed up the intention here - sorry. It was to provide an example of the process more than anything. If you want it to stay this way then it can be easily reverted.

It needs to be, but I think I had the gatherer wrong anyway. The Salt Gatherer allows a building that provides salt. Every coast sea or fresh water also allows you to build a building that provides salt.

The Salt Gatherer improvement has a small chance of finding (quality) salt or natron on a Salt Flat like mines do for other bonuses. The Salt Gatherer can then upgrade to a Quarry otherwise it does not upgrade and this is intended.


We haven't added that restriction capability to any improvements yet BUT the improvement won't place the bonus with the <BonusChange> tag if any bonuses already exist since that would make it invalid

Restrictions can be on the build rather than the improvement or both. There is just not a restriction called "can't place on any plot that already has a resource on it even if we can't see it:.:lol:

In this way the farmer may be made to be less revealing - he'd have to make the improvement, the improvement would reveal if it works or not once placed.

If you can wait the 50 turns necessary and it consumes the unit as well. Sounds bad:mwaha:
 
Every coast sea or fresh water also allows you to build a building that provides salt.

IMO a fresh water tile should not allow you to build a building that provides salt. Because if it did it would not be fresh water. :mischief:
 
IMO a fresh water tile should not allow you to build a building that provides salt. Because if it did it would not be fresh water. :mischief:

However there is no way to tell the difference at the moment. Both are "coast" which you can check for. I know I tried all sorts of stuff to make it work properly to no avail.
 
It needs to be, but I think I had the gatherer wrong anyway. The Salt Gatherer allows a building that provides salt. Every coast sea or fresh water also allows you to build a building that provides salt.

The Salt Gatherer improvement has a small chance of finding (quality) salt or natron on a Salt Flat like mines do for other bonuses. The Salt Gatherer can then upgrade to a Quarry otherwise it does not upgrade and this is intended.
As I'm reverting this a few things stand out:
1)The tech prereq on the build and the improvement differ - they really should be the same.

2)If you want there to be a chance of finding salt or natron then the improvement should really have <iDiscoverRand>0</iDiscoverRand> on those to be set as much higher than 0 (no chance to discover!)



Restrictions can be on the build rather than the improvement or both. There is just not a restriction called "can't place on any plot that already has a resource on it even if we can't see it:.:lol:
A bNotOnAnyBonus tag would be easy enough added so it can be placed on an improvement and I THINK a build makes sure the improvement that comes from the build will be valid on that plot so it would by default inherit that property into the canBuild function. Whether the bonus exists on the plot or not does not depend on whether the player can see it or not so the coding would be exceedingly easy.



If you can wait the 50 turns necessary and it consumes the unit as well. Sounds bad:mwaha:
Yeah I suppose but it sure is a giveaway! lol



I've updated the system a bit here and am working on a fix to your crash before committing it along with a fix to the Healer AI.

BTW, I noticed that there's only one Forest Feature (aside from New, Burnt and Old.) I'm not sure how the graphics go outside of that but there's only one Forest.

But I've changed FeatureChange to FeatureChangeTypes and I've added bChangeRemove which indicates that as soon as the improvement is added it removes itself (it actually shortcuts a lot in doing this so that it processes much faster but it adds the Feature and/or Bonus before it vanishes.)

So the syntax will be like:
Code:
			<FeatureChangeTypes>
				<FeatureType>FEATURE_FOREST</FeatureType>
			</FeatureChangeTypes>
			<bChangeRemove>1</bChangeRemove>
When there is more than one FeatureType defined it will use the first valid one. I can see this being very useful in the coastal stuff.

And along the lines of the coastal matters we were discussing, if you simply add a 'dummy' improvement that adds a normal Reef and set it as the <ImprovementPillage> and give it <bChangeRemove> then destroying the Reef with Beacon improvement will simply return the normal reef. :)


I'll try to squeeze the bNotOnAnyBonus tag before commit here. Should be able to get that in quickly.

My wife is also explaining there seems to be a bug with some improvement upgrades not taking place when they should so I'll be looking into that very soon too.
 
As I'm reverting this a few things stand out:
1)The tech prereq on the build and the improvement differ - they really should be the same.

Not necessarily. There should be a build that matches but there can also be ones that don't. eg ones which are the "same" for the gatherer and worker will have different techs possibly.

2)If you want there to be a chance of finding salt or natron then the improvement should really have <iDiscoverRand>0</iDiscoverRand> on those to be set as much higher than 0 (no chance to discover!)

I did have that in my modmod but I think I forgot to transfer it when I merged it in.
Spoiler :
Speaking of modmods, if I get my act together and build some test cases I have almost got three ready.

- Population Limits as in Civ III but based on the Civ IV Total War mod in which you need certain buildings before your cities can grow past a certain size.

- Movement Limits but as JosephII says if you are playing with the escort subdued animals option on this is probably not necessary.

- not just a mod but a fix Units every so often with city exp

My wife is also explaining there seems to be a bug with some improvement upgrades not taking place when they should so I'll be looking into that very soon too.

I thought I had seen this happen too. However I just assumed I had pressed enter at the wrong time.
 
Not necessarily. There should be a build that matches but there can also be ones that don't. eg ones which are the "same" for the gatherer and worker will have different techs possibly.
Fair 'nuff. Just seems it may warrant a look into on that one.



I did have that in my modmod but I think I forgot to transfer it when I merged it in.
Ack! That was part of the reason the whole thing confused me.

- Population Limits as in Civ III but based on the Civ IV Total War mod in which you need certain buildings before your cities can grow past a certain size.
Interesting but probably not my cuppa.

- Movement Limits but as JosephII says if you are playing with the escort subdued animals option on this is probably not necessary.
Again... not something I'd be looking forward to but I know a lot have clammored for it. The 'limits' I intend will be something more similar to the reason those playing with escort subdued off would not need hard limitations.

- not just a mod but a fix Units every so often with city exp
What's this all about? Is this what we were talking about the other day about delaying xp given to the unit? The more I think of the harm this would cause the AI the more I shudder.

I thought I had seen this happen too. However I just assumed I had pressed enter at the wrong time.
It's not just the normal freezing - apparently there's something more 'odd' amiss there. She was saying that only some of her stone tools gatherers were upgrading to mountain mines once mountain mines were enabled, and this was after she would clear the freeze on the upgrade by unworking and reworking the tile. I'm needing a test game that shows the problem if anyone knows they have it.
 
What's this all about? Is this what we were talking about the other day about delaying xp given to the unit? The more I think of the harm this would cause the AI the more I shudder.

No, wrong discussion. Its the one where Crusader units were not getting the city exp. I said I wanted to make a more generic solution. So far I have only gone half way and reduced the code to about a fifth of what it was.

edit I tend to make a prototype mod to see if the mod idea is useful before going into a full development.
 
No wrong discussion. Its the one where Crusader units were not getting the city exp. I said I wanted to make a more generic solution. So far I have only gone half way and reduced the code to about a fifth of what it was.

Ah... now that is something we do need for sure imo ;) Thanks!
 
Again... not something I'd be looking forward to but I know a lot have clammored for it. The 'limits' I intend will be something more similar to the reason those playing with escort subdued off would not need hard limitations.

I assume you mean the limits people have if they play with escort subdued on. Having it on means you collect the animals with your exploring units and need to take them back to your nation fast as they cost a lot in upkeep outside your borders.

With it off there is no limit to exploration as your explorers have no reason to return and can just keep going further.

The limits in the Movement Limits mod are purely based on a very crude supply mechanism so are natural in that regard.
 
ABSTRACT: I did some statistical analysis to address the issue of the information a player gains by building an improvement with the described scheme, which subsequently fails to do anything because of an underlying unseen resource or bonus, giving the player unintended inferential power. I propose using the "randomly discover [bonus]" behaviour in the base game in order to baffle a player's exploitive attempts, and provide hard bounds on his certainty about information that is designed to be hidden.

I've made some assumptions about the mechanisms you're talking about, since I'm not entirely sure what they are and cannot possibly be sure without doing the modding you've been doing. I understand you're describing builds which supposedly plant improvements, but with an actual effect of <doing something> and, in some cases, immediately removing the improvement. This is powerful sugar that lets workers modify terrain, however, there is an issue with tile bonuses not compatible with these actions, if those bonuses are hidden to your current tech level. A simple implementation allows a player to learn hidden information by using these terramorphous builds and seeing them fail or do other than standard. What I've proposed is a means to introduce doubt into the system, so that the exploit is minimized - which I've called 'baffling the exploitive player'.
By creating a random chance of failure independent of the likelihood of the incompatible tile, the certainty that the incompatible tile is present given the build behaved oddly can be bounded from above. (The likelihood of the incompatible tile is some prespecified proportion, p, where p*N = number of tiles of that type, N being the number of tiles on the map. I assume p is a constant for any given map seed, but it at least is a constant for any given map simply.)

Spoiler other subject :
1) The terriform and tree planting can certainly use it and we can possibly use it for burnt forests.

Does it place the improvement as well as the bonus/feature? Can the be a boolean to stop it placing the improvement?

The terriform planting of forest, jungle and bamboo place an improvement of that name. The python removes the improvement and places the feature of that name so that the workers will improve the feature after it is planted.

Does it place the correct version of the feature? eg forest has three different types based on latitude.

Looking at it in terms of data-driven architecture, the fact that the game enforces the rule: { 'Forest' has three variations with nonidentical latitude ranges where each is legal } is a proper possession of the game and not the data of this terraforming improvement tech. So the data should not contain any element of this fact, but the game should drive forest-correction.


(Also, just for ease of reference, in the rest of this post I refer to improvements which have nonempty tags of <FeatureChange> or <BonusChange> as Terramorphous Improvements, Terramorphs, or TMIs)

Also, about Terramorphs placed on tiles with hidden bonus resources: We have the technology to do the following. Make the TMI have a "random chance" to discover the bonus it is actually intended to reveal, which is nearly equal to 1. But then also script it not to work when there is a "real" bonus under there.
If the chance that the TMI doesn't fail randomly is x, the event of which is independent of bonuses under the tile, then the probability that the TMI will fail (event 'F') is given by

Code:
P(F) = (1-x)(y) + (x)(1-y) + (1-x)(1-y) = y - xy + x - xy + 1 - x - y + xy
 = 1 - xy = complement(xy)

where y is the complement of the prevalence of the incompatible bonus (i.e. the chance that a tile doesn't have the bonus). This is the complement of the chance that neither reason for failure comes to pass, which is as well should be.

Now suppose the terramorph fails and we wonder if we now have conditional knowledge about the probability of a certain bonus being under it in truth. We want to know if P(-Y|F) = P(-Y), Y is the event "the other bonus is not present" (and F is "The improvement failed to produce a bonus").

Code:
P(-Y & F)/P(F) = P(-Y)/P(F)  [I](since -Y --> F)[/I]

which clearly gives conditional knowledge if failure is not 1. However, let's now consider a player who is eager to assume a certain bonus resource is present. We want him to be wrong enough of the time that the scripting described is not a reliable visor into hidden information. Consider the chances of both type I error and type II error. What we can control is the fact the player only gets one sample of the tile. We're already talking about a player who gets nothing and is suspicious of a hidden resource, so obviously type II error we don't care about (the player is rejecting the null hypothesis). We want to magnify type I error. However, we also want the effect of random failure to be minimized.

We can't really control the player's hypothesis, and we already proved they are going to be a little bit right, so let's look at possible ways to introduce doubt.

y is a constant, and x is something the player will know too. So the chances P(-Y|F) and P(Y|F) are both known to him. Y^F = Y^-X, so P(Y|F) = P(-X&Y|F) .
These are complements, so P(-X&Y|F) = 1 - P(-Y|F) . Suppose what we really want is for the hypothesis that the failure is the result of random chance to be as good as the hypothesis that it was because of a hidden resource. (This is still a lot of knowledge about the tile - 50% right is better than (1-y) probability right.) This is when P(-X&Y|F) = P(-Y|F). Since they are complements, it is when they are 0.5.
Thus, solve the equation:

Code:
0.5 = P(-X&Y|F) = P(-X&Y&F)/P(F) = P(-X&Y)/P(F)
= P(-X)P(Y)/P(F) = (1-x)y/(1-xy) = (y - xy)/(1-xy)

The delightful app at Mathway.com solves this reciprocal equation because I can't work fractions (or radicals) a damn, and x = 2 - 1/y
Notice that to bound x in [0,1], 1/y must be in [1,2] or equivalently, y is in [0.5,1]. So the incidence of incompatible resources must be no greater than a half, which is certainly doable. Recall x,y were the probabilities of non-failure, so y is the complement of the incidence of the incompatible resource. Also, xy =/ 0, xy =/ 1, and y is certainly in (0,1), so the real bounds are x in (0,1) and y in (0.5, 1) .

So, if, say, the resource occurs on 15% of tiles, y = 0.85, and x =~ 0.82 . So the terramorphous improvement should be configured to "randomly" reveal its intended bonus 82.35% of the time.
Actually, this is a maximum bound on x, since we don't care if the hidden resource turns out not to be there even more than half the time. We wanted to keep x as large as possible though, as it just interferes with gameplay.

Suppose instead we want the chance of a guess of a resource to be minimally more accurate than without the sample of the TMI. That is, we want a type I error as close as possible to the naked chance (y) of there being nothing there. So we want the chance of observing F and asserting --X to be wrong as much as possible.
H0 is the hypothesis the TMI randomly failed, which has probability P(-X|F) (as an explanation of event F which is already known). How can we vary this in relation to P(Y)?

Our eager Civizen is rejecting H0, so he is wrong with probability P(-X|F) = (1-x) /(1-xy) . I just studied a function like this a week ago: u/(1 - y + uy) . (u=1-x) . Here is a link to a Mathway that graphs this function for y of 0.9, 0.85, and 0.51 (recall y is bounded by 0.5)
http://www.mathway.com/graph/NDI5MjM {after loading, click a colored square next to an equation and set the color to make the app draw the graphs}

Focusing on the region (0,1), it's clear this function is bounded below by f(u)=u, and is strictly increasing in y. We want to minimize u to impact gameplay the least, but still have a large error chance. Let's have a "good enough" condition on the error chance and minimize u. Either we're comparing to the chance of guessing the hidden bonus is present and we're wrong, or the chance of guessing that and we're right : Y and -Y , respectively. To relate to values for u, find the intersection with the constant function f(u) = y
Again, solving an equation gives u = y/(y+1) . With y in (0.5,1), u is somewhere between 1/3 and 1/2 . So the more prevalent the resource is, the easier this masking task is (unintuitive).

Combining the two results, we want u > y/y+1, which is to say x < 1/(y+1) , and also we want x < 2 - 1/y (not strict inequalities). The largest x satisfying both , rounded to fit a computer simulation, is thus

round[down]( min{1/(y+1), 2 - 1/y} )

x is the probability of the improvement "randomly" revealing what it is supposed to add. y is the complement of the prevalence of incompatible resources (that will interdict the improvement's scripted effect). If the incompatible resource(s) occur on half the tiles or more, this technology does not work.
 
I assume you mean the limits people have if they play with escort subdued on. Having it on means you collect the animals with your exploring units and need to take them back to your nation fast as they cost a lot in upkeep outside your borders.

With it off there is no limit to exploration as your explorers have no reason to return and can just keep going further.

The limits in the Movement Limits mod are purely based on a very crude supply mechanism so are natural in that regard.
Yes that's what I meant. You may have an approach similar to what I had in mind... very interesting.
I did some statistical analysis to address the issue of the information a player gains by building an improvement with the described scheme, which subsequently fails to do anything because of an underlying unseen resource or bonus, giving the player unintended inferential power. I propose using the "randomly discover [bonus]" behaviour in the base game in order to baffle a player's exploitive attempts, and provide hard bounds on his certainty about information that is designed to be hidden.



Looking at it in terms of data-driven architecture, the fact that the game enforces the rule: { 'Forest' has three variations with nonidentical latitude ranges where each is legal } is a proper possession of the game and not the data of this terraforming improvement tech. So the data should not contain any element of this fact, but the game should drive forest-correction.

(Also, just for ease of reference, in the rest of this post I refer to improvements which have nonempty tags of <FeatureChange> or <BonusChange> as Terramorphous Improvements, Terramorphs, or TMIs)

Also, about Terramorphs placed on tiles with hidden bonus resources: We have the technology to do the following. Make the TMI have a "random chance" to discover the bonus it is actually intended to reveal, which is nearly equal to 1. But then also script it not to work when there is a "real" bonus under there.
If the chance that the TMI doesn't fail randomly is x, the event of which is independent of bonuses under the tile, then the probability that the TMI will fail (event 'F') is given by

Code:
P(F) = (1-x)(y) + (x)(1-y) + (1-x)(1-y) = y - xy + x - xy + 1 - x - y + xy
 = 1 - xy = complement(xy)

where y is the complement of the prevalence of the incompatible bonus (i.e. the chance that a tile doesn't have the bonus). This is the complement of the chance that neither reason for failure comes to pass, which is as well should be.

Now suppose the terramorph fails and we wonder if we now have conditional knowledge about the probability of a certain bonus being under it in truth. We want to know if P(-Y|F) = P(-Y), Y is the event "the other bonus is not present" (and F is "The improvement failed to produce a bonus").

Code:
P(-Y & F)/P(F) = P(-Y)/P(F)  [I](since -Y --> F)[/I]

which clearly gives conditional knowledge if failure is not 1. However, let's now consider a player who is eager to assume a certain bonus resource is present. We want him to be wrong enough of the time that the scripting described is not a reliable visor into hidden information. Consider the chances of both type I error and type II error. What we can control is the fact the player only gets one sample of the tile. We're already talking about a player who gets nothing and is suspicious of a hidden resource, so obviously type II error we don't care about (the player is rejecting the null hypothesis). We want to magnify type I error. However, we also want the effect of random failure to be minimized.

We can't really control the player's hypothesis, and we already proved they are going to be a little bit right, so let's look at possible ways to introduce doubt.

y is a constant, and x is something the player will know too. So the chances P(-Y|F) and P(Y|F) are both known to him. Y^F = Y^-X, so P(Y|F) = P(-X&Y|F) .
These are complements, so P(-X&Y|F) = 1 - P(-Y|F) . Suppose what we really want is for the hypothesis that the failure is the result of random chance to be as good as the hypothesis that it was because of a hidden resource. (This is still a lot of knowledge about the tile - 50% right is better than (1-y) probability right.) This is when P(-X&Y|F) = P(-Y|F). Since they are complements, it is when they are 0.5.
Thus, solve the equation:

Code:
0.5 = P(-X&Y|F) = P(-X&Y&F)/P(F) = P(-X&Y)/P(F)
= P(-X)P(Y)/P(F) = (1-x)y/(1-xy) = (y - xy)/(1-xy)

The delightful app at Mathway.com solves this reciprocal equation because I can't work fractions (or radicals) a damn, and x = 2 - 1/y
Notice that to bound x in [0,1], 1/y must be in [1,2] or equivalently, y is in [0.5,1]. So the incidence of incompatible resources must be no greater than a half, which is certainly doable. Recall x,y were the probabilities of non-failure, so y is the complement of the incidence of the incompatible resource. Also, xy =/ 0, xy =/ 1, and y is certainly in (0,1), so the real bounds are x in (0,1) and y in (0.5, 1) .

So, if, say, the resource occurs on 15% of tiles, y = 0.85, and x =~ 0.82 . So the terramorphous improvement should be configured to "randomly" reveal its intended bonus 82.35% of the time.
Actually, this is a maximum bound on x, since we don't care if the hidden resource turns out not to be there even more than half the time. We wanted to keep x as large as possible though, as it just interferes with gameplay.

Suppose instead we want the chance of a guess of a resource to be minimally more accurate than without the sample of the TMI. That is, we want a type I error as close as possible to the naked chance (y) of there being nothing there. So we want the chance of observing F and asserting --X to be wrong as much as possible.
H0 is the hypothesis the TMI randomly failed, which has probability P(-X|F) (as an explanation of event F which is already known). How can we vary this in relation to P(Y)?

Our eager Civizen is rejecting H0, so he is wrong with probability P(-X|F) = (1-x) /(1-xy) . I just studied a function like this a week ago: u/(1 - y + uy) . (u=1-x) . Here is a link to a Mathway that graphs this function for y of 0.9, 0.85, and 0.51 (recall y is bounded by 0.5)
http://www.mathway.com/graph/NDI5MjM {after loading, click a colored square next to an equation and set the color to make the app draw the graphs}

Focusing on the region (0,1), it's clear this function is bounded below by f(u)=u, and is strictly increasing in y. We want to minimize u to impact gameplay the least, but still have a large error chance. Let's have a "good enough" condition on the error chance and minimize u. Either we're comparing to the chance of guessing the hidden bonus is present and we're wrong, or the chance of guessing that and we're right : Y and -Y , respectively. To relate to values for u, find the intersection with the constant function f(u) = y
Again, solving an equation gives u = y/(y+1) . With y in (0.5,1), u is somewhere between 1/3 and 1/2 . So the more prevalent the resource is, the easier this masking task is (unintuitive).

Combining the two results, we want u > y/y+1, which is to say x < 1/(y+1) , and also we want x < 2 - 1/y (not strict inequalities). The largest x satisfying both , rounded to fit a computer simulation, is thus

round[down]( min{1/(y+1), 2 - 1/y} )

x is the probability of the improvement "randomly" revealing what it is supposed to add. y is the complement of the prevalence of incompatible resources (that will interdict the improvement's scripted effect). If the incompatible resource(s) occur on half the tiles or more, this technology does not work.
Um... I'm really going to need a few extra hours in the day to try to decipher this suggestion...
 
Try rereading the header now.
edit: also, I can't be the only person in this forum with stats background. You're all super-accomplished software designers!
 
My job was in software for statistics for 30 years, now I am retired:D.

Two points

1) the number of undiscovered resources reduces over time. On land there are at least coal, titanium and uranium at the time that you first get to use a Great Farmer. Oil is a possibility also if you did not the event that reveals it.

2) using the extra resources option with or without the "full of resources" map script means that almost every plot has a resource.
 
Try rereading the header now.
edit: also, I can't be the only person in this forum with stats background. You're all super-accomplished software designers!

I don't think it's that. I can get through it slowly if I read it a couple of times. But my first impression of it is perhaps the most valid: this sort of maths is wasted on Civ. No insult to Civilization, C2C, or your maths intended! I've seen maths of this complexity utilised before, but in World of Warcraft and Eve - pvp games where even the slightest edge can make a difference in whatever dick measuring contest people who sometimes play those games engage in.

An exploitative player in C2C can always access World Builder. Hell, I just accessed it to give the Incans a bunch of free cities because they were on a continent on their own with only 1 city, solidly into the classical era running monarchy. And I couldn't help but notice the mountain plot near my capital which had coal on it when WB was activated, a plot I would have put a mountain mine on anyway once I got to mountaineering.


Anyway, if introducing a probability based system for placing new resources through the great farmer or whatever, it would help to not make completion of the improvement kill the farmer. Even as it stands it's only a micro-manage-type annoying thing; the farmer makes a new bonus, he dies, so you get a nearby city to make a new guy next turn. They're not that expensive, so building a new one isn't a burden, yet if you forget about it there could be several turns where you don't have a guy making stuff. They're national units <iMaxPlayerInstances>1, so you've only got one anyway. (And yes, I've edited the xml in my own game to have them not be consumed and tried it out and it's fine and doesn't seem to upset game balance or anything, really all I do is end up placing wine so I can get those vintage wonders.)

If there was a new Great Prospector or whatever type unit who could do the same for minerals, it wouldn't have to die either. If you picked a plot that had a hidden resource on it and he failed, you've just wasted X turns of work with your single national unit (and however much gold it costs, seriously make it a LOT).
 
Top Bottom