PokéLLMon 源码解析(三)(3)

简介: PokéLLMon 源码解析(三)(3)

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",
]


相关文章
|
8月前
|
算法 测试技术 C语言
深入理解HTTP/2:nghttp2库源码解析及客户端实现示例
通过解析nghttp2库的源码和实现一个简单的HTTP/2客户端示例,本文详细介绍了HTTP/2的关键特性和nghttp2的核心实现。了解这些内容可以帮助开发者更好地理解HTTP/2协议,提高Web应用的性能和用户体验。对于实际开发中的应用,可以根据需要进一步优化和扩展代码,以满足具体需求。
807 29
|
8月前
|
前端开发 数据安全/隐私保护 CDN
二次元聚合短视频解析去水印系统源码
二次元聚合短视频解析去水印系统源码
316 4
|
8月前
|
JavaScript 算法 前端开发
JS数组操作方法全景图,全网最全构建完整知识网络!js数组操作方法全集(实现筛选转换、随机排序洗牌算法、复杂数据处理统计等情景详解,附大量源码和易错点解析)
这些方法提供了对数组的全面操作,包括搜索、遍历、转换和聚合等。通过分为原地操作方法、非原地操作方法和其他方法便于您理解和记忆,并熟悉他们各自的使用方法与使用范围。详细的案例与进阶使用,方便您理解数组操作的底层原理。链式调用的几个案例,让您玩转数组操作。 只有锻炼思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
|
8月前
|
移动开发 前端开发 JavaScript
从入门到精通:H5游戏源码开发技术全解析与未来趋势洞察
H5游戏凭借其跨平台、易传播和开发成本低的优势,近年来发展迅猛。接下来,让我们深入了解 H5 游戏源码开发的技术教程以及未来的发展趋势。
|
8月前
|
存储 前端开发 JavaScript
在线教育网课系统源码开发指南:功能设计与技术实现深度解析
在线教育网课系统是近年来发展迅猛的教育形式的核心载体,具备用户管理、课程管理、教学互动、学习评估等功能。本文从功能和技术两方面解析其源码开发,涵盖前端(HTML5、CSS3、JavaScript等)、后端(Java、Python等)、流媒体及云计算技术,并强调安全性、稳定性和用户体验的重要性。
|
9月前
|
机器学习/深度学习 自然语言处理 算法
生成式 AI 大语言模型(LLMs)核心算法及源码解析:预训练篇
生成式 AI 大语言模型(LLMs)核心算法及源码解析:预训练篇
2216 1
|
8月前
|
负载均衡 JavaScript 前端开发
分片上传技术全解析:原理、优势与应用(含简单实现源码)
分片上传通过将大文件分割成多个小的片段或块,然后并行或顺序地上传这些片段,从而提高上传效率和可靠性,特别适用于大文件的上传场景,尤其是在网络环境不佳时,分片上传能有效提高上传体验。 博客不应该只有代码和解决方案,重点应该在于给出解决方案的同时分享思维模式,只有思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
|
11月前
|
存储 设计模式 算法
【23种设计模式·全精解析 | 行为型模式篇】11种行为型模式的结构概述、案例实现、优缺点、扩展对比、使用场景、源码解析
行为型模式用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间怎样相互协作共同完成单个对象都无法单独完成的任务,它涉及算法与对象间职责的分配。行为型模式分为类行为模式和对象行为模式,前者采用继承机制来在类间分派行为,后者采用组合或聚合在对象间分配行为。由于组合关系或聚合关系比继承关系耦合度低,满足“合成复用原则”,所以对象行为模式比类行为模式具有更大的灵活性。 行为型模式分为: • 模板方法模式 • 策略模式 • 命令模式 • 职责链模式 • 状态模式 • 观察者模式 • 中介者模式 • 迭代器模式 • 访问者模式 • 备忘录模式 • 解释器模式
【23种设计模式·全精解析 | 行为型模式篇】11种行为型模式的结构概述、案例实现、优缺点、扩展对比、使用场景、源码解析
|
11月前
|
设计模式 存储 安全
【23种设计模式·全精解析 | 创建型模式篇】5种创建型模式的结构概述、实现、优缺点、扩展、使用场景、源码解析
结构型模式描述如何将类或对象按某种布局组成更大的结构。它分为类结构型模式和对象结构型模式,前者采用继承机制来组织接口和类,后者釆用组合或聚合来组合对象。由于组合关系或聚合关系比继承关系耦合度低,满足“合成复用原则”,所以对象结构型模式比类结构型模式具有更大的灵活性。 结构型模式分为以下 7 种: • 代理模式 • 适配器模式 • 装饰者模式 • 桥接模式 • 外观模式 • 组合模式 • 享元模式
【23种设计模式·全精解析 | 创建型模式篇】5种创建型模式的结构概述、实现、优缺点、扩展、使用场景、源码解析
|
10月前
|
自然语言处理 数据处理 索引
mindspeed-llm源码解析(一)preprocess_data
mindspeed-llm是昇腾模型套件代码仓,原来叫"modelLink"。这篇文章带大家阅读一下数据处理脚本preprocess_data.py(基于1.0.0分支),数据处理是模型训练的第一步,经常会用到。
307 0

推荐镜像

更多
  • DNS