-
Notifications
You must be signed in to change notification settings - Fork 177
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
Bug Fixes plus a couple features I wanted #194
base: master
Are you sure you want to change the base?
Conversation
Lines 107 - 109 removed. Created issue with no team preview as moves were being cleared and only options were switch.
fixed Issues on line 45 writing to log file due to UTF-8 encoded symbols coming from the websocket.
…TIME. Set the default to 15 since if two bots battle eachother the battle is too short and the challenger gets halted. Showdown has a 12 battle per 3 minute limit, so this should allow bots to battle continously.
…ner AI from gen 1. Random moves and only switches to the next Pokemon when forced.
Removed parentheses I added by accident.
Change default cooldown_time to 10
…using an error. Only run code at 340 if user_json contains active.
New fix for issue where fainted Pokemon count as trapped, as my previous fix caused other issues. When a Type error occurs in the line 340 try block just return.
hey thnx for opening this. by process of elimination, I take it that the changes in
Since its not immediately obvious, could you elaborate on how these bugs manifest and how these changes fix them, perhaps with a stacktrace and/or some logs? |
Yeah, I will share that tomorrow. |
Fixed a bug with no team preview causing a forced switch on turn 1. Here is a log snippet with some print debugging to show where the problem is. | The following is a code snippet from the read_messages_until_first_pokemon_is_seen function to aid in my explanation of what is happening.
"start" is found so the line following "start" are processed. "|switch|p1a: Grotle|Grotle, M|100/100" is processed. since it contains opponent_id and "switch" run battle.start_non_team_preview_battle(user_json, line). battle.started is set to true. At this point the debugging shows the best move is crunch. "|switch|p2a: Tyranitar|Tyranitar, F|351/351" is processed and since battle.started is true run async_update_battle(battle, line). After this the best move is now switch. When the best move is finally selected it ends up being switch. I am not sure why await async_update_battle(battle, line) makes switch the only option. I tried following the execution but I can't seem to find it. I thought I found it two days ago but I can't remember at this point. My fix is to remove the following lines which seems to have no side effects. elif battle.started: I suppose adding break after the following line may add efficiency since just removing code does not stop the for loop. battle.start_non_team_preview_battle(user_json, line) Let me know what you think. |
Fixed a bug where fainted Pokemon would be treated as trapped. Looking at this further I wouldn't call this bug Pokemon being treated as trapped, but an issue where the json is missing the fainted Pokemon. Here is a log at at the end of this comment for when that occurs with a stack trace. The exception occurs at the following point File "C:\Users\Carson\Downloads\showdown-master 1\showdown-master\showdown\battle.py", line 341, in from_json My change in the following code. I decided to return when the exception occurs since the function pokemon_battle in run_battle.py will loop again since action_required will be false since in the update_battle function battle.force_switch will be false from the request function. All to say returning from the exception causes no harm an will run the code again and allow the proper json to be recieved.
I added except TypeError: I am also not sure anymore if this is a side effect to my other bug fix. I feel like it is not, but it is hard to test. This bug only happens occasionally. Also this may only occur when two bots are playing as that is how I have tested for it. Anyway, I probably spent too much time digging into these bugs . Just let me know what you think, and if you need anything else. Here is the problematic json copied from the log. You can see it is missing data for the opposing pokemon. {'wait': True, 'side': {'name': 'SwagMander Gaming', 'id': 'p1', 'pokemon': [{'ident': 'p1: Jirachi', 'details': 'Jirachi', 'condition': '404/404', 'active': True, 'stats': {'atk': 236, 'def': 269, 'spa': 236, 'spd': 267, 'spe': 236}, 'moves': ['metronome'], 'baseAbility': 'serenegrace', 'item': 'leftovers', 'pokeball': 'pokeball'}]}, 'rqid': 4} Also here is a screen shot of the other bot. It was trying to make a move while the bot with the Jirachi was erroring. I don't have the logs for the second bot though. And here is the full log. [DEBUG] Applying move mod for gen 4 [DEBUG] Received message from websocket: >battle-gen4ou-2145995769 Traceback (most recent call last): |
Without calling For example, lets say the first pokemon to switch in (for either side.. doesn't matter) has intimidate. Intimidate activating would be a part of those log messages and without calling In your example you're inserting I don't see how the existing code would result in always selecting a switch, are you sure this isn't just happening for your particular example? Or do you see this repeatedly. Here is a replay of the bot clicking thunderbolt on turn1 of a gen3ou battle: https://replay.pokemonshowdown.com/gen3ou-2155753021-ceie90n8ebmboed3q4dmm7ydwkzp7pnpw and here is the associated log:
|
This is a nasty bug that really highlights some of the spaghetti in here. The request JSON is not being set on the battle because it is a standard battle and the request JSON isn't set until later on. code ref. Why does the bot do this for standard battles only? Who knows.. I made that change almost 5 years ago. Maybe for some reason I didn't want a request JSON present on the battle during team-preview. Anyway the absence of a request JSON causes this line to error. There are couple of things that need to go wrong for this to happen:
All of this is evidence that this should be refactored since its been over 5 years since I initially wrote it, but I'll put up a separate change to make this not happen in the short term. Thanks for bringing this up. |
…t yet. Discovered when addressing #194.
I found this awesome project that was perfect for some simulations I wanted to run. I ran into some bugs so I decided to fix them and make the project better.
Fixed issues with logfiles on Windows. (invalid filename and encoding issue on write)
Fixed a bug with no team preview causing a forced switch on turn 1.
Fixed a bug where fainted Pokemon would be treated as trapped.
I also added some features I need for my own simulations that might be appreciated.
Added COOLDOWN_TIME as an env option for custom delay for starting new challenges.
Added a random battle bot.
Please let me know if anything needs to be changed here.