PokéLLMon 源码解析(三)(2)https://developer.aliyun.com/article/1483645
.\PokeLLMon\poke_env\environment\side_condition.py
"""This module defines the SideCondition class, which represents a in-battle side condition. """ # 导入日志记录模块 import logging # 导入枚举模块 from enum import Enum, auto, unique # 定义一个枚举类,表示战斗中的一侧状态 @unique class SideCondition(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: return f"{self.name} (side condition) object" @staticmethod def from_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 类,表示宝可梦可能受到的状态 @unique class Status(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: return f"{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 枚举类 @unique class Weather(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: return f"{self.name} (weather) object" # 根据 Showdown 消息返回对应的 Weather 对象 @staticmethod def from_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"), }
.\PokeLLMon\poke_env\environment\__init__.py
# 从 poke_env.environment 模块中导入各种类和常量 from poke_env.environment import ( abstract_battle, battle, double_battle, effect, field, move, move_category, pokemon, pokemon_gender, pokemon_type, side_condition, status, weather, z_crystal, ) # 从 poke_env.environment.abstract_battle 模块中导入 AbstractBattle 类 from poke_env.environment.abstract_battle import AbstractBattle # 从 poke_env.environment.battle 模块中导入 Battle 类 from poke_env.environment.battle import Battle # 从 poke_env.environment.double_battle 模块中导入 DoubleBattle 类 from poke_env.environment.double_battle import DoubleBattle # 从 poke_env.environment.effect 模块中导入 Effect 类 from poke_env.environment.effect import Effect # 从 poke_env.environment.field 模块中导入 Field 类 from poke_env.environment.field import Field # 从 poke_env.environment.move 模块中导入 SPECIAL_MOVES, EmptyMove, Move 类 from poke_env.environment.move import SPECIAL_MOVES, EmptyMove, Move # 从 poke_env.environment.move_category 模块中导入 MoveCategory 类 from poke_env.environment.move_category import MoveCategory # 从 poke_env.environment.pokemon 模块中导入 Pokemon 类 from poke_env.environment.pokemon import Pokemon # 从 poke_env.environment.pokemon_gender 模块中导入 PokemonGender 类 from poke_env.environment.pokemon_gender import PokemonGender # 从 poke_env.environment.pokemon_type 模块中导入 PokemonType 类 from poke_env.environment.pokemon_type import PokemonType # 从 poke_env.environment.side_condition 模块中导入 STACKABLE_CONDITIONS, SideCondition 类 from poke_env.environment.side_condition import STACKABLE_CONDITIONS, SideCondition # 从 poke_env.environment.status 模块中导入 Status 类 from poke_env.environment.status import Status # 从 poke_env.environment.weather 模块中导入 Weather 类 from poke_env.environment.weather import Weather # 从 poke_env.environment.z_crystal 模块中导入 Z_CRYSTAL 类 from poke_env.environment.z_crystal import Z_CRYSTAL # 定义 __all__ 列表,包含所有导入的类和常量的名称 __all__ = [ "AbstractBattle", "Battle", "DoubleBattle", "Effect", "EmptyMove", "Field", "Move", "MoveCategory", "Pokemon", "PokemonGender", "PokemonType", "SPECIAL_MOVES", "STACKABLE_CONDITIONS", "SideCondition", "Status", "Weather", "Z_CRYSTAL", "abstract_battle", "battle", "double_battle", "effect", "field", "move", "move_category", "pokemon", "pokemon_gender", "pokemon_type", "side_condition", "status", "weather", "z_crystal", ]