Advertisement
Sorceress

7dRTS - Some AI Methods

Jul 11th, 2013
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. ---------------------------------------------------------------
  2. - 7dRTS
  3. - Here are a couple of different approaches to writing a
  4. - real-time AI. You may find some of these techniques
  5. - useful when writing your 7dRTS game.
  6. -
  7. - http://is.gd/7dayRTS
  8. - sorceress / @_sorceress
  9. ---------------------------------------------------------------
  10.  
  11.  
  12. Basic Subroutine
  13. -----------------
  14. - Create a timer, and every few milliseconds (maybe 500ms) you run your AI script.
  15.  
  16.  
  17. Heuristic based script
  18. -----------------------
  19. Consider lots of possible actions, and give each of them a score which roughly estimates how effective the action might be. You pick the highest scoring action and go with that. This can be surprisingly effective. The more actions you consider the more thorough the AI will be. However, it may be impractical to consider ALL possible actions, in which case consider a random selection, or a handpicked selection, or handpicked+random.
  20.  
  21. To determine the score of any particular action you add together various weights. Here is an example:
  22.  
  23. Consider an action to attack a nearby region.
  24.  
  25. If the opponent has no presence in that region: score = score - 100 // pointless attacking it
  26. If the opponent has 2 or more units than us nearby: score = score - 10 // we are at a disadvantage
  27. If the opponent has defensive structures in that region: score = score - 10 // could be suicidal
  28. If the opponent has 2 or less units than us nearby: score = score + 10 // we have the advantage
  29. If the opponent has 10 or less units than us nearby: score = score + 15 // we have a great advantage
  30. If we have siege weapons nearby: score = score + 5 // siege weapons are effective in attacks
  31. if we have some defensive structures in that region: score = score + 10 // we got cover
  32. if the region contains our own structures: score = score + 15 // important to defend our own structures
  33. etc
  34.  
  35.  
  36. Priority based script
  37. ----------------------
  38. Define a prioritised list of objectives. Each time you run this script, you go through the list and determine if each objective is satisfied (true or false). The first objective that returns false is your immediate priority, and is what you should do as soon as you have sufficient resources. Objectives lower down the list are not considered until all higher objectives are fulfilled.
  39.  
  40. This is useful for defining build orders: determining what to construct, when to expand, when to train units and what units to train. Although the script is predictable (the worst mistake in strategy) and maladaptive, it is deemed good enough for many commercial RTS games.
  41.  
  42.  
  43. Conditional Lists
  44. ------------------
  45. Consider our priority based script, and adding if() blocks to it, so that some parts of the list are considered only in certain circumstances, (eg, if we are under attack; if we are at tier 3; if our opponent has expanded; or if our opponent is massing a particular kind of unit.) This allows our AI to react with an 'expert system' type of approach.
  46.  
  47. Also we can have two or more lists that can be executed in parallel: One may deal with spending resources; the other may optimise resource gathering units.
  48.  
  49.  
  50. Macro theory
  51. -------------
  52. In RTS games, you have two main areas to think about: Macro- and Micro- management. Macro is about the health of your Economy, the composition of your Forces, and your broadest decisions (such as deciding when to attack or construct things). Macro theory revolves around the trichotomy of Produce, Expand, and Upgrade.
  53.  
  54. Production is the training of units which are able to do damage. Expanding is an investment which promises increased economy later in the game. Upgrades are an investment which may be offensive or defensive in nature: eg, advancing through the tech tree and moving to higher tier, creating defensive structures, developing counters, or boosting damage and hitpoints of individual units.
  55.  
  56. Crucially to Macro, these form a non-transitive set, such that there is no absolute best strategy.
  57.  
  58. - Production is stronger than Expansion... A player who expands has spent less resources on producing units, so is at an immediate disadvantage compared with a player who has focused on producing units, who should therefore consider launching an attack.
  59.  
  60. - Expansion is stronger than Upgrades... Both expansion and upgrades are investments, because you don't get immediate returns from the resources spent. But a player who is expanding is developing a stronger economy, and will be able to outproduce their opponent later in the game. Upgrades are not so powerful that they outperform double production.
  61.  
  62. - Uprades are stronger than Production... A player who is spending resources on producing units is not upgrading, so is less able to develop counters. By upgrading you are able to develop counters and give yourself an advantage against that player. Upgrades are often persistent also, so as an investment it can be a single expense with eternal benefits.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement