AI Build Conditions Bug?

Discussion in 'Mod Support' started by bmb, August 17, 2016.

  1. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Tinkering a bit with the AI, trying to pull it back to some more basic builds, I don't seem to understand how the build conditions are supposed to work. For example, if a test "NeedsXFactory" is used, it never seems to build any of that factory. The same seems to hold for desire. If desire is the only build condition extractors never get built. Generator desire seem to work, but only slightly. Yet, I am given the impression that need is used by the AI personality to decide how many of a kind of factory to build, with the default preferring vehicle over other types? The only other interpretation for need I can think of is if some kind of planner has decided that it wants to build X unit and that unit comes from X factory, which would then result in a single factory being built. But not even that seems to happen most of the time.

    I guess I also don't understand how multiple build condition objects [],[],[] are supposed to work. It seems that only the first conditions are evaluated. If the need condition is put first, then it never passes. But the default AI files have several, sometimes many build condition objects on a single build. I assumed if one of them passed then it would be built, allowing for different conditions for the same build. But there must be either more to it, or it just doesn't work and can in fact take only one build condition object and sorian just made a mistake here? That seems unlikely, but it could be a bug.
  2. Quitch

    Quitch Post Master General

    Messages:
    5,850
    Likes Received:
    6,045
    Firstly, let me check whether you've read my guide on building an AI?

    Needs are tied into the percentage distributions in the AI personality file. If it wants 20% bots and 80% vehicles and it has one of each then the vehicle factory need is true while bot need is false. When all factories are 0 then it will start with the factory with the highest percentage, so if you've pared it down to bots only then it won't work using these tests because vehicles have the highest percentage. I never used these tests myself so this is based on what Sorian said about them. Make sure you're using valid tests.

    Desire is true when a CanAffordBuildDemand check failed. It sets it true for the resource type it couldn't afford.

    The AI works through each block in the order you put the tests, and if one test returns FALSE then it moves to the next block. You should put the cheap tests at the top (boolean) and expensive tests at the bottom (finding build location). If all tests in a block return TRUE then the item is built.
  3. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Yes I did indeed read it, very informative. My problem is that a test like
    Code:
    [
    	{
    		"test_type" : "NeedBasicVehicleFactory",
    		"boolean" : true
    	},
    	{
    		"test_type" : "CanFindPlaceToBuild",
    		"string0" : "BasicVehicleFactory"
    	}
    ]
    
    results in exactly zero of that factory being built, same appears to hold for metal desire, if desire is the only test, very little metal gets built, in the case of the normal AI profile, no metal gets built

    more confusingly, a test like
    Code:
    [
    	{
    		"test_type" : "NeedBasicVehicleFactory",
    		"boolean" : true
    	},
    	{
    		"test_type" : "CanFindPlaceToBuild",
    		"string0" : "BasicVehicleFactory"
    	}
    ],
    [
    	{
    		"test_type" : "UnableToExpand",
    		"boolean" : false
    	},
    	{
    		"test_type" : "AloneOnPlanet",
    		"boolean" : false
    	},
    	{
    		"test_type" : "CanDeployLandFromBase",
    		"boolean" : true
    	},
    	{
    		"test_type" : "CanAffordPotentialDrain",
    		"string0" : "BasicVehicleFactory"
    	},
    	{
    		"test_type" : "CanFindPlaceToBuild",
    		"string0" : "BasicVehicleFactory"
    	}
    ]
    
    also result in no factories getting built, in other words if the "need" test is first, the second block of tests never gets evaluated, maybe I'm misunderstanding how multiple blocks of tests are supposed to work but this seems like a bug to me
  4. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Okay so I've done some additional tests. And need seems to fire in exactly one condition only, when there are no other factories. So it will build the first factory of the appropriate type and then none others even while it is floating massive amounts of resources. It does seem to fall through properly now so I'm not sure what went wrong earlier. The other case is for advanced factories which seems to fire when there is none of that type of factory, where for the basic ones it appears to be shared. This is probably not the intended behavior.

    In any case the need test is useless for letting the AI personality distribute the amount of factories right now. Not sure how else to handle it although I saw that queller had some factory specific personalities? I might have a look at how you did that.

    It does explain why the current AI seems oddly air happy, even though the default personality has a very small air weight. And the only reason any factories get built at all in the default profile is because the singular test in each build that tests for need = false.

    Someone should probably tell sorian his thing is broken.
  5. mikeyh

    mikeyh Post Master General

    Messages:
    1,869
    Likes Received:
    1,509
  6. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Thank you for looking into it. I'm also still confused about what the multiple blocks of tests are actually supposed to do. Some enlightenment in that area would be nice too.
  7. Quitch

    Quitch Post Master General

    Messages:
    5,850
    Likes Received:
    6,045
    Which blocks do you mean? The basic framework is:
    • I want to build X
      • Block 1
        • Are all these conditions TRUE? Then build the thing
        • If not then...
      • Block 2
        • Are all these conditions TRUE? Then build the thing
        • If not then...
    • I want to build Y
    And so on.
  8. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Right, I guess I got confused because in the standard files that's usually implemented as several independent builds. So I thought there was something more to the test blocks.

    Are you sure that's a "if not then" and not an "and then"? Is the second block only supposed to be evaluated if the first one fails?
  9. Quitch

    Quitch Post Master General

    Messages:
    5,850
    Likes Received:
    6,045
    They'll be implemented as separate blocks primarily when you want multiple priorities e.g. responding to a threat versus anticipating one, or if you want to change where it's built. Queller has, for example, multiple Umbrella builds at Uber level. It has one for protecting the Commander, one for protecting key installations, one for locking down the planet, etc. All of them have different priorities and placement rules.

    So in this instance the AI will do the thing if:
    • It needs a Basic Vehicle Factory AND can find a place to build it
    OR
    • Isn't able to expand AND isn't alone on the planet AND can deploy land from base AND can afford the drain AND can find a place build it
  10. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Okay. logical or. got it. thanks. Still not sure how that explains the first block seemingly blocking the second when I tested it.
  11. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    I think it's worth bumping to point out that this is still not fixed.
    NeedBasicXFactory and DesireX tests ALWAYS fail.
  12. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Figured out the bug finally. All the need tests are implemented as
    Code:
    {
        "test_type": "NeedX",
        "boolean": true/false
    }
    
    but should be just
    Code:
    {
        "test_type": "NeedX"
    }
    
    I figured it out only because there is only one build in the default AI files that has it the right way, all the rest are wrong. with this a minimal desire and need only ai works.
    DeathByDenim likes this.
  13. Quitch

    Quitch Post Master General

    Messages:
    5,850
    Likes Received:
    6,045
    While there does seem to be an issue with the Need tests for factories, all removing the boolean does is cause the test to be passed every time.
  14. Quitch

    Quitch Post Master General

    Messages:
    5,850
    Likes Received:
    6,045
    Actually, an additional test suggests this *might* be caused by basic_to_advanced_factory_ratio being set to 0.

    EDIT: Yep, that's totally the cause.
    Last edited: June 24, 2018
  15. bmb

    bmb Well-Known Member

    Messages:
    1,497
    Likes Received:
    219
    Shouldn't it pass every time? From what I saw, it still worked to change the composition of factories.

Share This Page