Hot posts in thread: AI coding overview

  1. gja102

    gja102 Cadet

    Posts:
    26
    Joined:
    Oct 27, 2016
    Thanks Adam, glad to see you "get" it in regards to the difficulty curve. It's quite telling that one of the earliest user mods for Civ 6 is called "Smoother Difficulty" (to quote the creator - I didn't like that the AI got insane bonuses at the start, which meant the #1 way to lose a game was to just get DoW'd in ancient or classical and get killed by more units than you could possibly handle. This mod smooths the difficulty curve of the AI, so now they have about the same start you do, but get better constant bonuses so they can keep up with tech and production throughout the entire game.) So the lop-sided cheating is clearly an issue across the 4x genre.

    The ideal end result is an AI that feels like the same kind of challenge as a competent player would. I wonder if it would be possible to create some kind of save game analysis tool, that measures the amount of infrastructure, colonies, and military that a player has at each point of the game - and use that information to structure the AI cheats. So a top level AI would be getting handouts to put it on a par with a top level player, etc etc.

    Although handouts work well for shoring up strategic AI, I can't see an elegant approach to boosting the tactical battle AI in such a straightforward way. That's one area where you might need to consider *slight* but brazen AI cheating in terms of to-hit bonuses, etc. Because although it can be frustrating to face "superhuman" opponents, it's probably preferable to having situations where an outgunned human can effortlessly carve through waves of AI ships.
     
  2. Konstantine

    Konstantine Grand Admiral

    Posts:
    2,200
    Joined:
    Oct 19, 2016
    There is another way to handle this.
    Granted the work, focus and resources available in creating the AI is key but you can create a great game even if your AI is only competent at best.
    Events.
    If used correctly, events (randomized but with predetermined triggers) could easily assist the AI in creating a satisfying game experience for the player. The trick is balance as in all things. No event should cause rage quit but should present the occasional un-planed for challenge that will throw some good obstacles at the player.
    Barring a full 4x campaign, a number of events (from minor to major) can allow the developers to create a sandbox 4x that cannot be easily beaten as the player will have to react at times to threats that were not anticipated.
    The idea is to level the playing field as needed, not make it impossible to win.
     
  3. IvanK

    IvanK Lieutenant

    Posts:
    138
    Joined:
    Oct 17, 2016
    That's how I do it in my pet project :). The code is divided in two major C# projects: game core and user interface. Core has all of the business logic of the game and interface for interacting with it, it's basically model and controller from MVC pattern. User interface is view part of that pattern. So is the AI plugin project, it too "sees" the game through same controllers as human's UI. The difference between the two is that AI assembly is much thinner, with only AI's game playing logic while user interface project has to cover all the administrative stuff like settings, loading plugins, starting game, saving, loading, etc.

    It's not so difficult to do IF you divide the code like in MVC pattern and you can leverage all the goodness about C# (great IDE, powerful strictly typed language which won't blow up on syntax errors during runtime). Unfortunately Unity3D likes to tempt developers to put game logic on the display objects and discourages the usage of namespaces which may challenge disciplined code architecture.
     
    Last edited: Oct 28, 2016
    • Agree Agree x 1
  4. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    I have a lot less sympathy for huge developers, like Firaxis, which have the resources to employ a team of AI experts to devote man-years to the task, yet deliver AI which has hardly advanced since Civ 1.

    Other genres, for what ever reason, seem to make a lot more effort to keep up to date with research and treat the AI as something important. In the RTS genre, there has been definite improvements to pathing, due to developers actually bothering to read up on research work. And not just utilising improved pathing algorithms, but even exploring more experimental approaches such as gestalt behaviour and flocking.

    It seems to me that the 4X developer community, on the other hand, are happy to stay in the dark ages with regards AI.

    Please note again, that this criticism applies to so-called triple A developers, who have the resources to at least make an effort.
     
  5. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    OK. I was thinking more along the lines of, say for example, a user written dll, which would interact with the game via some well defined interface. This would enable users to experiment with arbitrary AI methodologies and, if they achieve good results, provide these back to the community. Anyway, looks like the answer to my question is a no. Which is fair enough!
     
    • Agree Agree x 1
  6. aReclusiveMind

    aReclusiveMind Developer Grand Admiral

    Posts:
    3,040
    Joined:
    Sep 24, 2016
    I don't envy 4X developers when it comes to creating a balanced AI. This is a task even the best in the business still struggle with in the eyes of the players. It seems likely nearly every other genre gets off a bit easier in this regard. Hopefully we can all play a part in making suggestions and in letting our voice be heard during the pre-release period to assist with plugging the holes we find in the AI.
     
  7. dayrinni

    dayrinni Ensign

    Posts:
    45
    Joined:
    Oct 14, 2016
    FYI, Paradox Games usually expose some of their AI via LUA. May be something to consider :)
     
  8. Adam Solo

    Adam Solo Developer Administrator Grand Admiral

    Posts:
    4,847
    Joined:
    Sep 9, 2016
    No, that's not envisaged right now. However, we'll see if there are parts of the AI that we can expose via XML files that could be tweaked to influence the AI behavior. We'll figure that out as we go.
     
    Last edited: Oct 27, 2016
  9. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    Fair point. One question. Have you considered providing support for users to create their own AI modules for the game? I assume the design is quite modular and the AI modules will interact with the game via some defined interface, so you wouldn't need to expose too much of the games internal workings. Of course, I fully understand if you wouldn't want to allow this.
     
  10. Adam Solo

    Adam Solo Developer Administrator Grand Admiral

    Posts:
    4,847
    Joined:
    Sep 9, 2016
    I see what you mean, but it's tricky, because they are playable races. As you say, this would work easily with NPC races, but that's not the direction that we're taking here.

    However, it's still a helpful thought on how one could disperse bonuses throughout the game, giving little spikes of advantage, instead of giving a constant +X% to Research since turn 1.
     
  11. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    The trouble is that slight bonuses aren't enough and massive bonuses distort the gameplay.

    One way you could stagger the bonuses to different times in the game, is having the AI have access to certain technologies not available to the player. These could be scattered across the tech tree. Different species can have different special technologies, increasing the diversity of the challenge. This probably fits in more cleanly with NPC species, since human player will be peeved if he/she doesn't get same technologies when picking that species.
     
  12. Adam Solo

    Adam Solo Developer Administrator Grand Admiral

    Posts:
    4,847
    Joined:
    Sep 9, 2016
    Hi @gja102, welcome to the forums.

    I agree with a lot of what you said. I also think the big problem we have with the AI sometimes is not so much with the AI cheating per se (although it would be nice if didn't had to), but when we see it do obvious things that are either: very weird, obviously hardwired (e.g. gang up on the human) or simply absurd (e.g. when the AI asks you to stop doing something, that you obviously aren't doing).

    So, it should feel like it's competing, I agree. And, if the AIs cheat, there should be only slight bonuses given to them (or through other more sophisticated means), and not simply insane bonuses that will distort the experience at the higher difficulty levels. That's why I never found playing Deity in Civ games an interesting challenge, given the ridiculous amounts of bonuses the AI gets.

    Your idea for giving boosts to the AIs not in the early game, but only at mid game is also interesting.
     
  13. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    MOO2 was a great game, but it was simply too easy, even on hardest skill level, for a competent human player in single player mode. Since this game will be single player only, MOO2 is not a great model to follow for the level of challenge.

    Subtle cheats just won't cut it. Without some major improvements in the quality of the AI (compared with every other 4X I've ever played), the AI needs massive cheats to provide a challenge.

    There is a point at which the magnitude of the cheats you need to give the AI to compete becomes so great, that you may be better off designing separate mechanics for the AI, which can then be balanced to provide a interesting challenge to the player.

    Improving the AI is, of course, the better solution. And, as I have posted in this thread, there are techniques that could be applied, even by non-experts without huge resources, to work towards this aim. However, if the AI cannot be improved beyond what is seen in the typical 4X, then another approach is needed to provide a long term challenge. The AI playing by different mechanics is just a suggestion. I fully accept it may not work out in practice.

    I don't know about other posters here, but for me, the typical 4X experience is enjoyable whilst I am learning the systems, then becomes boring beating up the AI once I understand them. Thus, with the exception of a period where I played MOO2 multiplayer, every 4X gets abandoned. Beating up on an AI that can't challenge me is simply not fun.
     
  14. gja102

    gja102 Cadet

    Posts:
    26
    Joined:
    Oct 27, 2016
    This approach is clever, but it wouldn't feel very "MOO2". Of course there were the Antatans, which did act as a challenge in the way you describe, but the 'main' game was very much about broadly equivalent spacefaring races in the style of Star Trek etc.

    Higher difficulty MOO2 did in fact give the AI aliens bonuses to growth, production, etc. The amusing thing was that these bonuses were tied to their populations, so when playing at high level, you could enslave a bunch of AI-enhanced Silicoid workers, and end up with a more productive worker base than you could ever have on standard difficulty. Which took the sting out of the 'cheating AI' feeling.

    My two cents is that the AI should 'feel' like a competing player - with as many subtle cheats as it takes to get it to that point. When people complain about AI cheating, it is usually triggered by things that make it OBVIOUS that it is playing by different rules. For example, many 4X games decide that higher difficulty should mean the AI automatically hates the player more, which makes a diplomatic playstyle impossible. Or they give the AI dramatic production bonuses, which in theory would be fine, but they don't scale well with the early game, which means it is physically impossible for the player not to get outproduced at the start.

    If you're clever about AI cheating, using it to boost the AI to player level rather than giving it a different ruleset entirely, and giving it mid-game boosts rather than early-game ones, it should work fine.
     
    • Agree Agree x 1
  15. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    For sure, we are a long way from an AI than can match a human at a complex game, such as a 4X. Your analogy with hot air balloons may be fair, but if that is the current state of AI, then I would counter that most game developers are still attaching feathers to their arms and flapping them up and down.

    I am all for having some aggressive factions (although not all factions as that would spoil the immersion for me). Too many 4X games are way too easy because you can just fast expand early and the AI just lets you get away with it.
     
  16. Konstantine

    Konstantine Grand Admiral

    Posts:
    2,200
    Joined:
    Oct 19, 2016
    Greetings Neil
    Yes, I have heard of these developments and it is quite exciting. I am no expert on AI but it seems that this is akin to what hot air balloons were to early flight. In other words a beginning that is still quite a long way from being adequate for the subject at hand. In either case I have faith that a great game can be made with todays technology as long as the work is put in, Another option that would help the game overall is to program AI factions in an aggressive manner so that the player would be forced to respond to the AI to a greater degree. This would need to be carefully balanced however so that the player still feels like he/she is playing the game rather than the other way around.
     
  17. Neil

    Neil Ensign

    Posts:
    30
    Joined:
    Oct 20, 2016
    I think there is a very good chance you are right!

    As I alluded to before, this is something where simpler AI techniques could be applied without the need for huge processing power or expertise. Bayesian based approaches are easy to implement and have many advantages over bunches of it-then-elses :-
    • All information is combined under a probabilistic framework.
    • It won't become unwieldy as the number of features you are basing you decisions on increases.
    • New decision features can be added easily.
    • Prior information can be added to bias decisions easily.
     
  18. IvanK

    IvanK Lieutenant

    Posts:
    138
    Joined:
    Oct 17, 2016
    Probably bunch of if-then-elses :D
     
  19. rxnnxs

    rxnnxs Ensign

    Posts:
    120
    Joined:
    Oct 15, 2016
    That sounds interesting.

    Besides that, I really would like to know, how the AI was designed for the older MoO Series and, to a greater extend, other X4 Games.
    Pathfinding is not a problem :)
    But, what makes the differenc ebetween lets say MoO and Space Empires?
    SEV needs soo long to calculate, MoO is done in no time.
     
  20. IvanK

    IvanK Lieutenant

    Posts:
    138
    Joined:
    Oct 17, 2016
    Calm down boys! :)

    Rxnnxs, Neil knows what he is talking about but doesn't articulate it in a most layman friendly way. Thing is faster processing doesn't help much because small changes in problem size result in steep jump in how much stuff needs to be processed. For example let's say you have checkers playing AI and it takes 1 millisecond to decide a move on normal 8x8 board. If you increase the board size the processing time doesn't increase by 12.5% but by factor of 10. This means that 11x11 board takes whole second to process while 15x15 takes half a day. Using twice as fast processor and making AI multithreaded to use all available cores might reduce 15x15 board to less then an hour but 16x16 will still be unplayable. So it's more practical to use processing power smarter. In your post you assume that plugging neural network is trivial while in fact it's the crux of the problem. As Neil said there are multiple ANN (artificial neural network) implementations around, in my experience for every popular programming language there is at least one free ANN library.
     
    • Agree Agree x 1