Search Unity

AI pattern for supply chain management?

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Mar 17, 2019.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm working on an AI for an old-school 4x game in the style of Caesar III, currently it uses a really coarse utility AI which assigns every building a relative value in terms of its usefulness for Economy, Military, Politics, and so forth. That works well to set high-level strategic priorities, but I'm having a lot of trouble coming up with a more granular system to actually determine build orders. Most valuable structures require a several-step deep supply chain: Wineries make a lot of money (because they produce wine to sell), but wineries require grapes, grapes require a vineyard, and the vineyard might require water, labor, and some third intangible, none of which have much value on their own.

    Thus far the best approach I've found is to simply brute-force iterate through every buildable structure for n steps, checking what new structures can be built with each iteration, and assigning a total value to each possible route based on the cost of each component building and the total revenue produced by the final chain. That works, but it's really ugly- the search space is necessarily huge, since I have to test-build every building type against every other type, and 95% of the computational effort immediately goes to waste.

    So is there an established pattern I should be looking up that does this more elegantly? Or is the brute force approach my best chance at getting reasonably fun behavior from a simple system?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    It sounds like you just need to tweak things to only consider "end goal" target structures and consider anything along the way as necessary for that goal. Instead of considering every possible next step, weigh your current needs as multipliers (poverty = 5.0 wealth multiplier, well defended = 0.25 military multiplier, etc.) against a weighted distance between your current structures and the "final" structure. That should organically build "less wealth generating structures" because they're required for the wealth goal winery, despite them not generating wealth by themselves. Once you've reached the goal, and possibly periodically throughout the chain, adjust your multipliers based on whatever factors you deem appropriate (distance to final step in the chain, immediate needs, etc.)