Essentials Docs Wiki

The Essentials wiki has moved and is now at: Essentials Engine wiki

This wiki will no longer be updated.

READ MORE

Essentials Docs Wiki
(Created page with "This article describes the '''battle AI''' (artificial intelligence). That is, how computer-controlled opponents in battle (both wild Pokémon and enemy trainers) choose whi...")
Tag: Visual edit
 
Maruno (talk | contribs)
mNo edit summary
Line 1: Line 1:
  +
{{for|when the AI is used|Battle round}}
This article describes the '''battle AI''' (artificial intelligence). That is, how computer-controlled opponents in battle (both wild Pokémon and enemy trainers) choose which moves to use and which items to use when. This article assumes the AI is for an enemy trainer, although it applies for wild Pokémon and partner trainers too.
+
This page describes the '''battle AI''' (artificial intelligence). That is, how computer-controlled opponents in battle (both wild Pokémon and enemy/[[Partner trainer|ally]] trainers) choose which moves to use and which items to use when. This page assumes the AI controlling an enemy trainer, although it applies for [[Wild encounters|wild Pokémon]] and [[Partner trainer|partner trainers]] too.
   
 
This is a complicated topic, and unnecessary for most users. Do not attempt to modify the AI unless you have decent scripting knowledge.
 
This is a complicated topic, and unnecessary for most users. Do not attempt to modify the AI unless you have decent scripting knowledge.
   
 
== Levels of AI ==
 
== Levels of AI ==
  +
Better trainers should be cleverer than worse trainers. The way the AI decides how good a trainer is is by looking at how much money the player will receive by defeating them - the more money they give out, the better a trainer they are, and the better their AI is.
 
  +
The basic principle of AI in Essentials is that better trainers should be cleverer than worse trainers. A cleverer AI has access to more information about the battle and is more informed about various effects of moves/abilities/items/other effects.
  +
  +
When [[defining a trainer]] type, one of the properties that can be defined is a skill level. This is usually the same as the trainer type's base money payout. A higher skill level represents a better AI.
  +
  +
By default, there are 5 tiers of AI in Essentials:
  +
  +
* Skill level 0 - Used by wild Pokémon, which have an equal chance of choosing each move they know.
  +
* Skill level 1-31 - Known as <code>PBTrainerAI.minimumSkill</code>. Trainers are assumed to be at least this tier.
  +
* Skill level 32-47 - Known as <code>PBTrainerAI.mediumSkill</code>.
  +
* Skill level 48-99 - Known as <code>PBTrainerAI.highSkill</code>.
  +
* Skill level 100+ - Known as <code>PBTrainerAI.bestSkill</code>.
  +
  +
All trainer types within a given tier will behave exactly the same. The only differences are between different AI tiers, where higher tiers have access to more information and improved calculations.
   
 
== AI overview ==
 
== AI overview ==
The first thing the AI needs to do each turn is decide whether to use an attack, use an item, or switch their Pokémon with another one. This decision starts in the script section '''PokeBattle_Battle''', in the def <code>pbDefaultChooseEnemyCommand</code>.
 
   
 
The first thing the AI needs to do each turn is decide whether to use an attack, use an item, or switch their Pokémon with another one. This decision starts in the [[script section]] '''PokeBattle_Battle''', in <code>def pbDefaultChooseEnemyCommand</code>.
Firstly, the AI decides whether it should use an item ('''PokeBattle_Battle''', <code>pbEnemyItemToUse</code>). This def goes through each item the AI has, and decides whether to use it. There are separate clauses in this decision for each item the AI has been programmed to recognise - it can recognise (and therefore use) only the basic battle items. Note the order in which each recognised item is checked, e.g. Full Restore takes priority over Full Heal.
 
   
If the AI decides not to use an item, then it decides whether it can/should withdraw the Pokémon instead ('''PokeBattle_AI''', <code>pbEnemyShouldWithdrawEx?</code>). This def looks at several factors in turn, including how good the player's Pokémon's moves will do against it, whether it can use any moves itself, whether it is about to die of toxic poisoning or Perish Song, and so forth. This decision can flip-flop as it runs through each factor. Then the def decides which other Pokémon is the best choice to switch in with, and at the end does so.
+
Firstly, the AI decides whether it should use an item ('''PokeBattle_Battle''', <code>def pbEnemyItemToUse</code>). This method goes through each item the AI has, and decides whether to use it. There are separate clauses in this decision for each item the AI has been programmed to recognise - it can recognise (and therefore use) only the basic battle items. Note the order in which each recognised item is checked, e.g. Full Restore takes priority over Full Heal.
   
