Alpha Centauri 2

Sid Meier's Alpha Centauri & Alien Crossfire => Modding => Bug/Patch Discussion => Topic started by: bvanevery on February 16, 2020, 01:36:54 AM

Title: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on February 16, 2020, 01:36:54 AM
I have proven to my satisfaction that the University AI uses Directed Research, rather than Blind Research, to go after the Hunter-Seeker Algorithm no matter where it is located in the tech tree.  I noticed because my mod is different from vanilla.  My University is Passive rather than Erratic and does not have a -2 PROBE penalty.  None of my social engineering choices have PROBE penalties.  I consider the Hunter-Seeker Algorithm to be a Conquer tech and have it weighted accordingly.  My Pre-Sentient Algorithms is a Tier 5 Conquer tech with no Discover component at all.

Despite these differences, the University was beelining up the Conquer techs, totally bypassing the Discover part of the tech tree I'd laid out for it!  When I disabled the HSA from the game, the behavior stopped.  When I moved the HSA to my Explore 5 Centauri Psi, it would beeline for Centauri Psi.  It took longer because more prereqs in more categories were needed, but eventually it got there by the shortest path it could.

This is the 1st time in almost 2 years of modding, that I've come across definitive proof of the AI ignoring the tech weights in alphax.txt.  And AFAICT, it only happens in pursuit of the HSA.  Otherwise all the factions have seemed to do what I'd expect.  My Explore, Discover, Build, and Conquer trees are quite disentangled from each other nowadays, so when a faction starts researching stuff it shouldn't be, it's quite noticeable.

I believe at some point in SMAC's development, someone decided that the University absolutely must try to get the HSA and hardwired this cheat.  Whereas in my mod, I don't believe in the "easy mind control" play mechanic.  I think it's lousy and I got rid of it.

I also haven't found the University's research to be "all that", so I goosed it with free Biology Labs in addition to free Network Nodes.  My Gaians are also a part research faction with an Explore and Discover focus, and they get free Biology Labs only.  Well, when I put the HSA at Conquer 4 Advanced Military Algorithms, the University was beginning it by turn 75!  On a Huge map I might not even have Probe Teams by then.  Clearly this is intolerable, so I've been looking at fixes.

The best that I can seem to do to slow the University down, is to put in prereqs from broad sections of the tech tree, so that the University has to grind through the maximum amount of stuff to reach its goal.  That's not good lore, but it's an effective patch for the gameplay.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on February 26, 2020, 06:34:03 PM
I found this scenario interesting. I think I found the code responsible. There is a tech_val() function that from what I can tell helps guide or add weight for reaching specific tech goals. It looks like if the faction's base SE Probe score is <= 0, then it focuses on trying to reach HSA. This is fairly early on in this large function. Try setting the University's SE probe value to 1 rather than 0. From my testing, this causes them to skip trying to build HSA. This looks like a fun function to do, I might try to decompile it tonight. It would also give me a temporary distraction from slogging through Path path-finding class that is 60-70% done.

