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

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

PokéLLMon 源码解析(三)(1)https://developer.aliyun.com/article/1483644

.\PokeLLMon\poke_env\environment\pokemon_gender.py

"""
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 枚举类
@unique
class PokemonGender(Enum):
    """Enumeration, represent a pokemon's gender."""
    
    # 定义枚举值
    FEMALE = auto()
    MALE = auto()
    NEUTRAL = auto()
    # 定义对象的字符串表示
    def __str__(self) -> str:
        return f"{self.name} (pokemon gender) object"
    # 根据接收到的性别信息返回对应的 PokemonGender 对象
    @staticmethod
    def from_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 枚举类
@unique
class PokemonType(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:
        return f"{self.name} (pokemon type) object"
    # 计算该类型对于具有 type_1 和 type_2 类型的宝可梦的伤害倍率
    def damage_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,则返回伤害倍率为 1
        if (
            self == PokemonType.THREE_QUESTION_MARKS
            or type_1 == PokemonType.THREE_QUESTION_MARKS
        ):
            return 1
        # 计算伤害倍率
        damage_multiplier = type_chart[type_1.name][self.name]
        if type_2 is not None:
            return damage_multiplier * type_chart[type_2.name][self.name]
        return damage_multiplier
    # 从给定名称返回对应的 PokemonType 对象
    @staticmethod
    def from_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()]

PokéLLMon 源码解析(三)(3)https://developer.aliyun.com/article/1483646

相关文章
|
4天前
|
Linux 网络安全 Windows
网络安全笔记-day8,DHCP部署_dhcp搭建部署,源码解析
网络安全笔记-day8,DHCP部署_dhcp搭建部署,源码解析
|
5天前
HuggingFace Tranformers 源码解析(4)
HuggingFace Tranformers 源码解析
6 0
|
5天前
HuggingFace Tranformers 源码解析(3)
HuggingFace Tranformers 源码解析
7 0
|
5天前
|
开发工具 git
HuggingFace Tranformers 源码解析(2)
HuggingFace Tranformers 源码解析
8 0
|
5天前
|
并行计算
HuggingFace Tranformers 源码解析(1)
HuggingFace Tranformers 源码解析
11 0
|
6天前
PandasTA 源码解析(二十三)
PandasTA 源码解析(二十三)
43 0
|
6天前
PandasTA 源码解析(二十二)(3)
PandasTA 源码解析(二十二)
35 0
|
6天前
PandasTA 源码解析(二十二)(2)
PandasTA 源码解析(二十二)
42 2
|
6天前
PandasTA 源码解析(二十二)(1)
PandasTA 源码解析(二十二)
33 0
|
6天前
PandasTA 源码解析(二十一)(4)
PandasTA 源码解析(二十一)
24 1

推荐镜像

更多