Closed mancho1987 closed 4 years ago
So you'll need to assemble the state such that each side has the active pokemon you want,.
It's really hacky, but this should get you the most damaging move for either side.
Notice calculate_damage
has been changed on the master branch from the version I see you were using. You may want to get the latest changes.
from showdown.engine import calculate_damage
def find_most_damage_move(state, side_string):
# `side_string` is either constants.SELF or constants.OPPONENT
my_options, opponent_options = state.get_all_options()
moves = []
switches = []
for option in my_options:
if option.startswith(constants.SWITCH_STRING + " "):
switches.append(option)
else:
moves.append(option)
most_damage = -1
for move in moves:
damage_amounts = calculate_damage(state, side_string, move, constants.DO_NOTHING_MOVE)
damage = damage_amounts[0] if damage_amounts else 0
if damage > most_damage:
most_damage = damage
return round(most_damage)
side_string
should indicate which side you want to find the most damaging move for. You can use this function for both sides.
To repeat this for each matchup, you'll need to modify your other functions to change the active pokemon in the state each time find_most_damage_move
is called.
This is REALLY hacky, but something like:
from copy import deepcopy
import constants
def how_many_each_sweeps(state, side, other_side):
how_many = dict()
for pkmn in ([side.active] + list(side.reserve.values())):
count = 0
if pkmn.hp == 0:
continue
for other_pkmn in ([other_side.active] + list(other_side.reserve.values())):
if other_pkmn.hp == 0:
continue
state_copy = deepcopy(state)
state_copy.self.active = pkmn
state_copy.opponent.active = other_pkmn
# use SELF to indicate we want to look at how much damage the active pokemon in state.self does
if find_most_damage_move(state_copy, constants.SELF) > (other_pkmn.hp / 2):
count += 1
how_many[pkmn.id] = count
return how_many
my_state = State(...)
how_many = how_many_each_sweeps(state, state.self, state.opponent)
and how_many
will be a dictionary representing how many pokemon each pokemon sweeps.
To do this for the opponent, you can simply reverse the order of sending in state.self
and state.opponent
closing this as we have discussed this privately
This is the code I have. Please excuse how bad it is, I am just starting and I am learning by reading your code.
` def find_most_damage_move(state, pkmn, opponent_pokemon):
Here I was trying to make a switch before getting all state options, as mentioned in the previous message. I realize this way to do it doesn't work.
I also need to calculate the maximum damage each opponent pokemon can inflict on each of the bot's
def find_most_damage_move_opponent(state, pkmn, opponent_pokemon):
Here is how I count how many opponent pokemon each of the bot's kills in one hit given their #current hp and the current conditions of the state.
def how_many_each_sweeps(state, user_pkmn):
def how_many_each_sweeps_opponent(state, opponent_pkmn):
`