(https://i.imgur.com/GkETbBv.png)
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on February 26, 2020, 11:18:34 PM
Interesting deduction.  However I have trouble believing it's any faction and PROBE <=0.  Most factions in my mod have PROBE = 0 to start with.  The Hive and the Cyborgs have +1, the Data Angels have +2.  No faction has negative PROBE.  My SE table doesn't have PROBE penalties.

In the stock game, the University has -2 PROBE.  No other faction has a PROBE penalty.  I thought perhaps the binary had hardcoded a response to the University's problem.

In other factions, I have not previously noticed the HSA beelining behavior.  It's possible the behavior is there, but other factions have research rates that are too slow to matter.  In my mod, SPs are expensive, and it tends to be a "big distant economic powerhouse" faction that gets the HSA.  Assuming I don't.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on February 27, 2020, 02:43:58 AM
The way most faction specific checks in the game work is by doing a compare to the faction's filename. For example (https://github.com/b-casey/OpenSMACX/blob/master/src/base.cpp#L571), the Caretaker Secret Project exclusion check for bases.

There are some of these checks for University related to tech, but they're all diplomacy related (buy, trade, gift). Nothing specific to goals. That isn't to say there wasn't game logic designed around them that doesn't blatantly call out University (ex. FREEPROTO flag only used by Spartans).
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on March 02, 2020, 12:22:52 AM
Looks like there are some other factors that drive University towards HSA. Do you make any changes to AI values (ai-fight, ai-power, ai-tech, ai-wealth, ai-growth) inside faction text file? The default for University is all zeros with 1 set for ai-tech.

Here is the full code segment from the screenshot above. Based on default values, University is definitely driven to gain tech to build HSA. They are not alone, Peacekeepers and Consciousness are also driven towards this based on default values (x4 weight given to HSA tech). There are also 5 factions that give x2 weight towards HSA. You may be right that since University has faster tech gains it is more noticeable.

Code: [Select]
if (PlayersData[factionID].SE_ProbeBase <= 0) {
if(tech_is_preq(techID, Facility[FAC_HUNTER_SEEKER_ALGO].preqTech,
(PlayersData[factionID].AI_Tech != 0) + 2)) {
if (!PlayersData[factionID].AI_Power) {
valueRet *= 2;
}
if (PlayersData[factionID].AI_Tech) {
valueRet *= 2;
}
}
}

Excluded due to Probe SE (no weight):
Angels:         0, 0, 1, 1, 0 (+2 base PROBE)
Believers:      1, 1, 0, 0, 1 (+1 base PROBE)

Excluded non-zero ai-power with zero ai-tech (no weight):
Planet Cult:    1, 1, 0, 0, 1 (0 base PROBE)
Hive:           1, 1, 0, 1, 0 (0 base PROBE)
Pirates:        0, 1, 0, 0, 1 (0 base PROBE)
Usurpers:       1, 1, 0, 1, 0 (0 base PROBE)

ai-power zero, ai-tech zero (x2):
Drones:         0, 0, 0, 1, 0 (0 base PROBE)
Gaians:        -1, 0, 0, 0, 1 (0 base PROBE)
Morgan:        -1, 0, 0, 1, 0 (0 base PROBE)

ai-power non-zero, ai-tech non-zero (x2):
Caretakers:     1, 1, 1, 0, 1 (0 base PROBE)
Spartans:       0, 1, 1, 0, 0 (0 base PROBE)

ai-power zero, ai-tech non-zero (x4):
Consciousness: -1, 0, 1, 0, 1 (0 base PROBE)
Peacekeepers:   0, 0, 1, 0, 1 (0 base PROBE)
University:     0, 0, 1, 0, 0 (-2 base PROBE)
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on March 02, 2020, 03:43:12 AM
I changed University Personality from Erratic 0 to Passive -1.  ai-fight doesn't appear to be a value in the case logic you found.

Does the game have hardwired modifiers for lots of SPs?  Or is it only the HSA specifically singled out for this treatment?
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on March 02, 2020, 04:21:23 AM
I changed University Personality from Erratic 0 to Passive -1.  ai-fight doesn't appear to be a value in the case logic you found.

Does the game have hardwired modifiers for lots of SPs?  Or is it only the HSA specifically singled out for this treatment?


In that case, University with SE base probe 0 and default ai-tech/ai-power then Univ would still put x4 priority towards HSA tech.

Yep, besides HSA there are two other SPs with tech weight values: Ascent to Trans and Dream Twister.

I'm still working through tech val function but once I'm finished I think there will be a better understanding of how AI and blind research works.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on March 02, 2020, 05:14:30 AM
Ascent shouldn't matter in my mod.  It's at the end of my tech tree!  You have to complete all techs to learn it.

Dream Twister is all the way up the Explore tree in my mod.  Not so different from the original game that way.  I've changed some things as to "what's Explore", to make it more purely about mindworms.  For instance, you don't get Missile Launchers that way.

The HSA, I don't think of it as "avoid techs being stolen".  I think of it as, "avoid bases being mind controlled when I'm conquering."  That's why I put it in the Conquer part of the tree.  The HSA doesn't make your research go faster.  It just keeps other players from getting ahold of it.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on March 08, 2020, 11:17:36 PM
I've decided to put the Dream Twister super far up the Explore tree in my mod, to stop it from interfering with things.  It's overpowered anyways.  Now I've got it with Sentient Resonance.  If I understand your code, a qualified Discover faction would start getting the weights 3 prereqs before the Dream Twister tech.  A qualified non-Discover faction would get them 2 prereqs before the tech.  This definitely won't affect anything in the early to midgame now.  By the time the Dream Twister becomes available, the game should be over already.  Assuming a veteran butt-kicking player on Transcend; YMMV for lesser levels of player skill.

I've thrown in the towel and put the Hunter-Seeker Algorithm back in the Discover tree.  That way, qualified Discover factions actually learn Discover techs, instead of something else.

I am concerned that this strong Discover pull, may derail my version of the Gaians.  I have them as a combo Explore, Discover faction.  The Cult of Planet, in contrast, is my pure Explore faction.  I fear that the Gaians may not learn the Explore techs they're supposed to, instead 4X fixating on the HSA.  I'll be playtesting the Gaians to see what happens with my newly reworked tech tree.

Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on April 18, 2020, 06:43:11 AM
Putting the Dream Twister far up my tech tree, isn't really working.  The game can still realistically go on as long as Sentient Resonance.  I'm actually trying to seek Economic Victory, which in my mod requires Global Energy Theory, a Build tech.  I can't seem to learn it until I've got Sentient Resonance, which is annoying.  The only thing positive I can say, is my research is fast enough that the disruption won't last too much longer.  But it can still translate into hours of real world play time.

Do you happen to know which choices trigger a big Dream Twister weighting boost?  I would hope it's not the same as the HSA, with Discover and non-Conquer.  It would be at least rational to expect Explore to take the place of Discover.  I'm currently doing Build only, so I'm a non-Conquer faction, and I haven't done Conquer at all since the beginning of the game.  I'm also +3 PLANET and it wouldn't surprise me if that exerts influence, same way that being 0 PROBE or lower exerts influence for the HSA.

Arguably, the game thinks a PLANET-friendly faction is supposed to want the Dream Twister above all else.  But I'm doing it for the resource bonuses from the Manifold Harmonics.

EDIT: it didn't beeline after all.  Just seemed like it was going to.  I'd still like to know when it beelines.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on April 22, 2020, 08:33:44 PM
I've finished the tech_val() function and now just need to run it through my battery of regression tests. Pretty much everything is identified except for a couple checks that tie into Continent struct I've been working on. I'm going to wrap up a few more map functions and push an update sometime next week.  I've been pretty swamped with work and training. Will let you know once it's on git. They're not fixed weights because a lot of checks are dependent on current game state and faction. If you would like, I'll leave in my regression test code that dumps all tech weights for each faction to log file. You would just need to use a debugger to change current execution point (eventually I'm going to hook some of debug shortcut keys). I generally set a breakpoint on stack_fix() since it's pointless for singleplayer then change origin to tester function.

