I
基于 python 语言的五子棋游戏设计与实现
摘 要
五子棋最早起源于我国,现如今已是全国智力运动会的竞赛项目之一,它是一种由
两人相互对弈的纯策略型棋类游戏,上手难度不高,但是其中又包含着许多奥妙的地方,
可以很好的锻炼脑力,男女老少都适合。因此,为了推广五子棋,让更多的人可以接触、
参与进来,笔者将通过简单的人工智能来研究,并利用 python 语言开发五子棋游戏。
其中的功能主要包含 PVE 模式,棋局重开,悔棋 qi’ju,游戏输赢的判断方法这几个功
能。在 PVE 模式中,通过递归算法的“今后几步预测法”和对棋局棋型的判断,让计算
机进行大致的分析,以此提高计算机的人工智能。让计算机利用预测法分析了玩家接下
来打算下子的地方,然后以及此来决定下一子该选择防守还是该选择进攻,在这些步骤
的基础上,可大大的提高计算机下棋的水平。通过深度搜索和估值模块,对计算机进行
大致的分析,以此提高计算机的智能。分析了估值模块中对精密度的几个影响因素,并
提出几个提高精密度的方法,还有比较扫描到的节点数,在这些步骤的基础上,可以提
出让计算机智能提高的方案。算法研究能够更好地理解程序结构,增强逻辑思维能力,
对其他人工智能也有很多参考价值。
关键词:五子棋;python;程序设计人机对弈;棋局重开;悔棋;python; 深度搜索;
人工智能
II
Abstract
Gobang first originated in China, now it is one of the national intelligence games
competition items, it is a pure strategy chess game by two people playing against each other,
the difficulty is not high, but it contains a lot of mysterious places, can be very good exercise
brain, men and women, young and old suitable. Therefore, in order to promote gobang, so that
more people can contact, participate in, the author will study through simple artificial
intelligence, and use python language to develop gobang game. The functions mainly include
PVE mode, the game win or lose the judgment method these several functions. In PVE mode,
a recursive algorithm is used to predict the next few steps and judge the type of chess games,
so that the computer can make a general analysis, so as to improve the artificial intelligence of
the computer. Let the computer use the prediction method to analyze the player next down place,
and then this to decide the next child should choose defense or attack, on the basis of these
steps, can greatly improve the level of computer chess. Algorithm research can better
understand program structure, enhance logical thinking ability, and has a lot of reference value
for other artificial intelligence.
Keywords:python
,
man machine chess
,
chess game reopened
,
regret
Gobang first originated in China, now it is one of the national intelligence games
competition items, it is a pure strategy chess game by two people playing against each other,
the difficulty is not high, but it contains many mysteries, can be a good exercise
of brain power, suitable for all ages. Therefore, in order to promote gobang, so that more people
can contact, participate in, the author will study through simple artificial intelligence, and use
python language to develop gobang game. The functions mainly include PVE mode, chess
game initialization, repenting, the game to win or lose the judgment method these several
functions. In PVE mode, through the deep search and valuation module,the computer is roughly
analyzed to improve the intelligence of the computer. This paper analyzes several factors
III
affecting the precision in the evaluation module, and puts forward several methods to improve
the precision, and compares the number of nodes scanned. On the basis of these steps, we can
put forward the scheme to improve the computer intelligence. Algorithm research can better
understand program structure, enhance logical thinking ability, and has a lot of reference value
for other artificial intelligence.
Keywords:gobang
,
programming
,
python
,
depth search
,
artificial intelligence
目 录
摘 要 ..............................................................................................................................Ⅰ
AbstractBSTRACT...........................................................................................................Ⅱ
第 1 章 绪 论 ........................................................1
1.1 前言 ...........................................................1
1.2 程序研究意义 ...................................................1
1.3 项目任务 .......................................................2
1.4 文章结构 .......................................................2
第 2 章 项目相关技术介绍 .............................................3
2.1 PYTHON 简介 ...................................................3
2.1.1 PYTHON 的特点..............................................3
2.1.2 PYTHON 的版本..............................................4
2.1.3 PYTHON 的配置..............................................4
2.2 开发环境 ........................................................5
2.3 开发环境的变量设置 ..............................................5
第 3 章 项目分析 .....................................................8
3.1 项目需求分析 ....................................................8
3.1.1 项目适用范围 ................................................8
3.1.2 项目实现的功能要求 ..........................................8
3.1.3 项目性能需求 ................................................9
3.1.4 系统平台要求 ................................................9
3.2 项目可行性分析 ..................................................9
3.2.1 技术可行性 ..................................................9
3.2.2 经济可行性 ..................................................9
3.2.3 社会可行性 ..................................................9
第 4 章 系统设计 ....................................................10
4.1 五子棋游戏简介 .................................................10
4.1.1 游戏概述 ...................................................10
4.1.2 游戏相关规则 ...............................................10
4.1.3 游戏相关术语 ...............................................10
4.2 项目程序流程图 .................................................12
4.3 游戏程序设计思路 ...............................................13
4.3.1 程序页面设计 ...............................................13
4.3.2 程序算法设计 ...............................................13
第 5 章 项目系统实现 ................................................16
5.1 程序页面模块实现 ...............................................16
5.2 PVE 程序模块实现...............................................18
5.3 REPLAY 功能模块实现..........................................231
5.4 悔棋功能模块实现 ..............................................244
5.5 重新开局模块实现 ..............................................256
第 6 章 项目程序测试 ..............................................2829
6.1 项目系统测试的意义 ...........................................2829
6.2 项目系统测试的目的 ...........................................2829
6.3 程序运行 .....................................................2829
6.3.1 程序正常运行结束 .........................................2829
6.3.2 REPLAY 功能模块测试......................................3030
6.3.3 悔棋功能模块测试 ..........................................301
6.3.4 对局重开功能模块测试 .....................................2832
6.3.5 子功能模块测试 ...........................................2833
6.4 测试评价 .....................................................2834
结论 ..............................................................2835
参考文献 ..........................................................2836
原创新声明 ........................................................2837
致谢 .............................................................2538
附录 ..............................................................3839