1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Artificial Unintelligence

Discussion in 'Civ5 - Mod Components' started by Delnar_Ersike, Oct 23, 2014.

  1. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Artificial Unintelligence
    Improves Civ5's AI. Nothing more, nothing less.
    Latest version: v9 w/ mini-update, released 2015-01-09

    Workshop Link to Full Version
    Workshop Link to Lite Version (XML files only)
    CivFanatics Download Link to Full Version
    CivFanatics Download Link to Lite Version

    GitHub Repository for Source Code (Fully populated!)
    All of my changes are wrapped in preprocessor directives using defines located in AuI.h. Parameters that have the word "FIX" in them are fixes for AI bugs or bad code (therefore merging them should be a priority).

    This mod, to my knowledge, is the most extensive AI mod available for Civ5 as of yet. Pretty much everything has been tweaked or overhauled: city placement, unit management, choosing beliefs, voting on UN resolutions, choosing ideologies, tech progression, puppet-annex-raze logic, choosing promotions, the whole "Grand Strategy" dynamic, formations used by the AI, Great Person handling... the list goes on. Diplomacy and Deal AI are the only big exceptions, seeing as those systems are a lot harder to troubleshoot for AI-only games and pretty much require a complete rewrite due to how gamey they currently are.
    The mod contains nothing but AI changes; the only non-AI change is the implementation of a second random number generator that returns values in a binomial distribution instead of a flat distribution, but only AI-related routines have been modified to use this random number generator.

    The lite version contains only XML changes for maximum compatibility with other mods.
    Note that my DLL does not necessarily depend on the values I used in my XML files, so it should be compatible with all non-DLL mods.

    List of all XML-based changes in no particular order:
    Spoiler :
    • City strategy "Need Tile Improvers" has a threshold of 50 (from 67)
    • City strategy "Want Tile Improvers" has a threshold of 33 (from 40)
    • City strategy "Have Training Facility" alters flavors for tile improvement, expansion, growth, and happiness by -1 (from -3)
    • City Strategy "Capital Under Threat" alters Defense flavor by +35 (from +25)
    • Expansion flavor +5 in the AI's original capital
    • Economic strategies "Expand Like Crazy" and "Grow Like Crazy" give +75 Expansion and +75 Growth flavors respectively by (from +10)
    • Economic Strategy "Losing Money" now alters Gold flavor by +40 (from +25), Mobile flavor by -10, Ranged flavor by -10, and Naval flavor by -10
    • Economic Strategy "Losing Money" now checks and can trigger every turn (from 5 turns)
    • Economic Strategy "Early Expansion" now alters Defense flavor by +10
    • Economic strategy for Conquest Grand Strategy alters Air flavor by +10 (from +5), Mobile flavor by +5, and Gold flavor by +5 (to pay for unit upkeep)
    • Economic strategy for Spaceship Grand Strategy alters Growth flavor by +20 (population = science) and Gold flavor by +5 (to put it on similar footing as the other Grand Strategy stuff)
    • Economic strategy for Spaceship Homestretch alters Science flavor by +40 (from +25; helps the AI complete techs for parts it has not unlocked yet), Gold flavor by +10 (both an equalizer and helps the Freedom ideology), and Production flavor by +15 (helps direct towards improvements that increase production, thereby speeding up parts production)
    • Increased the effect grand strategies' primary flavor has on the AI choosing said grand strategy to 9/10/10/16 (from 9/10/10/13) for Conquest/Culture/Diplomacy/Spaceship respectively
    • Increased the influence of Grand Strategies on certain City Specializations: Conquest increases Gold specialization weight by 50, Diplomacy and Culture increases Science specialization weight by 50, Spaceship increases Food specialization (ie. Settler Pump) weight by 50
    • AI Conquest Grand Strategy's flavor effects added or altered: Offense by +3 (from +2), Expansion by +2 (from +1), Military Training by +2 (from +1), Air by +2 (from +1), Nukes by +6 (from +1), Mobile by +2, Defense by +1, Naval by +1, and Water Connection by +3
    • AI Culture Grand Strategy's flavor effects added or altered: Culture by +3 (from +2) and Religion by +2 (from +1)
    • AI Spaceship Grand Strategy's flavor effects added or altered: Spaceship by +4 (from +2), Science by +3 (from +2), Production by +2 (from +1), Religion by -2 (from -5), Great People by +1, and Gold by +1
    • Nukes flavor now increases drastically depending on the AI's Military Strategy: "At War" gives +20, "Empire Defense" gives +15, "Empire Defense Critical" gives +50, "War Mobilization" gives +10, and "Losing Wars" gives +30. For reference, the "Need Nuke" gives +150 Nukes flavor.
    • AI Military Strategy "War Mobilization" alters Growth flavor by -10 (from -50 in vanilla, -10 in Brave New World, this helps with warlike civs' science)
    • Commerce City Specialization alters Production flavor by +20 (from +10) and Growth flavor by +30 (from +20)
    • Science City Specialization alters Production flavor by +20 (from +10)
    • General Economic City Specialization alters Production flavor by +25 (from +20), Growth flavor by +30 (from +20), and Culture flavor by +20 (from +30)
    • Target gold and science yields per citizen increased by 0.3 and 0.5 respectively for the following city specializations: General Economic (now 0.3/0.5), Military Training (now 0.3/0.5), Military Naval (now 0.3/0.5), Commerce (now 1.3/0.5), and Science (now 0.3/1.5). Target food and production yields per citizen remain unchanged.
    • Modified Multi-Unit Formation settings to 1) allow for more flexibility between ranged and siege units, 2) allow for smaller task forces, 3) allow certain land task forces to also contain a single naval unit, 4) no longer have the AI place melee units into "slots" meant for ranged units, and 5) force fast-moving task forces (eg. Fast Pillagers) to only contain fast-moving units
    • Minimum Personality score now set to 1 (from 0) to fix possible divide-by-zero situations in the DLL code leading to wonky AI behavior
    • The AI can now send Great Generals with City-State attack squads
    • The AI will now place ranged units with a range of 1 (ie. gatling guns, machine guns, and bazookas) into the front row of formations when necessary
    • The AI will consider rushing items that take over 5 turns to build (from over 15 turns to build)
    • The AI places an extra 15 priority on techs that unlock unique units/buildings/improvements (from extra 5 priority)
    • The AI is a lot less schizophrenic when it comes to grand strategies: it will keep Grand Strategy directions active for at least 20 turns (from 10 turns), and during Grand Strategy rerolls, it will give each Grand Strategy a random extra priority up to +12 (from +50)
    • Grand Strategy rerolls do not force the AI to switch to less desirable options: other players' grand strategies multiply a certain grand strategy's weight by up to 10 (from up to 50) during AI rerolls.
    • Grand Strategy priority multipliers for Culture and Tourism ratios are now 50 and 100 respectively (from 75 each)
    • Reroll weight modifiers for the Conquest Grand Strategy have been adjusted as follows: being at war gives +20 (from +10), nobody met gives -25 (from -50), and conquered civilizations give +50 each (from +15 each). To compensate for possible overaggression, power ratio for Conquest Grand Strategy weight is multiplied by 125 (from 100).
    • Reroll weight modifier on the Conquest Grand Strategy for having met nobody now activates 40 turns in (from 20), but gives -100 (from -50)
    • Early AI expansion baseline set to 6 cities (from 8).
    • Plot value for strategic resources increased by +80 (from +50, the bonus is now double a luxury resource's plot value bonus)
    • Fierce land dispute increases plot value by +8 (from +6)
    • 250 Gold priority given to buying plots (from 275), but buying requirement is halved when treasury has contains over 500 gold (from 1000 gold)
    • Diplomacy has 50 Gold base priority each (from 150) and Defensive buildings have 250 Gold base priority (from 400), while Upgrades have 200 Gold base priority (from 150)
    • Worker plot evaluation is multiplied by 6/6/3/3/2 based on food, production, gold, science, and culture yields respectively (from 2/2/1/1/1)
    • Military threat weights for Minor/Major/Severe/Critical are now 1/3/9/27 (from 1/3/6/10)
    • Minimum units the AI desires to defend lands now increases by 1.5 per city (from 1.0 per city), allowing a unit to patrol between two cities to defend against barbarians
    • City specializations are rerolled every 4 turns (from 50)
    • City specialization reroll weight modifiers have been modified as follows: food specialization weights alter by -25 per number of cities (from -50), production weights alter by +1 for building the next wonder (from +0.2), science specialization weight alters by +40 for science flavor (from +20) and +40 for spaceship flavor (from +10)
    • City categorization thresholds altered: medium is now 6 population (from 5), large is now 15 population (from 12)
    • Negative gold income alters target gold yield per citizen by +0.5 (from +0)
    • Automatic Citizen Management's yield type values for Production, Science, and Culture are now 9/8/7 respectively (from 12/7/15 in Brave New World, 8/6/8 in vanilla)
    • AI's now recruit units within 6 tiles for City Attack operations (from 5 tiles), but only 3 tiles for Tactical Pillage operations (from 5 tiles). Up to 6 turns can be spent recruiting units for operations (from up to 5 turns), up to 12 turns in case of operations in enemy territory (from up to 10 turns)
    • Forward Muster commands are considered at 25% danger or less (from 20% or less)
    • When evaluating the AI tactical map, unit strength is multiplied by 20 (from 10); a zone is considered dominant at 40% ownership (from 25% ownership)
    • Tactical move priority randomness range is now 3 (from 6); homeland tactical move priority randomness range is now 5 (from 10)
    • Max turns to move for homeland defense is now 3 (from 4). This doesn't stop the AI from defending its homeland, but instead forces it to use units that don't have to travel as far.
    • Diplomatic weights for Weak/Strong/Fierce land disputes are now 1/3/9 (from 1/3/5)
    • Danger values for diplomatic approaches have been altered as follows: Deceptive is 0.4 (from 0.1), Hostile is 0.8 (from 0.2), Bully is 0.8 (from 0.9)
    • When spreading religion, unowned plots are multiplied by 4 (from 3), owned plots are multiplied by 6 (from 5), and worked plots are multiplied by 6 (from 8)
    • Missionaries will be sent to destinations up to 8 turns away (from 10 turns)
    • Annexation thresholds set to 0.4 for normal (from 0.5) and 0.8 for aggressive (from 0.75)
    • Ideology value based on Hostile/Guarded/Afraid/Friendly approaches to players already running the ideology is -20/-10/10/20 (from -8/-4/6/12)
    • Ideology value based on Happiness set to 5 (from 3)
    • Ideology value bonus for each free tenet set to 40 (from 36)
    • Ideology value based on Grand Strategies set to 400 (from 300)
    • Diplomatic Opinion modifier based on no/weak/strong/fierce land disputes set to -1/5/25/125 (from -6/10/20/30)
    • Diplomatic Opinion modifier based on no/weak/strong/fierce victory disputes set to -1/5/25/125 (from -6/10/20/30)
    • Diplomatic Opinion modifier based on no/weak/strong/fierce wonder disputes set to -1/5/10/20 (from 0/10/15/20)
    • Diplomatic Opinion modifier based on no/weak/strong/fierce minor civ disputes set to -1/4/16/64 (from 0/10/20/30)
    • Opinion Threshold to possibly declare war if current Grand Strategy is Conquest set to 10 (from 50)
    • War evaluation if not prepared set to -150 (from -100)
    • War evaluation for game threats none/minor/major/severe/critical set to 10/25/75/150/300 (from 0/20/50/100/150)
    • War evaluation based on soft/favorable/average/bad/impossible target set to 200/100/-25/-150/-300 (from 100/50/-25/-100/-200)
    • Thresholds for observations of aggressiveness levels low/medium/high/incredibly set to 5/15/25/35 (from 10/25/50/80)
    • Military and Economic strength ratio multipliers for diplomatic/war evaluation set to 125 and 110 respectively (from 100 each)
    • Barbarian "Capture City" tactical move's priority is now 11 (from 9, placing it above Blockade Resource, Attrition, and Move to Safety for barbarians)
    • "Move to Safety" tactical move's priority is now 20 (from 11, placing it above Pillage Resource, Attrition, and Damage City)
    • "Damage City" tactical move's priority is now 11 (from 15, making it possibly exchangeable with Heal and Low Priority Attrition once randomness factor is taken acount)
    • "Heal" tactical move's priority is now 10 (from 8, placing it above Park on Trade Route and equal to Low Priority Attrition)
    • "Low Priority Attrition" tactical move's priority is now 11 (from 12)
    • "Barbarian Camp" tactical move's priority is now 13 (from 11)
    • "Reposition" tactical move's priority is now 2 (from 1)
    • Base war preference against City States when running a Conquest Grand Strategy is now 5 (from 8), but 20 when they're also neighbors (from 10)
    • War preference against City States who are neighbors is now 2 (from 1)
    • War preference against City States based on Impossible/Bad/Average/Favorable/Soft target is now 0/10/50/100/150 (from 10/20/40/110/130)
    • "Area is full" threshold is now at 80% tile ownership (from 50%)
    • 19 empty tiles are required for the early expansion strategy now (from 25 tiles)
    • Units executing the following tactical moves can now be recruited into operations: Pillage, Safe Bombard, Bastion, Garrison, Guard Improvement

    Any (detailed) gameplay feedback is appreciated, both in terms of existing AI flaws that are unaddressed/worsened by my mod and new AI flaws that are introduced by my mod. Plus I'm curious how well my AI changes hold up against more seasoned players, seeing as I only ever play on Prince or King (I dislike playing against cheating AIs) and I'm forced to run my AI-only test games on Prince.

    I haven't bothered porting my changes to older DLL versions, so the mod is BNW-only for now.
     
  2. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Reserved (I think this is how it works?).
     
  3. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,063
    Location:
    America
    Moderator Action: Moved to the Civ 5 Mod Components forum.

    Very Interesting! I'm quite curious to see what you changed and your rationale for it. AI modding is very challenging, even for civ 4 there were only a couple very talented programmers who were willing to try it. Did you manage your DLL source changes using Whoward's method?
     
  4. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    No, I didn't manage my source changes using WHoward's method. What exactly is the method?

    Most of my changes are actually fairly minor tweaks that add up to substantial differences: things like changing the types of a lot of internal variables to float or double (from int) to minimize loss of information on division operations, checking for more booleans in certain scenarios (eg. worker automation for Celt AIs no longer completely ignores forests once they are in the Industrial Era), adding additional weight multipliers that vary logistically, logarithmically, sinusoidally, and/or exponentially (pretty much everything except linearly) w.r.t. data points like turns remaining and current era, the aforementioned binomial distribution random number generator being used for flavor randomizers, etc.
    This is primarily because I've yet to completely map out all AI functions, so with the exception of clearly visible tweaks (eg. choosing beliefs for religions), I've tried to make it so that my modified functions/systems give back similar values as the unmodified functions, albeit through more nuanced algorithms powering the output.

    [Un]fortunately, I've noticed that a lot of the systems powering the AI are simple but expansive, not necessarily complicated. Outside of possibly the unit management code (ie. parts of CvUnit, CvTacticalAI, and CvHomelandAI), nothing I've seen has been particularly esoteric, the code's just, well... big (and bloated). You don't necessarily need to be a talented programmer to try your hand at improving the AI (eg. I'm no programming expert by any stretch of the imagination), you just need to be patient.
     
  5. Nutty

    Nutty Chieftain

    Joined:
    Mar 9, 2011
    Messages:
    3,153
    Gender:
    Male
    Location:
    Orange County, California, U.S.A.
  6. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Ah, I understand. Thing is 99% of my modifications are functional changes rather than value changes, so it seems pointless to have all my changes embedded in preprocessor directives. Please enlighten me if you think I'm wrong however.

    For example, consider my changes to the logic behind scoring for the Scholars in Residence UN proposal. Here's the old one:
    Code:
    if (pProposal->GetEffects()->iMemberDiscoveredTechMod != 0)
    {
    	float fTechRatio = GetPlayer()->GetPlayerTechs()->GetTechAI()->GetTechRatio();
    	fTechRatio = (fTechRatio - 0.5f) * 2.0f; // -1.0 if in first, 1.0 if in last
    	
    	// We are better than average
    	if (fTechRatio < 0.0f)
    	{
    		int iFactor = 30;
    		iScore += (int) (fTechRatio * iFactor);
    		if (bSeekingScienceVictory)
    		{
    			iScore += -30;
    		}
    	}
    	// At or worse than average
    	else
    	{
    		int iFactor = 50;
    		iScore += (int) (fTechRatio * iFactor);
    		if (bSeekingScienceVictory)
    		{
    			iScore += 40;
    		}
    	}
    }
    Here's my modified one:
    Code:
    if (pProposal->GetEffects()->iMemberDiscoveredTechMod != 0)
    {
    	float fTechRatio = GetPlayer()->GetPlayerTechs()->GetTechAI()->GetTechRatio();
    	fTechRatio = (fTechRatio - 0.5f) * 2.0f; // -1.0 if in first, 1.0 if in last
    
    	// if AIs are behind in tech compared to planned progress, score gets boosted so future techs get researched faster
    	fTechRatio += -2.0f / 3.0f * logf((float)(GET_TEAM(m_pPlayer->getTeam()).GetTeamTechs()->GetNumTechsKnown() * GC.getGame().getMaxTurns()) / 
    		(float)(m_pPlayer->GetPlayerTechs()->GetTechs()->GetNumTechs() * GC.getGame().getElapsedGameTurns()));
    	// if congress is not the UN, add in extra score based on AI's plan for diplomatic victory
    	if (!GC.getGame().GetGameLeagues()->GetActiveLeague()->IsUnitedNations())
    	{
    		fTechRatio += 0.5f * MAX(0.0f, fDiploVictoryRatio - sqrtf(fConquestVictoryRatio * fScienceVictoryRatio));
    	}
    
    	// Score difference is -30 at -1.0 tech ratio, 50 at 1.0 tech ratio; difference between vanilla is that it is now exponential instead of linear
    	float fFactor = 30.0f * sqrtf(5.0 / 3.0) * powf(sqrtf(5.0 / 3.0), fTechRatio) * (1.0f + fScienceVictoryRatio);
    	fScore += fTechRatio * fFactor;
    }
    Messiness and possibly pointless (float) castings aside, everything after the first four lines is different from the original logic. Also notice that iScore has become fScore, since I changed its type from int to float (and I also had to change every line that interacts with it as a result, since (int) casting and rounding is no longer required). Embedding everything in preprocessor directives would be a much larger headache than it's worth; I'd basically need to wrap every mention of iScore and fScore into its own #if...#else...#endif shell, not to mention my blocks of modifications and every single call to new or modified functions. There would be so many directives strewn throughout the code that it would be at least twice as unreadable as it is now.

    Even my "minor" tweaks actually affect multiple lines of code: a simple type change of a variable from an int to a float means I have to change almost every single line that modifies the variable's value to make sure information is retained (eg. removing (int) casts, casting dividing ints as floats). To comply with WHoward's method, I'd need to place all of those lines inside their own directive shells; when we're talking about 200+ lines or so (eg. CvUnit's promotion scoring calls iScore and iTemp pretty much every other line), things would get unwieldy really fast.
     
  7. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,063
    Location:
    America
    In that case you probably could just wrap the whole body of the function in a large #if #else #endif directive. The main reason this is done is to make it extremely easy to roll back any changes for whatever reason, and to easily test any combination of changes in isolation (just change the file which controls which preprocessor directives are enabled).

    It also makes the code work nicely with other people's code in source control systems. Theoretically if you do it entirely correctly you should be able to do a git merge with anyone else's code which properly uses the preprocessor directive system without any conflicts whatsoever.
     
  8. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Spread-out changes like altering variable type would still be a problem (since they're called and modified all throughout the function, I'd basically have to put the entire function in an #if...#else...#endif directive, putting a damper on automated merging and troubleshooting ease), but otherwise I see your point.
    Between refactoring/restructuring to use preprocessor directives, commenting my code a lot more, learning how to use GitHub as a developer, and playing bug whack-a-mole, looks like I've got plenty of work ahead of me...
     
  9. ls612

    ls612 Deity Moderator

    Joined:
    Mar 10, 2008
    Messages:
    8,063
    Location:
    America
    Yeah. It isn't like it is required to do any of this stuff, but the main DLL modders in the community all work together using this system so if you want to work with them on new features/feature sharing you will also probably need to use the same system.
     
  10. ilteroi

    ilteroi Chieftain

    Joined:
    Mar 11, 2006
    Messages:
    300
    hi, would you mind putting your dll source on github? i've been looking into some ai improvements for the community patch project, and i'd like to see what you did and if it can be merged ...
     
  11. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    I'll try to get something uploaded to GitHub once I publish v6 (v5 turned out to be riddled with holes I hadn't found because I wasn't varying my test game setups enough), but it probably won't be of much use to you until I go back and comment all of my changes (not just the funky ones) and wrap some of them in preprocessor directives. Plus, as mentioned before, quite a few of my changes are spread out, so you'll have to either merge them manually or not at all.
     
  12. ilteroi

    ilteroi Chieftain

    Joined:
    Mar 11, 2006
    Messages:
    300
    #ifdef in or out, if you can help it, please don't make it just one big commit - having several smaller changesets makes it much easier to see what's happening
     
  13. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Right, now that I've got v6 published, which should hopefully fix most of v5's bugs, I'll start organizing my code and try to get something uploaded to GitHub. I've never used a version control system before, so expect the worst.
     
  14. S3rgeus

    S3rgeus Chieftain

    Joined:
    Apr 10, 2011
    Messages:
    1,270
    Location:
    London, United Kingdom
    This looks very interesting! I'll be diving deep on the AI for a mod I'm working on now and it would be great to see what kinds of changes you've made to achieve these effects. :D Out of curiosity, what was the specific reason to switch the random number generation for the AI? How did it change the AI's behavior?
     
  15. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    I didn't switch the random number generator for all functions, just ones that had personality-altering effects.

    The vanilla RNG (random number generator) is a fairly straightforward pseudo-RNG. Now we can talk uniformity and periodicity, but what I was interested in was distribution. Disregarding uniformity, the numbers it generates have a flat distribution; when given a range between 0 and n, all numbers in the range have an equal chance of being spat out.

    The game has a lot of personality-altering functions that use the vanilla RNG to avoid predictability: you don't want all of the AI's starting flavor and personality values to be identical each game. I found the vanilla range on these RNG calls too small, so I initially dialed up the range to fairly high levels. Problem was that while this did result in less predictability, it also resulted in a lot of AIs ending up with extremes: generating a 0 out of [-10;+10] was just as likely as generating a +10.
    The way I got around this was by implementing a second RNG that, while sharing the same seed and seed-altering calls as the original RNG, resulted in a binomial distribution of numbers. For example, if I were to generate a a number between 0 and 4 inclusive using the binomial RNG, I'd have a 1/16 chance of rolling 0 or a 4, but a 6/16 chance of rolling a 2 (vs. 1/5 for all rolls in the flat RNG).
    My binomial RNG has so far given me an excellent balance between being unpredictable enough to result in unique outcomes, but still controllable enough so that extremes are more of a one-off case instead of a regular occurance.

    The implementation is fairly basic: to generate a short between 0 and n inclusive, I have a for loop that runs n cycles, generating a new seed and adding its bit 30 to a temporary short variable (bit 30 ensures high periodicity, eg. bit 0 would create a pattern that repeats every 2 generations). Once the loop is finished, the temporary short variable is outputted. This is essentially like flipping a coin n number of times and outputting the number of heads you get.
    With a low n, my binomial RNG runs equally fast as (sometimes faster than) the game's flat RNG, since I don't have any division operations and only one multiplication operation (to generate a new seed). With a high n though, running my binomial RNG starts becoming quite computationally expensive, since I need to run a multiplication step n times. Though I could optimize for higher n by checking bit 29, bit 28, etc. of the seed before generating a new one, it would skew the RNG's distribution more and more depending on how far down I go, and that's not something I really want to do.

    Moderator Action: Merged double post
    Sorry for the double post, but I added the mod's GitHub repository to the first post. Most of the files are still unmodded ones, and I'll slowly commit my modified functions as I clean them up. As of now, the only modified files contain functions that I originally implemented to help my AI functions, but they can be used for pretty much anything (eg. my binomial RNG and being able to cache double-type variables from XML).
     
  16. Gazebo

    Gazebo Lord of the Community Patch

    Joined:
    Sep 26, 2010
    Messages:
    17,244
    Gender:
    Male
    Location:
    Little Rock
    I look forward to where this goes. As an added means of managing dll mods, you might consider building your dll based off of the Community Patch Project's DLL, as it'll give you the structure you need for preprocessors, and it'll show you what we've already done. Good luck! You can find it on github: https://github.com/LoneGazebo/Community-Patch-DLL
    G
     
  17. merill

    merill Chieftain

    Joined:
    May 15, 2010
    Messages:
    433
    Location:
    France
    hi

    i didn't test it yet, but i have a question:
    Actually, one of my concern with the AI is his fleeing tendency. Setting this parameter to 20 doesn't make the AI a real coward?

    Pillage can be a safety measure to heal when on fire under a city. This behavior is still active?

    The problem of "Move to (not really) Safety in water tile" no longer occurs?
     
  18. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Not really. The AI handles tactical moves in an odd manner: instead of selecting individual units/armies and handing out orders for each one, it scrolls down a list of orders and finds out which units/armies with moves remaining are eligible to execute that order. Setting the "Move to Safety" move to a higher priority doesn't make units more likely to flee, it simply makes the AI scroll to the "Move to Safety" move before it considers moves like "Heal" or "Low Priority Attrition".

    The AI will still pillage resources; the priority changes simply mean that if the AI can/wants to attack an enemy with a unit, but can also pillage with that same unit, it will attack instead of pillaging.

    I don't think it should. The reason this happened is because the AI did not take ranged units and cities into account in its Tactical Analysis code. As a result, it marked certain water tiles as "safe" even though said tiles were within city range or move + ranged attack distance. I've fixed this in my code (I haven't uploaded my Tactical Analysis stuff to GitHub yet though), and I don't think I've seen it happen all that much in my test games (there are certain moves where the AI doesn't check the Tactical Analysis map, such as when reorganizing forces around a muster point).
     
  19. merill

    merill Chieftain

    Joined:
    May 15, 2010
    Messages:
    433
    Location:
    France
    Thank for the details.

    I can't see the Ninakoru's Smart AI (v2) changes in your github code, i think it's not already push.
    I'm glad you bother to push a good-looking code. Can't wait to see all your changes.
     
  20. Delnar_Ersike

    Delnar_Ersike Chieftain

    Joined:
    Jan 1, 2007
    Messages:
    497
    Location:
    localhost
    Yeah, I don't think any of my commits contain code that I either lifted from Ninakoru's work or wrote inspired by Ninakoru's changes. Thing is, based on what people have been telling me in the Workshop comments, Ninakoru's code isn't exactly flawless, and I'm probably going to revisit it before I push any of the altered files to my GitHub page.

    Speaking of revisiting changes, the reason GitHub commits have slowed down a bit is because after an effort to clean up the culture Grand Strategy priority code, I finally had it with Firaxis' code, so I'm rewriting all Grand Strategy priority algorithms from scratch. Since I want to work with Victory ETA's (ie. how quickly can the AI win a certain victory type), it's a bit of a pain trying to account for everything. Naturally this has slowed my work in getting my other modifications pushed to GitHub. The end result should hopefully be 1) more AI space victories, 2) less cases where the AI gets "locked into" a culture Grand Strategy after getting influential with the two weakest players in the game, and 3) AIs that are more adaptable when selecting Grand Strategies, switching gears much more seamlessly and choosing the ideal goal even if their flavor dictates that they shouldn't.
     

Share This Page