How the AI knows the progress of your Wonder building

Well I just spent a fascinating hour looking through the parts where it chooses techs (CvPlayerAI::AI_bestTech()) and city builds (CvCityAI::AI_chooseProduction()).

They're pretty long and complicated functions and that's my first time looking at the Civ 4 code but I can't see anything like either of the suspected cheats. I would expect it to be quite a large hard-to-miss piece of code too if it's got to look at all items on the build queues of all enemy cities. Happy to be proved wrong though.

One thing that did pop out was as Dirk mentioned a while ago civs with zero wonderbuild probability will still occasionally build wonders, because it always adds a little fudge factor to what it gets out of the XML.
 
I suspect the RNG sequence is being affected here when we stop working the mine. Working a mine for a turn requires a RNG roll to see if we discover gold/whatever.

Then there's a butterfly effect across the board. The Babylonian archer to our north wins his battle with a different amount of HP remaining. Babylon itself finishes a spearman and starts on the great lighthouse next instead of an axeman. And Djenne starts the oracle - no cheating need have been involved.

I'm still curious to hear the results if anybody goes code diving :)

We have two hypotheses here.

1.
The most credible-sounding one from half-remembered reports of earlier code dives is that hammers into a wonder reduces the attraction of the associated wonder tech by a bit.

2.
The hypothesis this thread is toying with is that some aspect of the hammers input into a wonder actually deters AIs from starting the wonder itself.

I think people may be trying to make themselves believe in number 2 because it's a more direct effect and gives you something concrete you could actually use. Number 1 is rather subtle and hard to see exploits for.

Wow! Thanks for putting together my though in a more coherent way! :goodjob: :)
I'm in the ones that from experience wonders (after reading about it) if this cheat might be true; but at the same time wouldn't affirm anything close to 'likely true' for now; just say: "improbable, but might be true".

---

However, if true, it would be an interesting game feature.

And about the meaning of it: why don't take into consideration the opposite reason?

I mean, if it was meant to allow the player to build its targeted early wonder even on higher levels? I mean if a Deity AI wants to build the Great Wall, with all bonus it gets, it would get it chopping/whipping or whatever I believe, end of story. So before proceeding to build it, the AI checks if that is the early wonder the player wants, and like pick another one (or something else) in that case...
Just a silly reflection, if too dummy, just ignore it. :D
 
Does your choice of working a mine or a food tile affect the RNG? If not, then the only explanation for Mansa's behavior is that he sees you building the Oracle and assigns a different valuation to building the Oracle, which causes him to build walls instead. Honestly, I don't think your choice of tile assignments affects the RNG.

Of course it does -- mines can "pop" a resource, and the game uses the random number stack to check.

Another way to experiment with that idea is to replace the mine with an equivalent production tile; use the world builder to replace the mine with camped elephants, and see what happens.

When I do that, I get the oracle build each time (in am insignificant number of trials).



You could confirm that the random number stack is being consumed differently by turning on the right logging, although it appears that doing so requires rebuilding the DLL (or knowing which bits in the save file to hack to enable it).
 
The theory that changing tiles doesn't alter the RNG itself, but working a mine does because of the resource-pop roll, makes sense from what most people here know of the code, and has been shown twice now. I think it's reasonable to take that as an assumed fact.

In light of that, consider this: instead of writing a piece of code to check for invested hammers in the build queue of every city every turn, it's easier to write a code that weighs the AI's interest in producing a wonder based on the likelihood that the wonder may be in the process of being built somewhere else.

