Search Unity

Better decisionmaking for economic AI

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Feb 24, 2019.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm working on building a small-scale 4x game that is very heavy on the economic and expansion elements, and extremely light on the tactical layer. At its core, I'm trying to build the AI into a system that can start with a single unit, and eventually build up an entire network of buildings and units that are collaborating to expand further.

    The basic building blocks seem to be reasonably simple: the top-level AI keeps track of resources (gold/wood/whatever), currently-owned units and structures, and a list of potential tasks that its units can execute. I'm taking a page out of The Sims' book for this, insofar as tasks and their accompanying logic are contained within the objects that own them, and the units/decisionmaking AI simply evaluates each task with a utility function, decides what gets the highest score, and assigns that to an available unit.

    That gets me maybe 70% there, but I'm having a really hard time figuring out how to implement long-term planning. Like, right now every buildable structure gets a score based on what it does, weighted by what I have, so lumberjack huts get a very high score when my wood production is low, and a low score when wood production is higher than other resources. However, the system is incapable of identifying situations where several low-score moves in a row can have a high net benefit, and there are edge cases that are very hard to quantify, like recruiting new units (which is invaluable and super-good when there are enough resources to support the new guys, and terrible when resources are tight).

    So, is there another design pattern I should be researching here? Utility theory and really carefully balanced weighting algorithms kinda work, but they frequently result in weird and counterproductive behavior. Gameplay is asymmetrical (the player is essentially a single character trying to sabotage the AI's economy, not an equivalent empire), so it's critical that the AI's economic growth be purposeful and logical enough that the player can figure out what they're doing and sabotage their efforts tactically ('if I blow up this gold mine, they'll lose the ability to fund all their cool stuff') instead of strategically ('the base is over here, time to build 500 guys and stampede over it').
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Maybe try hybrid approach? For example Utility AI with Behavioural Tree AI.
     
  3. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I've been thinking of using action planning for the actual executional stuff, so the utility AI is essentially responsible for making a strategic decision (build a building, recruit a guy, harvest resources), and either a behavior tree or planner can actually make it happen, but the strategic level still feels a bit half-baked. I think the biggest weakness with the utility approach is that it doesn't do a good job of cost/benefit analysis or long-term planning. It essentially only reads the situation one layer deep.

    I've been looking at other 4x/RTS games to see if they've done anything worth reproducing, but it seems like the vast majority of them are built for symmetrical gameplay, and essentially do away with all the back-end decisionmaking in favor of lots of hardcoded and macroed behavior backstopped by steady resource ticks. That makes sense when most of the gameplay happens in the tactical layer, but since I'm essentially eliminating combat and micromanagement in favor of a logistics and economics-oriented game, it seems worth looking at other options.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    May be a bit far to go that route, but you can always consider machine learning. Like Neural Networks etc.
    But it may be hard to maintain the game, if you do modifications.
     
  5. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Yeah, plus it'd be a lot harder to tune if I ever want to give specific factions particular personalities or strategic leanings. That's actually one thing the utility approach is good for, since it'd just be a matter of weighting each approach differently.