Here is reference to Dream Twister:

Code: [Select]
if (Players[factionID].rulePsi <= 0) {
<snip, various checks related to reactor tech>
}
else {
if (tech_is_preq(techID, Facility[FAC_DREAM_TWISTER].preqTech, 9999)) {
valueRet *= 2;
}
}
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on April 22, 2020, 09:59:40 PM
Thanks for that, I'll try to wrap my head around it.  My musings are by no means some urgent request.  Not clear on what rulePsi is.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on April 22, 2020, 10:24:36 PM
Of course! I figured I might as well keep test code there since I'll be building it out to ensure everything is working correctly anyway. I generally delete it from temp.cpp once I'm done so it doesn't get too cluttered. I'm sure there is interest how the AI picks tech.

; SPECIAL RULES = rule, parameter
;
;   PSI         = Percentage combat bonus for PSI Combat.

So rulePSI is if a faction has the special rule set for PSI. It looks like the default factions don't have this set. It would be something like "PSI, #" near top of faction file. If you don't have it set for any of your factions there is something else at work that is shifting priority towards Dream Twister tech.

Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on April 22, 2020, 11:49:27 PM
I have not actually observed a "pull to the Dream Twister" in the wild.  I was led to believe that such a pull could occur.  I'm now thinking this is debatable.  None of my factions have any inherent Psi combat bonus.  The Gaians ever so briefly did in one release, before I decided that was overpowered, and gave them free Biology Labs instead. 

