"""
This module defines the PokemonGender class, which represents the gender of a Pokemon.
"""# 导入必要的模块from __future__ import annotations
from enum import Enum, auto, unique
from poke_env.exceptions import ShowdownException
# 定义 PokemonGender 枚举类@uniqueclassPokemonGender(Enum):"""Enumeration, represent a pokemon's gender."""# 定义枚举值
FEMALE = auto()
MALE = auto()
NEUTRAL = auto()# 定义对象的字符串表示def__str__(self)->str:returnf"{self.name} (pokemon gender) object"# 根据接收到的性别信息返回对应的 PokemonGender 对象@staticmethoddeffrom_request_details(gender:str)-> PokemonGender:"""Returns the PokemonGender object corresponding to the gender received in a message.
:param gender: The received gender to convert.
:type gender: str
:return: The corresponding PokemonGenre object.
:rtype: PokemonGenre
"""if gender =="M":return PokemonGender.MALE
elif gender =="F":return PokemonGender.FEMALE
# 抛出异常,表示未处理的请求性别raise ShowdownException("Unmanaged request gender: '%s'", gender)
.\PokeLLMon\poke_env\environment\pokemon_type.py
"""This module defines the PokemonType class, which represents a Pokemon type.
PokemonTypes are mainly associated with Pokemons and moves.
"""# 导入必要的模块from __future__ import annotations
from enum import Enum, auto, unique
from typing import Dict, Optional
# 定义 PokemonType 枚举类@uniqueclassPokemonType(Enum):"""A Pokemon type
This enumeration represents pokemon types. Each type is an instance of this class,
whose name corresponds to the upper case spelling of its english name (ie. FIRE).
"""# 定义不同的 Pokemon 类型
BUG = auto()
DARK = auto()
DRAGON = auto()
ELECTRIC = auto()
FAIRY = auto()
FIGHTING = auto()
FIRE = auto()
FLYING = auto()
GHOST = auto()
GRASS = auto()
GROUND = auto()
ICE = auto()
NORMAL = auto()
POISON = auto()
PSYCHIC = auto()
ROCK = auto()
STEEL = auto()
WATER = auto()
THREE_QUESTION_MARKS = auto()# 返回 Pokemon 类型对象的字符串表示def__str__(self)->str:returnf"{self.name} (pokemon type) object"# 计算该类型对于具有 type_1 和 type_2 类型的宝可梦的伤害倍率defdamage_multiplier(
self,
type_1: PokemonType,
type_2: Optional[PokemonType]=None,*,
type_chart: Dict[str, Dict[str,float]],)->float:"""Computes the damage multiplier from this type on a pokemon with types `type_1`
and, optionally, `type_2`.
:param type_1: The first type of the target.
:type type_1: PokemonType
:param type_2: The second type of the target. Defaults to None.
:type type_2: PokemonType, optional
:return: The damage multiplier from this type on a pokemon with types `type_1`
and, optionally, `type_2`.
:rtype: float
"""# 如果类型为 THREE_QUESTION_MARKS,则返回伤害倍率为 1if(
self == PokemonType.THREE_QUESTION_MARKS
or type_1 == PokemonType.THREE_QUESTION_MARKS
):return1# 计算伤害倍率
damage_multiplier = type_chart[type_1.name][self.name]if type_2 isnotNone:return damage_multiplier * type_chart[type_2.name][self.name]return damage_multiplier
# 从给定名称返回对应的 PokemonType 对象@staticmethoddeffrom_name(name:str)-> PokemonType:"""Returns a pokemon type based on its name.
:param name: The name of the pokemon type.
:type name: str
:return: The corresponding type object.
:rtype: PokemonType
"""# 如果名称为 "???",返回特定的 PokemonType 对象if name =="???":return PokemonType.THREE_QUESTION_MARKS
# 否则根据名称在 PokemonType 枚举中查找对应的对象并返回return PokemonType[name.upper()]
"""This module defines the SideCondition class, which represents a in-battle side
condition.
"""# 导入日志记录模块import logging
# 导入枚举模块from enum import Enum, auto, unique
# 定义一个枚举类,表示战斗中的一侧状态@uniqueclassSideCondition(Enum):"""Enumeration, represent a in-battle side condition."""
UNKNOWN = auto()
AURORA_VEIL = auto()
FIRE_PLEDGE = auto()
G_MAX_CANNONADE = auto()
G_MAX_STEELSURGE = auto()
G_MAX_VINE_LASH = auto()
G_MAX_VOLCALITH = auto()
G_MAX_WILDFIRE = auto()
GRASS_PLEDGE = auto()
LIGHT_SCREEN = auto()
LUCKY_CHANT = auto()
MIST = auto()
REFLECT = auto()
SAFEGUARD = auto()
SPIKES = auto()
STEALTH_ROCK = auto()
STICKY_WEB = auto()
TAILWIND = auto()
TOXIC_SPIKES = auto()
WATER_PLEDGE = auto()# 返回对象的字符串表示形式def__str__(self)->str:returnf"{self.name} (side condition) object"@staticmethoddeffrom_showdown_message(message:str):"""Returns the SideCondition object corresponding to the message.
:param message: The message to convert.
:type message: str
:return: The corresponding SideCondition object.
:rtype: SideCondition
"""# 替换消息中的特定字符
message = message.replace("move: ","")
message = message.replace(" ","_")
message = message.replace("-","_")try:# 尝试返回对应的 SideCondition 对象return SideCondition[message.upper()]except KeyError:# 如果未找到对应的对象,则记录警告信息
logging.getLogger("poke-env").warning("Unexpected side condition '%s' received. SideCondition.UNKNOWN will be"" used instead. If this is unexpected, please open an issue at ""https://github.com/hsahovic/poke-env/issues/ along with this error ""message and a description of your program.",
message,)return SideCondition.UNKNOWN
# SideCondition -> Max useful stack level# 定义可叠加状态及其最大叠加层数的字典
STACKABLE_CONDITIONS ={SideCondition.SPIKES:3, SideCondition.TOXIC_SPIKES:2}
.\PokeLLMon\poke_env\environment\status.py
"""
This module defines the Status class, which represents statuses a pokemon can be afflicted with.
"""# 导入必要的模块from enum import Enum, auto, unique
# 定义 Status 类,表示宝可梦可能受到的状态@uniqueclassStatus(Enum):"""Enumeration, represent a status a pokemon can be afflicted with."""# 定义不同的状态
BRN = auto()# 烧伤状态
FNT = auto()# 濒死状态
FRZ = auto()# 冰冻状态
PAR = auto()# 麻痹状态
PSN = auto()# 中毒状态
SLP = auto()# 睡眠状态
TOX = auto()# 中毒状态(剧毒)# 定义 __str__ 方法,返回状态对象的字符串表示def__str__(self)->str:returnf"{self.name} (status) object"
.\PokeLLMon\poke_env\environment\weather.py
"""This module defines the Weather class, which represents a in-battle weather.
"""# 导入日志记录模块import logging
# 导入枚举模块from enum import Enum, auto, unique
# 定义 Weather 枚举类@uniqueclassWeather(Enum):"""Enumeration, represent a non null weather in a battle."""# 枚举值
UNKNOWN = auto()
DESOLATELAND = auto()
DELTASTREAM = auto()
HAIL = auto()
PRIMORDIALSEA = auto()
RAINDANCE = auto()
SANDSTORM = auto()
SNOW = auto()
SUNNYDAY = auto()# 返回对象的字符串表示def__str__(self)->str:returnf"{self.name} (weather) object"# 根据 Showdown 消息返回对应的 Weather 对象@staticmethoddeffrom_showdown_message(message:str):"""Returns the Weather object corresponding to the message.
:param message: The message to convert.
:type message: str
:return: The corresponding Weather object.
:rtype: Weather
"""# 处理消息字符串
message = message.replace("move: ","")
message = message.replace(" ","_")
message = message.replace("-","_")try:# 尝试从枚举中获取对应的 Weather 对象return Weather[message.upper()]except KeyError:# 如果未找到对应的 Weather 对象,则记录警告并返回 UNKNOWN
logging.getLogger("poke-env").warning("Unexpected weather '%s' received. Weather.UNKNOWN will be used ""instead. If this is unexpected, please open an issue at ""https://github.com/hsahovic/poke-env/issues/ along with this error ""message and a description of your program.",
message,)return Weather.UNKNOWN
.\PokeLLMon\poke_env\environment\z_crystal.py
"""This module contains objects related ot z-crystal management. It should not be used
directly.
"""# 导入必要的类型from typing import Dict, Optional, Tuple
# 定义一个字典,存储 Z 晶石的信息,键为晶石名称,值为元组,元组包含两个元素:对应的宝可梦属性和招式
Z_CRYSTAL: Dict[str, Tuple[Optional[PokemonType], Optional[str]]]={"buginiumz":(PokemonType.BUG,None),"darkiniumz":(PokemonType.DARK,None),"dragoniumz":(PokemonType.DRAGON,None),"electriumz":(PokemonType.ELECTRIC,None),"fairiumz":(PokemonType.FAIRY,None),"fightiniumz":(PokemonType.FIGHTING,None),"firiumz":(PokemonType.FIRE,None),"flyiniumz":(PokemonType.FLYING,None),"ghostiumz":(PokemonType.GHOST,None),"grassiumz":(PokemonType.GRASS,None),"groundiumz":(PokemonType.GROUND,None),"iciumz":(PokemonType.ICE,None),"normaliumz":(PokemonType.NORMAL,None),"poisoniumz":(PokemonType.POISON,None),"psychiumz":(PokemonType.PSYCHIC,None),"rockiumz":(PokemonType.ROCK,None),"steeliumz":(PokemonType.STEEL,None),"wateriumz":(PokemonType.WATER,None),"aloraichiumz":(None,"thunderbolt"),"decidiumz":(None,"spiritshackle"),"eeviumz":(None,"lastresort"),"inciniumz":(None,"darkestlariat"),"kommoniumz":(None,"clangingscales"),"lunaliumz":(None,"moongeistbeam"),"lycaniumz":(None,"stoneedge"),"marshadiumz":(None,"spectralthief"),"mewniumz":(None,"psychic"),"mimikiumz":(None,"playrough"),"pikaniumz":(None,"volttackle"),"pikashuniumz":(None,"thunderbolt"),"primariumz":(None,"sparklingaria"),"snorliumz":(None,"gigaimpact"),"solganiumz":(None,"sunsteelstrike"),"tapuniumz":(None,"naturesmadness"),"ultranecroziumz":(None,"photongeyser"),}