If the AI won't switch Pokémon either, then it needs to choose a move to use ('''PokeBattle_AI''', <code>pbChooseMoves</code>). For each available move in turn, it calculates a score depending on various factors, including the function code and effectiveness of that move, the currently active abilities, move effects and weather, the user's held item and status, and how many Pokémon the player has left. Then it compares the scores for each move, and chooses which move to use depending on these scores. If there are no good moves to choose from, then there is another opportunity to switch the Pokémon out.
+
If the AI decides not to use an item, then it decides whether it can/should withdraw the Pokémon instead ('''PokeBattle_AI''', <code>def pbEnemyShouldWithdrawEx?</code>). This method looks at several factors in turn, including how good the player's Pokémon's moves will do against it, whether it can use any moves itself, whether it is about to faint because of toxic poisoning or Perish Song, and so forth. This decision can flip-flop as it runs through each factor. Finally, if it has decided to switch Pokémon, the method decides which other Pokémon in the AI trainer's party is the best choice to switch in with, and does so.
   
  +
If the AI won't switch Pokémon either, then it needs to choose a move to use ('''PokeBattle_AI''', <code>def pbChooseMoves</code>). For each known move in turn, it calculates a score depending on various factors, including the [[Function codes|function code]] and effectiveness of that move, the currently active abilities, move effects and weather, the user's held item and status, and how many Pokémon the player has left. It then compares the scores for each move, and chooses which move to use depending on these scores. If there are no good moves to choose from, there is another opportunity to switch the Pokémon out instead.
Just before it chooses a move to use, the AI will decide if it should Mega Evolve their Pokémon. By default, it will always choose to do so if possible.
 
  +
 
Just before it chooses a move to use, the AI will decide if it should [[Mega Evolution|Mega Evolve]] their Pokémon. By default, it will always choose to do so if possible.
   
 
== Item recognition and effects ==
 
== Item recognition and effects ==
The AI needs to be programmed to recognise items. Currently it only recognises the basic Potions, Heal items and X stat raisers. This recognition is done in the script section '''PokeBattle_Battle''', in the def <code>pbEnemyItemToUse</code>.
 
   
 
The AI needs to be programmed to recognise particular items. Currently it only recognises the basic Potions, Heal items and X stat raisers. This recognition is done in the [[script section]] '''PokeBattle_Battle''', in <code>def pbEnemyItemToUse</code>.
Items used by the AI also need effects - they are defined separately from the effects used when the player uses them. These effects are listed in the def <code>pbEnemyUseItem</code>, just below the above def. These effects should be the same as if the player had used them, for fairness.
 
  +
 
Items used by the AI also need code describing their effects - this code is separate from the code used when the player uses the item. These effects are listed in <code>def pbEnemyUseItem</code>, just below the above method. These effects should be the same as if the player had used them, for fairness.

Revision as of 23:50, 1 January 2019

For when the AI is used, see Battle round.

This page describes the battle AI (artificial intelligence). That is, how computer-controlled opponents in battle (both wild Pokémon and enemy/ally trainers) choose which moves to use and which items to use when. This page assumes the AI controlling an enemy trainer, although it applies for wild Pokémon and partner trainers too.

This is a complicated topic, and unnecessary for most users. Do not attempt to modify the AI unless you have decent scripting knowledge.

Levels of AI

The basic principle of AI in Essentials is that better trainers should be cleverer than worse trainers. A cleverer AI has access to more information about the battle and is more informed about various effects of moves/abilities/items/other effects.

When defining a trainer type, one of the properties that can be defined is a skill level. This is usually the same as the trainer type's base money payout. A higher skill level represents a better AI.

By default, there are 5 tiers of AI in Essentials:

  • Skill level 0 - Used by wild Pokémon, which have an equal chance of choosing each move they know.
  • Skill level 1-31 - Known as PBTrainerAI.minimumSkill. Trainers are assumed to be at least this tier.
  • Skill level 32-47 - Known as PBTrainerAI.mediumSkill.
  • Skill level 48-99 - Known as PBTrainerAI.highSkill.
  • Skill level 100+ - Known as PBTrainerAI.bestSkill.

All trainer types within a given tier will behave exactly the same. The only differences are between different AI tiers, where higher tiers have access to more information and improved calculations.

AI overview

The first thing the AI needs to do each turn is decide whether to use an attack, use an item, or switch their Pokémon with another one. This decision starts in the script section PokeBattle_Battle, in def pbDefaultChooseEnemyCommand.

Firstly, the AI decides whether it should use an item (PokeBattle_Battledef pbEnemyItemToUse). This method goes through each item the AI has, and decides whether to use it. There are separate clauses in this decision for each item the AI has been programmed to recognise - it can recognise (and therefore use) only the basic battle items. Note the order in which each recognised item is checked, e.g. Full Restore takes priority over Full Heal.

If the AI decides not to use an item, then it decides whether it can/should withdraw the Pokémon instead (PokeBattle_AIdef pbEnemyShouldWithdrawEx?). This method looks at several factors in turn, including how good the player's Pokémon's moves will do against it, whether it can use any moves itself, whether it is about to faint because of toxic poisoning or Perish Song, and so forth. This decision can flip-flop as it runs through each factor. Finally, if it has decided to switch Pokémon, the method decides which other Pokémon in the AI trainer's party is the best choice to switch in with, and does so.

If the AI won't switch Pokémon either, then it needs to choose a move to use (PokeBattle_AIdef pbChooseMoves). For each known move in turn, it calculates a score depending on various factors, including the function code and effectiveness of that move, the currently active abilities, move effects and weather, the user's held item and status, and how many Pokémon the player has left. It then compares the scores for each move, and chooses which move to use depending on these scores. If there are no good moves to choose from, there is another opportunity to switch the Pokémon out instead.

Just before it chooses a move to use, the AI will decide if it should Mega Evolve their Pokémon. By default, it will always choose to do so if possible.

Item recognition and effects

The AI needs to be programmed to recognise particular items. Currently it only recognises the basic Potions, Heal items and X stat raisers. This recognition is done in the script section PokeBattle_Battle, in def pbEnemyItemToUse.

Items used by the AI also need code describing their effects - this code is separate from the code used when the player uses the item. These effects are listed in def pbEnemyUseItem, just below the above method. These effects should be the same as if the player had used them, for fairness.