Whereas, I've observed a pull to the HSA, and the effect is quite dramatic.  I didn't like having to work around that, but I did.

The Dream Twister deserves to be far up the tech tree anyways for other reasons.  It's overpowered.  Even the Xenoempathy Dome is overpowered for when it is offered.  I moved all that stuff farther up, in sequence.  I'm happier with it.  Means you actually have to use some fungal tactics and not just get a cakewalk by virtue of setting your focus to Explore.

I don't know when, if ever, I'll observe a Dream Twister pull.  I'm wondering what 9999 means.  It looks like a "disregard" value, the sort of thing you'd do if you wanted 0 to be a legitimate input.

 
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on April 23, 2020, 12:07:09 AM
From what I'm seeing, only modified factions with that PSI flag would ever see a pull towards Dream Twister tech. All the original SMAC/X factions would never get to the else section of code since rulePSI will be zero.

The 9999 basically tells it to find any prerequisite tech. There are about 15 instances inside tech_val() where it uses the max range. Not all tho, some are like a range of 2 or 5. It's basically telling it how far to recursively go to find prerequisite tech.

Purpose: Determine if preqTechID is a prerequisite of parentTechID within descending range.
Return Value: Is preqTechID prerequisite of parentTechID? true/false
BOOL __cdecl tech_is_preq(int preqTechID, int parentTechID, uint32_t range)
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on April 23, 2020, 01:13:41 AM
Good grief, most of my tree would be a prereq for the Dream Twister.  Anything leading to Sentient Resonance.  Oh well, I guess that means I've rendered the problem mostly meaningless, even if a pull was triggered.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on May 18, 2020, 01:31:16 AM
This was not fun to clean up and test. It comes in as the 89th largest function in the game, mostly because of inline function code from compiler optimizations. Let me know if you have any questions.  :)

https://github.com/b-casey/OpenSMACX/blob/master/src/technology.cpp#L302

Also, I left in some testing code if you wanted to see output for all factions / tech. Using a debugger, cause game execution to pause with a breakpoint. My recommendation is on stack_fix() at 0x005B8E10 that triggers when you click stack of units or a base. After that, redirect code flow to function below in DLL. It should be listed under exports. It will then iterate and dump output to logfile.txt.
https://github.com/b-casey/OpenSMACX/blob/master/src/temp.cpp#L438

I would be interested if it dumps any errors. It shouldn't, I ran this through rigorous testing and manual review. But I figured I would leave in check.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on May 18, 2020, 04:06:49 AM
That function is far out!  It will take some time to contemplate.  'Fortunately' COVID-19 grants time.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: EmpathCrawler on May 19, 2020, 03:36:26 AM
Weird how they didn't bother to make the Dream Twister a priority for factions with positive PLANET scores but left in the unused Psy rule compulsion.


Am I reading it right where if a faction has a positive Population rule, they are actually more compelled to research Hab Complexes?
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: scient on May 19, 2020, 03:54:31 AM
Weird how they didn't bother to make the Dream Twister a priority for factions with positive PLANET scores but left in the unused Psy rule compulsion.

I know. Line 425-427 is never reached with vanilla factions.

Am I reading it right where if a faction has a positive Population rule, they are actually more compelled to research Hab Complexes?
You are correct. The faction would be compelled to research Hab Complex/Dome. It looks like Morgan is the only vanilla faction that has POPULATION rule set.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on May 19, 2020, 10:05:19 AM
It looks like Morgan is the only vanilla faction that has POPULATION rule set.

To be quite exact, the only vanilla faction with POPULATION > 0.  The Peacekeepers have it "set", to -2.  It definitely makes sense that if you're crippling a faction with a hab restriction, that they need a strong pull to get the Hab Complex.  Of course it was bad game design to begin with, something I got rid of in my mod.  I suspect there are going to be a number of cases where they put something in alphax.txt, it wasn't really a good idea, so they "fixed" it by hardwiring the binary.

