Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto battle #4

Closed
wants to merge 155 commits into from
Closed

Auto battle #4

wants to merge 155 commits into from

Conversation

Mowlawner
Copy link
Contributor

This PR contains the changes needed to reimplement the automatic battling system. This also contains some handling for new move options- stop will stop execution and let the user pick, and cancel will mash B until the overworld is reached unless the currently displayed text says "Stop learning {whatever the move is}?", in which case it will press A to exit the game's loop.

Mowlawner and others added 5 commits August 22, 2023 21:48
- added menuing file to store menu navigation functionality
- added select_battle_option function to facilitate battle menu navigation
- added FleeBattle function (self-explanatory)
modules/Menuing.py Outdated Show resolved Hide resolved
@40Cakes 40Cakes mentioned this pull request Aug 23, 2023
40Cakes and others added 22 commits August 23, 2023 19:14
- Ports from old code:
-- added getMovePower to calculate effective move power
-- added isValidMove to determine validity of move
-- added FindEffectiveMove to find the best move to use
-- added BattleOpponent to handle battling opponents
- New stuff:
-- added handle_move_learning to deal with learning new moves
-- added placeholder calculate_new_move_viability to be fleshed out later
- updated all instances of `select_battle_option` to `SelectBattleOption`
- updated all instances of `log.info` to `console.print`
- removed extraneous print statements
# Conflicts:
#	modules/Menuing.py
#	modules/Stats.py
# Conflicts:
#	config.yml
#	modules/Config.py
#	modules/Memory.py
#	modules/Stats.py
@40Cakes
Copy link
Owner

40Cakes commented Oct 10, 2023

Really sorry it's taking me so long to test and review this, but can we please remove all os._exit() functions and force the bot to manual mode if possible?

I just got this error Desired option SHIFT not found in ['SUMMARY', 'CANCEL_1']. while testing Emerald and thought the bot crashed, noticed ~18 occurrences of os._exit() which is undesirable behaviour that can probably be avoided.

modules/Stats.py Outdated
replace_battler = not battle_won
else:
FleeBattle()
replace_battler = replace_battler or not CheckLeadCanBattle()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

┌───────────────────── Traceback (most recent call last) ─────────────────────┐
│ E:\Nextcloud\Projects\pokebot-gen3\pokebot.py:43 in MainLoop                │
│                                                                             │
│    40 │   │   try:                                                          │
│    41 │   │   │   if GetGameState() == GameState.BATTLE:                    │
│    42 │   │   │   │   if OpponentChanged():                                 │
│ >  43 │   │   │   │   │   EncounterPokemon(GetOpponent())                   │
│    44 │   │   │                                                             │
│    45 │   │   │   # If the game is still somewhere within the title screen  │
│    46 │   │   │   # with Prof. Birch) there is nothing the bot can do, so i │
│                                                                             │
│ ┌──────────────────────────────── locals ─────────────────────────────────┐ │
│ │                       ModeSpin = <function ModeSpin at                  │ │
│ │                                  0x0000028C033FE520>                    │ │
│ │                        profile = Profile(                               │ │
│ │                                  │   rom=ROM(                           │ │
│ │                                  │   │                                  │ │
│ │                                  file=WindowsPath('E:/Nextcloud/Projec… │ │
│ │                                  - Emerald Version (USA, Europe).gba'), │ │
│ │                                  │   │   game_name='Pokémon Emerald     │ │
│ │                                  (E)',                                  │ │
│ │                                  │   │   game_title='POKEMON EMER',     │ │
│ │                                  │   │   game_code='BPE',               │ │
│ │                                  │   │   language=<ROMLanguage.English: │ │
│ │                                  'E'>,                                  │ │
│ │                                  │   │   maker_code='01',               │ │
│ │                                  │   │   revision=0                     │ │
│ │                                  │   ),                                 │ │
│ │                                  │                                      │ │
│ │                                  path=WindowsPath('E:/Nextcloud/Projec… │ │
│ │                                  │                                      │ │
│ │                                  last_played=datetime.datetime(2023,    │ │
│ │                                  10, 10, 22, 52, 33, 11268)             │ │
│ │                                  )                                      │ │
│ │ verified_that_game_has_started = True                                   │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│                                                                             │
│ E:\Nextcloud\Projects\pokebot-gen3\modules\Stats.py:674 in EncounterPokemon │
│                                                                             │
│   671 │   │   │   replace_battler = not battle_won                          │
│   672 │   │   else:                                                         │
│   673 │   │   │   FleeBattle()                                              │
│ > 674 │   │   replace_battler = replace_battler or not CheckLeadCanBattle() │
│   675 │   │   if config['battle']['battle'] and config['battle']["replace_l │
│   676 │   │   │   RotatePokemon()                                           │
│   677 │   │   if config['battle']["pickup"]:                                │
│                                                                             │
│ ┌──────────────────────── locals ────────────────────────┐                  │
│ │ custom_found = False                                   │                  │
│ │      pokemon = {                                       │                  │
│ │                │   'name': 'Oddish',                   │                  │
│ │                │   'id': 43,                           │                  │
│ │                │   'natID': 43,                        │                  │
│ │                │   'species': 43,                      │                  │
│ │                │   'pid': 85797318,                    │                  │
│ │                │   'nature': 'Bashful',                │                  │
│ │                │   'language': 'E',                    │                  │
│ │                │   'shinyValue': 22537,                │                  │
│ │                │   'shiny': False,                     │                  │
│ │                │   'ot': {                             │                  │
│ │                │   │   'tid': 17925,                   │                  │
│ │                │   │   'sid': 13015                    │                  │
│ │                │   },                                  │                  │
│ │                │   ... +23                             │                  │
│ │                }                                       │                  │
│ └────────────────────────────────────────────────────────┘                  │
└─────────────────────────────────────────────────────────────────────────────┘
UnboundLocalError: cannot access local variable 'replace_battler' where it is 
not associated with a value
Shutting down...

@40Cakes
Copy link
Owner

40Cakes commented Oct 10, 2023

Really sorry it's taking me so long to test and review this, but can we please remove all os._exit() functions and force the bot to manual mode if possible?

I just got this error Desired option SHIFT not found in ['SUMMARY', 'CANCEL_1']. while testing Emerald and thought the bot crashed, noticed ~18 occurrences of os._exit() which is undesirable behaviour that can probably be avoided.

Turns out this is caused by having an egg in the party 🥚
image

Mowlawner and others added 11 commits October 10, 2023 15:35
…ttle

- added check to ensure `replace_battler` was only checked when battling is enabled
…her to print messages relating to switching a pokemon out

- added CheckBattleCanHappen func to prevent bot from doing battle-related stuff if the party doesn't allow it, but also to enable the bot to battle if, say, the user heals at a PC after the bot wass just spinning around because it couldn't battle
…at I don't let temporary turn into permanent) checks to make sure the bot mode isn't manual so that users can regain control at any time by switching to manual mode

- this is ugly and i don't like it but it fixes the issue quick so people can use it while i refactor this into a solution that uses fewer loops
…t doesn't display (since it's called like all the time)
@Mowlawner Mowlawner marked this pull request as draft October 19, 2023 19:58
This was referenced Oct 25, 2023
@40Cakes
Copy link
Owner

40Cakes commented Dec 2, 2023

Closing in favour of #117.

@40Cakes 40Cakes closed this Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants