Open yellowface7 opened 2 years ago
Hey @yellowface7,
For you bot to function, choose_move
should always return a BattleOrder
. Here, your code is testing if your active pokemon can use a move, and if its health is low, it will use the move that will restore as max HP as possible.
However, if your hp is not low, or if your pokemon can not use a move (for instance, if it fainted and needs to be switched out), choose_move
will just stop, and return None
. This is what is happening here - one way to fix it would be to do something like:
def choose_move(self, battle):
# If the bot can attack, it will.
if battle.available_moves:
#Is our health low?
print("Health: " + str(battle.active_pokemon.current_hp))
if battle.active_pokemon.current_hp != None:
print("Health: " + str(battle.active_pokemon.current_hp))
if battle.active_pokemon.current_hp < battle.active_pokemon.current_hp / 2:
print("-Healing-")
# Find a healing move.
HealingMove = max(battle.available_moves, key=lambda move: move.heal)
return self.create_order(HealingMove)
print("Choosing a random move!")
return self.choose_random_move(battle)
Let me know if this helps!
Hey @yellowface7,
For you bot to function,
choose_move
should always return aBattleOrder
. Here, your code is testing if your active pokemon can use a move, and if its health is low, it will use the move that will restore as max HP as possible.However, if your hp is not low, or if your pokemon can not use a move (for instance, if it fainted and needs to be switched out),
choose_move
will just stop, and returnNone
. This is what is happening here - one way to fix it would be to do something like:def choose_move(self, battle): # If the bot can attack, it will. if battle.available_moves: #Is our health low? print("Health: " + str(battle.active_pokemon.current_hp)) if battle.active_pokemon.current_hp != None: print("Health: " + str(battle.active_pokemon.current_hp)) if battle.active_pokemon.current_hp < battle.active_pokemon.current_hp / 2: print("-Healing-") # Find a healing move. HealingMove = max(battle.available_moves, key=lambda move: move.heal) return self.create_order(HealingMove) print("Choosing a random move!") return self.choose_random_move(battle)
Let me know if this helps!
After the last part of the code I shared, I had an else statement. I have a better understanding of choose_move thanks to the explanation. I decided to take a better look at the getting started section in the docs since I jumped right in previously.
I am new to both Python and poke-env.
I thought I was doing decent until I got the following log:
Here is the code that leads up to the error:
I created a reddit post in the Pokemon Showdown Coding subreddit but got no response. I decided to post here since I saw that someone else had this error at one point.