【Python开发实践】AI人机对战五子棋——棋型变量设置&多人游戏类

棋型变量设置

之前的内容里,有写到棋型的设置,但在整个程序中,为了让计算机对棋型的数量、类型进行识别,需要设置一些棋型变量:

python 复制代码
class SITUATION(IntEnum):  # 棋型
    NONE = 0,  # 无
    SLEEP_TWO = 1,  # 眠二
    LIVE_TWO = 2,  # 活二
    SLEEP_THREE = 3,  # 眠三
    LIVE_THREE = 4,  # 活三
    CHONG_FOUR = 5,  # 冲四
    LIVE_FOUR = 6,  # 活四
    LIVE_FIVE = 7,  # 活五


SITUATION_NUM = 8  # 长度

# 方便后续调用枚举内容
FIVE = SITUATION.LIVE_FIVE.value
L4, L3, L2 = SITUATION.LIVE_FOUR.value, SITUATION.LIVE_THREE.value, SITUATION.LIVE_TWO.value
S4, S3, S2 = SITUATION.CHONG_FOUR.value, SITUATION.SLEEP_THREE.value, SITUATION.SLEEP_TWO.value

多人游戏类设置

python 复制代码
class MultiStartButton(Button):  # 开始按钮(多人游戏)
    def __init__(self, screen, text, x, y):  # 构造函数
        super().__init__(screen, text, x, y, [(153, 51, 250), (221, 160, 221)], True)  # 紫色

    def click(self, game):  # 点击,pygame内置方法
        if self.enable:  # 启动游戏并初始化,变换按钮颜色
            game.start()
            game.winner = None
            game.multiple=True
            self.msg_image = self.font.render(self.text, True, self.text_color, self.button_color[1])
            self.enable = False
            return True
        return False

    def unclick(self):  # 取消点击
        if not self.enable:
            self.msg_image = self.font.render(self.text, True, self.text_color, self.button_color[0])
            self.enable = True
相关推荐
gCode Teacher 格码致知10 小时前
Pandas教学-6:coerce详解
python·pandas
梦在远山后10 小时前
Electron 与 FastAPI 如何完成流式 Agent 对话
python·langchain·agent
大衛說10 小时前
12 · 文件 I/O 与序列化
python
小静AI工程实验室10 小时前
Python 爬虫中文乱码排查:严格解码、UTF-8 BOM 与 JSON 转义的 12 项实验
字符编码·爬虫·python
天天被压力11 小时前
【跨市场数据实战 #08】可转债折价机会怎么筛:3个接口抓比价、列表和实时盘口
java·人工智能·python
weixin1997010801611 小时前
[特殊字符]️《从0到1搭多平台二手ERP中台:闲鱼+淘宝+京东+拼多多+Mercari统一调度》(附Python源码)
python
王国强200911 小时前
uv 深入指南:重新理解 Python 的包管理、依赖解析与项目工程化
python
巡山小钻风来也11 小时前
【保姆级教程】自定义数据集微调PP-OCRv6文本检测模型
python·ocr·paddlepaddle
aramae11 小时前
MySQL内置函数(7)
开发语言·笔记·后端·mysql·其他
baopixiaoz11 小时前
BeeQuant × BeeAgent:用AI加速策略验证
大数据·人工智能·python·区块链