Battle System Update: Introduce Battle strategies, support Double and Safari battles #366
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This updates the battle system to separate the menu-handling logic from the decision-making logic.
It introduces a new concept called 'BattleStrategy' that are objects with a set of functions that can make decisions given a certain battle state. (Here's the base class with all methods documented)
For example, the battle strategy's
decide_turn(battle_state)
method is called for each round of a battle to determine the next action (fight, item, run, ...)Likewise, there are methods for deciding whether an evolution should be allowed or aborted, which existing move should be replaced if a new one is about to be learned, what to do after the lead Pokémon faints, etc.
Bot modes can specify their preferred battle strategy in the
on_battle_started()
method. That way, a bot mode can have much greater control over how the battle system behaves without the user having to modify the config files all the time. (And, for example the Nugget Bridge mode could have its own 'try to lose' battle strategy.)As part of the battle system overhaul double battles are now supported, as are Safari encounters (in principle, the battle strategies still only switch to manual.)
Changes
modules/battle_strategies/
contains available Battle Strategies and their interfaces.modules/battle_strategies/_interface.py
contains the baseBattleStrategy
class which is heavily commented.modules/battle_state.py
contains a data class and helper functions to retrieve consolidated information about the current state of the battle, such as active Pokémon/opponents and various Pokémon-specific and arena-specific status conditions.battle_
withinmodules/
contain the menuing logic, so that's mostly just what the oldbattle.py
did with some enhancements and split up into several files.modules/data/...
andmodules/items.py
relate to a new property ofItem
objects that indicate if and how an item can be used within battles.Notes
So far, I have mostly just aimed for feature parity and not introduced any other battle strategies. So this PR does not make full use of the potential capabilities of the new battle system.
Checklist
--line-length 120
argument