_PoY

[Crystal] AI

Nov 1st, 2020 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. Pokémon Crystal - AI calculations
  2. -----
  3. NOTE:
  4. - Some behaviours are wrongly explained here. TODO
  5.  
  6.  
  7.  
  8.  
  9. ----
  10. LINKS :
  11. (1) AI layers : https://github.com/pret/pokecrystal/blob/master/data/trainers/attributes.asm
  12. (2) AI constant flags : https://github.com/pret/pokecrystal/blob/4fb008844030283ad34cb0802b088b4dd7c9891c/constants/trainer_data_constants.asm
  13. (3) Scoring : https://github.com/pret/pokecrystal/blob/650686476c47d03148dfb93de1388b1a7294e385/engine/battle/ai/scoring.asm
  14.  
  15. WHEN AI IS CALLED :
  16. - Just before the battle menu shows up.
  17.  
  18. INITIALISATION :
  19. - Each usable move is given a score of 20.
  20. - Each unusable move is given a score of 80. An unusable move is defined as follows :
  21. - Disabled moves.
  22. - Moves with 0 PP left.
  23.  
  24. SCORES MODIFICATION :
  25. - Each AI layer will juggle with each move score.
  26. - Encouraging a move decreases its score (gets closer to 0).
  27. - Discouraging a move increases its score (gets away from 0).
  28. - A call to `AIDiscourageMove` will add 10 to a move score. It almost always means the move is discarded.
  29. - the term "dismiss" will be used when this function is called.
  30. - Otherwise, (en/dis)couraging describes a score variation of 1.
  31. - Greatly (en/dis)couraging describes a score variation of 2.
  32.  
  33. IMPACT OF RANDOMNESS :
  34. - Many AI layers involve randomness thresholds, which can create variance in the results.
  35. - Variance functions are
  36. - `AI_50_50` : 50/50 outcome.
  37. - `AI_80_20` : 80/20 outcome (the odds of an outcome is context-specific).
  38.  
  39. ADRESSES :
  40. - `wBuffer1` up to `wBuffer1 + 3` store enemy move scores.
  41.  
  42. SCORE COMPILATION :
  43. - Once all AI layers have been applied, all moves with the minimum score are candidates for the AI choice.
  44. - If more than 1 move is candidate, the selection is done at random, each move having the same chance to be picked.
  45.  
  46.  
  47. EXAMPLE :
  48. - Blue's AI is defined as follows :
  49. AI_BASIC | AI_SETUP | AI_SMART | AI_AGGRESSIVE | AI_CAUTIOUS | AI_STATUS | AI_RISKY
  50.  
  51. - AI_BASIC will be the first layer, AI_SETUP will be the second, etc.
  52. - Let's investigate a setup turn on Pidgeot against a neutral faster player Pokémon :
  53. Moveset : QUICK_ATTACK, WHIRLWIND, WING_ATTACK, MIRROR_MOVE
  54.  
  55. (0) Initialisation : scores set to 20/20/20/20
  56. (1) AI_BASIC :
  57. - Dismiss all moves in `AI_Redundant` if they are useless.
  58. - Dismiss status-only moves if the user is already statused.
  59. - Dismiss Safeguard if already active.
  60.  
  61. Since none apply here, scores are unchanged : 20/20/20/20
  62.  
  63. (2) AI_SETUP :
  64. - 50% chance to greatly encourage stat-up/down moves during first enemy turn.
  65.  
  66. Since none apply here, scores are unchanged : 20/20/20/20
  67.  
  68. (3) AI_SMART :
  69. - Context-specific scoring : it could be seen as a combo-search layer.
  70. - It will search moves in `AI_Smart_EffectHandlers` and update their scoring.
  71.  
  72. MIRROR_MOVE (EFFECT_MIRROR_MOVE) and WHIRLWIND (EFFECT_FORCE_SWITCH) are in this table.
  73. a) MIRROR_MOVE :
  74. ┌─ enemy is faster ────────── dismiss
  75. - Player did not use a move ┴─ enemy is slower or tied ── nothing
  76. - Player used a move ┬─ not in `v` ──────────── nothing
  77. └─ in `UsefulMoves` ─┬─50%────────── nothing
  78. └─50%─ encourage ─┬─ enemy slower or tied ── nothing
  79. └─ enemy is faster ─┬─10%─ nothing
  80. └─90%- encourage
  81.  
  82. The player didn't use a move, the enemy is slower, so MIRROR_MOVE score won't be dismissed.
  83.  
  84. b) WHIRLWIND :
  85. - Discourage if the player has not shown a super-effective move, or its typing is super-effective.
  86. The player didn't use a move, and is neutral typing, so the move is discouraged.
  87.  
  88. Scores are now : 20/21/20/20
  89.  
  90. (4) AI_AGGRESSIVE :
  91. - Discourage all damaging moves but the one that does the most damage, unless such a move :
  92. - has 0 or 1 base power (moves like Seismic Toss, Hidden Power, Counter, Fissure, etc.)
  93. - is "reckless" (Selfdestruct, Thrash, Double Slap, Double Kick, etc.)
  94. - If no damaging move deals damage to the player (immune), no move will be discouraged
  95.  
  96. The most damaging move is WING_ATTACK and the only other damaging move is QUICK_ATTACK,
  97. so the latter is discouraged.
  98.  
  99. Scores are now 21/21/20/20
  100.  
  101. (5) AI_CAUTIOUS :
  102. - 90% chance to discourage moves in `ResidualMoves` after the first turn
  103. - Such moves are among Mist, Leech Seed, Poison Gas, etc.
  104.  
  105. Since we're still in turn 1, this clause doesn't apply.
  106. Scores are unchanged : 21/21/20/20
  107.  
  108. (6) AI_STATUS :
  109. - Dismiss status moves that don't affect the player.
  110. - If the player can't be poisoned, put to sleep, or paralyzed.
  111.  
  112. Since none apply here, scores are unchanged : 21/21/20/20
  113.  
  114. (7) AI_RISKY :
  115. - Use any move that will KO the target.
  116. - Enemy never uses moves like Selfdestruct or Horn Drill at full health (effect in `RiskyEffects`).
  117. - If effect in `RiskyEffects` and enemy is not at full health,
  118. 20% chance to reduce score by 5.
  119.  
  120. Since none apply here, scores are unchanged : 21/21/20/20
  121.  
  122. (8) Now that all layers have been encountered, the AI chooses a move among the lowest scores, at random.
  123. In this case, WING_ATTACK and MIRROR_MOVE have 20.
  124. Pidgeot will be doing either of those 50% of the time.
  125.  
  126. MANIP BLUE's PIDGEOT :
  127. - Since wLastPlayerCounterMove is not reset when using X Items,
  128. you can use a move in `UsefulMoves` to get 75% Mirror Move odds.
  129. - This can be a life-saver for specific Pokémon like Heracross with Earthquake,
  130. since Wing Attack is a 4x effective move.
Add Comment
Please, Sign In to add comment