Artificial intelligence

From Unknown Horizons - Wiki
Jump to: navigation, search

This page is part of the Unknown Horizons Design Document. Please discuss everything concerning this topic on the "discussion" tab of this page. If you're not sure whether your ideas are fitting the Unknown Horizons style, either use the related discussion page or ask us. Please don't directly edit the article!

Computer Players in Unknown Horizons

To allow for a better single-player experience, it is important to offer computer players that the human player can play with/against.

Those computer players (AI [Artificial Intelligence] in the following) will have to act as similar as possible as humans playing the game.

For the human player it should feel like he is be playing against other human players and not versus a computer.

For this it is important that the AI acts upon certain goals, which are similar to goals humans set themselves when playing the game.

Requirements for an AI in Unknown Horizons

  • Has to be able to follow certain goals (settle on island, etc)
  • Has to be able to judge goals quality based on the current game state
  • Should be able to solve problems (like not enough building space available)
    • Once a problem is detected, fixing it could be described as a goal and pushed through the same mechanics (problem (no more space) -> goal (find more space)) so problems are necessary for detection but solving could be done simply through (high priority) goals.
    • A goal is a something the AI wants to achieve. When finding out which goal to pick, the AI has to judge the value of all the goals and pick the goal that is best suited for the current world state. A goal is then accomplished by solving a set of Problems. Goal: Build School, Problems: Enough gold, enough wood, enough space, find best place to build, build school).
  • Problem solving is done by creating action plans, these consist of a set of commands that the AI has to execute in order to solve the problem.
  • Has to be able to coordinate multiple action plans at the same time (move ship, build stuff) but:
  • Should "feel" like a human player is playing when watching it act (not 10 actions in one turn etc.)
  • Should be flexible in order to implement different difficulty levels
  • Possibly have subgoals in one goal
    • having some hierarchical abstraction with subgoals is really a key feature if you want to keep the whole thing manageable. Otherwise you'll fail to formulate more advanced goals
  • Problems should be able to depend on other problems, in order to allow dependencies.
  • Problems have to know if they are already solved for the current context
  • Awareness of Plans that won't work any longer e.g. of interaction of other players. So the system will have to check regularly if the plans are still possible to fulfill and re-evaluate if they are not.

  • For »feeling« Human, I consider it useful to give the computer players some kind of personality. The blue player on the map will maybe tend to solve some problem similarly if confronted again while the red player does something entirely different each time.
  • We will use a system like in the newer Anno games witch characters representing AI players.
  • Probably we should transfer the complete AI stuff into a separate "file" and just implement interfaces into the game. This will give interested players the ability to create own AI or modify it.
  • We could create a special language (like the scenario markup) to write those control scripts for the AI. The language should use an intuitive syntax and should be action-based. For example an action could be "run out of wood" and then a few commands what should be done next ("build lumberjack near a forest or plant trees?").

  • OK really hard to do right but would help make the opponents feel real would be to have them interact with the player forming teams and have some common coordination.
    • this could be done by using a different utility function for judging the goals for example. Will not be easy to do though i guess.
      • I guess the easiest step towards such customization would be to use different weights that could just be loaded from some file. Different Algorithms for the calculation are a bit more complex but as python supports the notion of functions as data it should™ be possible. The hard part probably will be to make the different sets of weighting functions roughly comparable in player strength so no option is way superior to another (although one could implement some difficulties this way).

Specific technical requirements

  • Has to work with the game internal tick system
  • Should be threaded to make use of multi core processors and to make sure it does not cause the game to lag when calculating possibilities
    • Some Game AI related books I have lying around here 1 suggest AI had back then an impact of at most 5-7% of computational resources so I'm not sure making that part parallel is really worth the trouble (if you want this IMHO just push the complete AI stuff into one single thread so you at least don't need to have lock between different AI internals).
      • I wanted to go with one thread per AI, not multiple per AI. That would be overkill and make more problems that solve them. But i think using threads is pretty important as the game-play is laggy enough already when building stuff, etc. We don't need extra lags when the AI is calculating it's possibilities.
  • Should use the Command classes to invoke changes on the world, possible derived classes are needed for special AI use
    • If you go for a distinctive AI Thread make that a must, having a single interface to care for all the loking stuff is really beneficial ;)
      • I already added the interface for world data lookup to the UML diagram in Folder.png development/uml/ on the AI branch.

christoph: AI Game Programming Wisdom, Charles River Media IMHO the first part of the series is really worth reading

Personal tools