We know (I think? at least it's accepted as fact, for sure) that the AI is deterred from researching the "goodie" techs when the first person reaches it. We've also seen Soren state in that Google Tech video that they included abstract concepts of benefits in the Civ AI for buildings and techs. For instance, the AI weighs what a Temple gives them for benefit, or whether a tech allows something special (I think the video mentions irrigation), before building, or researching, the specific item.

So, isn't it likely that they built in a similar function for wonders and techs? If the AI can consider the benefits of a tech (and likely determine when the allure of the freebie is there and when it is not, as we have seen with religious techs, etc.) before researching it, isn't it likely that they built in a similar line of thinking for wonders?

As a human, the thought process for attempting a wonder on a difficulty where the AI can compete for it is often: was I first to the tech? If I was not first, how many turns behind was I? Can I make up the lost turns of teching with my production? So for example, if we get beaten to Literature by 50 turns, we know that getting the Great Library is a long shot, because we weren't there first, and the AI is likely building it. So wouldn't it be reasonable, instead of making the AI check the production of every city every turn, to just build in an artificial "freebie" bonus for researching techs that has to do with being first to attempt a wonder? We already know that the AI won't trade a tech if they're building a wonder from that tech; they can clearly see when a tech and a wonder are related. Maybe when they determine that an opponent has hit the tech first, the weight of the benefit of being able to build the wonder is reduced because the likelihood that someone else is producing the wonder has just increased, reducing the chance that the AI will get there in time.

Finally, one thing could contribute to the possible illusion that the AI knows when an opponent is building a wonder: often when a tech is researched, the human (can't speak for the AI here) starts building the wonder right away. Though the tech research and wonder building are clearly separate events (in that one does not necessitate the other). But if the AI considers the tech being researched somewhere else as a deterrent from building it, two seemingly independent actions are the same thing to the AI. This may lead to the situation where the human feels the AI has avoided the wonder because they were building it, when in reality the tech being researched may be the driving factor. This could probably be tested in some way by granting techs and changing build orders to see what the AI does.

Coming back the the top and tying this together, all of that decision making could be weighted by the RNG also. Thus, even though Mansa may have be badly beaten to Priesthood and his logic says "no way, don't build the Oracle," the changed tiles that activated an RNG roll for the mine may have triggered the "oh hell let's ignore the logic and build it anyway" code.

Or all AI builds could be random and it's just selective memory (like the "combat odds are rigged!" folks). My gut feeling says that the AI doesn't know what opponents build and acts based on something like I described, but the fact that so many people have circumstantial evidence that indicate the opposite makes me unsure.

EDIT: After thinking about the Soren video again, he says that all the supposed cheats for the AI are there to make up for the deficiencies of the AI with respect to the player. Being able to see every Civ's build queues isn't making up for anything because this is not something the player can do (without espionage or whatever). It makes much more sense, again, to weight it the way I described because the AI deficiency there that would be accounted for is the ability to weigh the allure of a wonder against the likelihood that an opponent would get there first. No cheating required, just logical reasoning based on information about opponents that can be known to both humans and AIs (in most cases). Of course, allowing the AI to know the techs of opponents before Alphabet or of those they haven't met might be a slight cheat, but that's a sidebar to the main discussion.

And if anyone hasn't seen it, Soren: http://www.youtube.com/watch?v=IJcuQQ1eWWI
 
A save where i clicked 3 turns to 1520BC and kept it for some reason.

Spoiler :
1520u.jpg


Djenne started on it
Spoiler :
15202.jpg


I switch to working all 3 mines, Oracle in the queue with 1 turn..
Spoiler :
hammersq.jpg


clicking next turn, and Djenne abandoned the Oracle for a hindu missionary :crazyeye:
Spoiler :
whatwp.jpg


Reloading shows that with switching to 1 or 2 mines, Djenne has the Oracle built in 7 next turn.
Working no mine, built in 8. Could be completely random, but i didn't know that the AI will stop building a wonder in peace times.
And only switching to 3 mines seems to result in that, tried lots of other tile combinations.
 
Looks like he might have 1-whipped the oracle in that screenshot, rather than abandoned it. Seems to be some overflow hammers going into the missionary, and also Djenne should be size 8 by now.
 
Looks like he might have 1-whipped the oracle in that screenshot, rather than abandoned it. Seems to be some overflow hammers going into the missionary, and also Djenne should be size 8 by now.

Nopes, 2 turns forward to 1440BC..the Oracle is still in my queue

Spoiler :
1440q.jpg


And Djenne is now back on it, 6 turns left.

Spoiler :
lalat.jpg


Overall this is a lot more time than you should get on Deity, assuming iam chasing a fairy tale and the AI has no idea what is going in my city. But i don't buy it ;)
 
Continuing to play devil's advocate in the interests of science... :mischief:

As you said the AIs don't stop building wonders in peacetime. However in this case there's a barb warrior near Djenne and from my (extremely) sketchy understanding of the code that might well qualify as what it calls "danger", so a build queue re-evaluation is allowed. (If there were less than 4 turns left it would not happen even in a danger situation). So as MM just got OR he took the opportunity to train a missionary, and then no surprise the oracle was resumed.

Maybe easy to disprove that theory by removing the barb?
 
Both the screenshots fom Delhi in post 46 shows 1520BC. So, Mansa didn't stop building the Oracle to build a missionary, he just started on the Oracle in the first (with no mines worked) and he didn't do it in the second (mines worked). Like previously said, mines change the RNG when worked.

The way Mylene wrote lead to believe that Mansa started building the Oracle when Delhi was working food and change the build once Delhi started working mines. That's not what happened. You can see that Djenne has the same pop in both screenshots for further evidence.

I don't see how post 46 contradicts what has been said here about how the RNG works.
 
Both the screenshots fom Delhi in post 46 shows 1520BC. So, Mansa didn't stop building the Oracle to build a missionary, he just started on the Oracle in the first

Sigh...fine, here is your Hindu with 1 turn left at 1440BC.
To raise the tension, here is me the second before i click it, woowoo :)

Spoiler :
blahg.jpg


And here he is...

Spoiler :
blah2up.jpg
 
To end this experiment from my part (cos people will believe what they feel is right anyway ;) )
the Oracle finally went on 1200BC to someone unknown, Mansa continued to delay it.
After GLH and same times as Mids, draw your own conclusions :)

Spoiler :
endfk.jpg
 
It seems pretty obvious that the "seed value" used by the RNG is saved in the game save file, otherwise there would be no need for a "random seed on reload" option.

I have a vague memory of divergences happening to the same save when different people play it forward which makes me doubt it a bit, but I could just be imagining it.
 
Could the divergences merely be different actions, or even possible the same actions in a different order causing the RNG to effect different things with different values. Since the build decisions are determined by the RNG what needs to be figured out is if the time since the tech was first researched is what lowers the chance of it being built or if hammers in the wonder lowers the chance. Its more likely that something atleast does than it not being effected at all :)
 
The game does save the random seed. Selecting "new random seed on reload" will cause it to generate a new seed when you reload. Great People do not work the same way - selecting "new random seed on reload" doesn't change what Great Person you get if you reload back one turn ago. I'm not sure whether it just saves that "roll" earlier (then only uses it when you actually pop a GP), or if it has a whole separate pseudo-random number generator function just for great people.

If you want to demonstrate "cheating" AIs, you'll need to demonstrate a statistically significant AI preference for not building Oracle when you would finish it first by replaying the same turn over and over when you have "new random seed on reload" selected as a game option, or you need to dive into the code and find some lines that actually cause that behavior (I gave a cursory glance and didn't see anything obvious either way - CvCityAI is kind of a mess).
 
Back
Top Bottom