Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------
- - 7dRTS
- - Here are a couple of different approaches to writing a
- - real-time AI. You may find some of these techniques
- - useful when writing your 7dRTS game.
- -
- - http://is.gd/7dayRTS
- - sorceress / @_sorceress
- ---------------------------------------------------------------
- Basic Subroutine
- -----------------
- - Create a timer, and every few milliseconds (maybe 500ms) you run your AI script.
- Heuristic based script
- -----------------------
- 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.
- To determine the score of any particular action you add together various weights. Here is an example:
- Consider an action to attack a nearby region.
- If the opponent has no presence in that region: score = score - 100 // pointless attacking it
- If the opponent has 2 or more units than us nearby: score = score - 10 // we are at a disadvantage
- If the opponent has defensive structures in that region: score = score - 10 // could be suicidal
- If the opponent has 2 or less units than us nearby: score = score + 10 // we have the advantage
- If the opponent has 10 or less units than us nearby: score = score + 15 // we have a great advantage
- If we have siege weapons nearby: score = score + 5 // siege weapons are effective in attacks
- if we have some defensive structures in that region: score = score + 10 // we got cover
- if the region contains our own structures: score = score + 15 // important to defend our own structures
- etc
- Priority based script
- ----------------------
- 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.
- 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.
- Conditional Lists
- ------------------
- 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.
- 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.
- Macro theory
- -------------
- 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.
- 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.
- Crucially to Macro, these form a non-transitive set, such that there is no absolute best strategy.
- - 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.
- - 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.
- - 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