Well at least now the Dream Twister mystery is solved.  I don't believe in giving Psi combat bonuses, so no issue for me.

I'm noticing special privileging for Explore PLANET factions, which would be all 3 of mine since I decided they needed to get their mindworm thing going on.  Centauri Meditation and Planetary Economics both get boosted.  Fortunately I don't consider that much of a problem, but I don't really see the rationale for the latter.  Hybrid Forest, why make it a super duper PLANET faction thing?  Just because Deirdre had some lines about it?

Why hardcode a boost for Environmental Economics as a Build tech?  It's got a Build tech weight in it already in alphax.txt.  Did this code get written before the generalized 4 field weighting mechanism was in place?  Or did it get written in a hurry, trying to fix problems at the binary level?  Did they decide alphax.txt wasn't something they could do revisions of after shipping the game, but they could change the binary around?  It doesn't make sense to have this going on in 2 different places.  This sort of thing is kind of a mess.

Well, at least such an implementation doesn't violate the basic theory of categorical weights actually mattering.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: EmpathCrawler on May 19, 2020, 02:46:39 PM
You are correct. The faction would be compelled to research Hab Complex/Dome. It looks like Morgan is the only vanilla faction that has POPULATION rule set.


Ah, I forgot POPULATION limits size with positive numbers.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: EmpathCrawler on May 19, 2020, 03:22:15 PM

Why hardcode a boost for Environmental Economics as a Build tech?  It's got a Build tech weight in it already in alphax.txt.  Did this code get written before the generalized 4 field weighting mechanism was in place?  Or did it get written in a hurry, trying to fix problems at the binary level?  Did they decide alphax.txt wasn't something they could do revisions of after shipping the game, but they could change the binary around?  It doesn't make sense to have this going on in 2 different places.  This sort of thing is kind of a mess.

Well, at least such an implementation doesn't violate the basic theory of categorical weights actually mattering.

Well it's not a boost to research the tech, but for the AI to research its prerequisites from the very bottom of the tree up if I'm reading it right. It looks like the alphax weights are directly used to make a decision when the AI selects the next tech to research, but any deeper thought is handled in the exe on a case by case basis. Maybe they wanted to nudge a Build AI to research the commerce-enabling techs? I don't understand the cloud cover condition.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: bvanevery on May 19, 2020, 07:49:47 PM
Well it's not a boost to research the tech,

It's what it accomplishes in practice.  It's beelining code.  Even a human player experiences the beelining phenomenon.  Meet the conditions, and your research will head straight for the Hunter-Seeker Algorithm.  I say they either didn't have time to test their weights in alphax.txt and so implemented "expedient hacks" to fix problems as they eventually noticed them.  Or they decided they couldn't ship alphax.txt for some reason but could ship binary patches.  Maybe they were worried about players modding alphax.txt and wanted to force certain behaviors.

Quote
I don't understand the cloud cover condition.

It would only make sense if at some point they had cloud cover as an empire wide problem.  Which maybe they toyed with at some point in their development, who knows.  Nothing about this code says it's good code.  We're clearly looking at a collection of hacks.
Title: Re: The University cheats to get the Hunter-Seeker Algorithm
Post by: EmpathCrawler on May 19, 2020, 11:46:58 PM
To be clear, it's not doing anything to the Build weight. It's doubling the fully calculated sum of weights only if the tech is a prerequisite to Environmental Economics. There is no way to accomplish that with alphax weights alone without completely restructuring the tech tree below Environmental Economics to accommodate something extremely specific to cater to a few factions. Maybe they factions with Build plus another interest (Yang? Roze? Marr?) were weakening themselves by not taking certain Build techs when their other interests suggested something else.


Regardless, the rationale is unknowable and not really worth deducing.
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 4: index+Modifications.english (default), TopicRating/.english (default), PortaMx/PortaMx.english (default), OharaYTEmbed.english (default).
Style sheets: 0: .
Files included: 31 - 840KB. (show)
Queries used: 15.

[Show Queries]