星际争霸传统AI设备人源码分析(1)——架构和规则
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">始终</span><span style="color: black;">败兴</span>,星际争霸等策略游戏AI都被视为游戏AI中实现难度最高的。其一,游戏规则较<span style="color: black;">繁杂</span>,<span style="color: black;">包括</span>建造、资源收集、兵种<span style="color: black;">协同</span>、战斗微操<span style="color: black;">非常多</span>内容;其二,玩家需要运用<span style="color: black;">区别</span>的策略对抗<span style="color: black;">区别</span>敌人,策略很<span style="color: black;">繁杂</span>。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/dce0e4f9039544e29c7b22dd8dfc066b~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=tj94CgvRpVEsm%2BJ4SUhZ5NkZrZY%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">星际争霸游戏画面</p>
</div>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">为何</span>写这篇<span style="color: black;">文案</span></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">写此篇<span style="color: black;">文案</span><span style="color: black;">重点</span>有以下几点考量。其一,传统游戏AI基于规则实现,有的<span style="color: black;">运用</span>状态机、有的<span style="color: black;">运用</span><span style="color: black;">行径</span>树、<span style="color: black;">乃至</span>有些运用搜索算法来寻找最优的动作,策略游戏<span style="color: black;">常常</span>综合运用多种技术,有<span style="color: black;">必定</span>的<span style="color: black;">科研</span>价值;其二,尽管基于规则的传统AI没法和人类对抗,但它<span style="color: black;">触及</span>的程序抽象思想值得<span style="color: black;">科研</span>;其三,我之前写过几个AI<span style="color: black;">关联</span>的材料,一个是课程《各类型游戏人工智能算法》,它<span style="color: black;">重点</span>偏重于<span style="color: black;">区别</span>类型游戏AI的综述,另一个课程 《直观理解AI博弈原理》<span style="color: black;">重点</span>介绍象棋、围棋、王者荣耀的AI实现,更偏重于强化学习<span style="color: black;">办法</span>的演进,两者中间还缺乏一个综合实例,而星际争霸<span style="color: black;">设备</span>人UAlbertaBot刚好<span style="color: black;">能够</span>填补这一空白。本文<span style="color: black;">重点</span>参考UAlbertaBot的源码、Wiki,以及<span style="color: black;">关联</span>的几篇论文,<span style="color: black;">咱们</span>并不去关心程序<span style="color: black;">怎么样</span>安装和运行,而是关注它的设计和原理。</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">UAlbertaBot是什么</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">UAlbertaBot是一套开源的星际争霸AI,该程序自2010年<span style="color: black;">起始</span>参加<span style="color: black;">各样</span>星际AI的比赛,并且赢得2013年AIIDE星际争霸AI比赛的冠军。它的作者是David Churchill,纽芬兰纪念大学的计算机助理教授。UAlbertaBot的开源<span style="color: black;">位置</span>如下:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">https://github.com/davechurchill/ualbertabot/</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在2018年以前,<span style="color: black;">运用</span>强化学习<span style="color: black;">办法</span>的AI尚未成熟,UAlbertaBot等星际争霸<span style="color: black;">设备</span>人<span style="color: black;">作为</span>游戏AI竞技的<span style="color: black;">表率</span>。尽管在2018年以后强化学习AI展现出很强的能力,但强化学习AI训练难度大且难以用<span style="color: black;">规律</span><span style="color: black;">暗示</span>它的<span style="color: black;">行径</span>,游戏产业依然广泛的<span style="color: black;">运用</span>传统AI。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">文案</span>会分如下几篇</span></p><span style="color: black;">架构和规则,宏观介绍UAlbertaBot的原理</span><span style="color: black;">建造<span style="color: black;">次序</span>搜索,介绍<span style="color: black;">运用</span>深度搜索算法去找到最优建造<span style="color: black;">次序</span>的<span style="color: black;">办法</span></span><span style="color: black;">战斗模拟<span style="color: black;">评定</span>,介绍模拟队伍作战<span style="color: black;">评定</span>能否获胜的<span style="color: black;">办法</span></span><span style="color: black;">starterbot,一个最简单的<span style="color: black;">设备</span>人,从中理解最<span style="color: black;">基本</span>星际AI的写法</span><span style="color: black;">策略制定,策略制定部分的代码分析</span><span style="color: black;">建造实现,生产、建造<span style="color: black;">关联</span>系统的代码分析</span><span style="color: black;">战斗实现,战斗<span style="color: black;">关联</span>代码分析</span><span style="color: black;">寻路算法,地图<span style="color: black;">关联</span>代码的分析</span>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">代码结构</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">UAlbertaBot的代码<span style="color: black;">运用</span>C++编写,代码架构层次分明,整体如下图所示。<span style="color: black;">咱们</span><span style="color: black;">能够</span>先有个大概印象,其中CombatCommander负责兵种战斗的<span style="color: black;">规律</span>、WorkerManager负责工人的<span style="color: black;">规律</span>、ProductionManager负责建造<span style="color: black;">规律</span>、StrategyManager负责整体策略,整体还是比较明晰。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/cc6e48d4022a422ab940f093095a4572~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=3ZUVN2R8HvOHX%2FeYVa9KUrbSprs%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码层次结构</p>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/5815b027aebb4652b5ad47ede7c63806~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=CAqbUFIq8YhTzSqZV8tdZ0ogjvc%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">源码文件</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">程序从main<span style="color: black;">起始</span>运行,沿着UAIBertaBot、GameCommander逐层调用,最后分发到WorkerManager、ProductionManager等子系统,main、UAIBertaBot、GameCommander它们并不<span style="color: black;">包括</span><span style="color: black;">详细</span><span style="color: black;">规律</span>,仅仅是一层层的往下调用。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/0179edf2947440fea2f381bbb40e763c~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=vy8vJWXgKHSXZfL7vpqSSeNZSmc%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">顶部的代码结构</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">各个子系统负责对应的<span style="color: black;">规律</span>实现,它们的<span style="color: black;">重点</span>功能如下。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/a0889e2038f6485ea7768dd464af2d3e~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=sn9ThdQx%2B1vRhn6J%2F2mmJT0DA1o%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">各个子系统</p>
</div>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">ProductionManager 生产管理器</h1><span style="color: black;">在程序中,策略管理器(StrategyManager)会负责<span style="color: black;">选取</span>合适的策略,而针对<span style="color: black;">区别</span>的策略需要生产<span style="color: black;">区别</span>的单位,StrategyManager会生成一个建造<span style="color: black;">目的</span>(build order goal ),<span style="color: black;">包括</span>要生产的内容,由ProductionManager去执行。</span><span style="color: black;"><span style="color: black;">因为</span>建造单元有依赖关系,<span style="color: black;">亦</span>会消耗资源,必须<span style="color: black;">恰当</span>地安排生产的<span style="color: black;">次序</span>。ProductionManager会调用StarcraftBuildOrderSearch进行搜索,找到最<span style="color: black;">恰当</span>的建造<span style="color: black;">次序</span>(后续还会<span style="color: black;">仔细</span>介绍搜索的过程),形成建造列表(build order)</span><span style="color: black;"><span style="color: black;">根据</span>优先级,建造队列(build order)里的单位。</span><span style="color: black;">ProductionManager会调用BuildingManager来实现<span style="color: black;">详细</span>的建造过程,<span style="color: black;">包含</span>分配工人去建造、建造过程中工人被打死需要重新分配工人、管理建筑的状态(准备建、已分配工人、建造中、建造完成)。</span>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">CombatCommander 战斗管理器</h1><span style="color: black;"><span style="color: black;">倘若</span>敌人来到我方<span style="color: black;">霸占</span>的区域,创建防御队伍(defense Squad)去防御。</span><span style="color: black;"><span style="color: black;">倘若</span>存在攻击单位,<span style="color: black;">根据</span>如下<span style="color: black;">次序</span>进行攻击,a:已知的敌人基地;b:可见的敌人单元;c:已知的敌人建筑;d:进行探索,直到找到攻击<span style="color: black;">目的</span>。</span><span style="color: black;">CombatCommander会<span style="color: black;">按照</span>需要创建队伍,如需要防御时创建防御队伍,攻击时创建攻击队伍,分配单元到各个队伍(Squads),并且管理它们。其中Squads模块会调用CombatSimulation进行战斗模拟(后续<span style="color: black;">亦</span>会<span style="color: black;">仔细</span>说明),<span style="color: black;">倘若</span>预估会胜利,则指示队伍去攻击敌人;<span style="color: black;">倘若</span>预估会失败,则撤退。Squads会调用<span style="color: black;">各样</span>MicroManager进行微观动作的操控。</span><span style="color: black;">MicroManager是一个基类,派生出MeleeManager(混战)、RangedManager(范围攻击)、DetectorManager(侦查管理器),<span style="color: black;">区别</span>子类会实现一种特定<span style="color: black;">行径</span>的<span style="color: black;">掌控</span>。</span><span style="color: black;">在合适时间,设置一个工人去侦查,以探索地图区域。CombatCommander会调用scoutManager,负责侦查<span style="color: black;">规律</span>,a:<span style="color: black;">详细</span><span style="color: black;">规律</span>是寻找敌人基地并往敌人基地的方向行进;b:<span style="color: black;">倘若</span>在敌人基地内遇到敌方工人则攻击它;c:<span style="color: black;">倘若</span>敌方工人反击,则撤退。</span>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">WorkerManager 工人管理器</h1><span style="color: black;"><span style="color: black;">倘若</span>有空闲工人,分配<span style="color: black;">她们</span>去收集矿产</span><span style="color: black;">为<span style="color: black;">每一个</span>提炼厂分配3个工人</span><span style="color: black;"><span style="color: black;">倘若</span><span style="color: black;">发掘</span>新的油矿,重新分配工人去挖矿</span><span style="color: black;"><span style="color: black;">倘若</span>需要建造,分配<span style="color: black;">有些</span>工人去建造</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">其他系统诸如InformationManager会记录已<span style="color: black;">发掘</span>的敌人信息,MapGrid和MapTool会实现寻路辅助的功能。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">下面又到广而告之的时间啦,<span style="color: black;">倘若</span>你想学习<span style="color: black;">研发</span>游戏,不妨看一看笔者写的《Unity3D网络游戏实战》和《百万在线:大型游戏服务端<span style="color: black;">研发</span>》,毕竟<span style="color: black;">亦</span>是花费<span style="color: black;">数年</span>时间编写,相信对<span style="color: black;">大众</span>理解游戏<span style="color: black;">研发</span>技术会有<span style="color: black;">有些</span><span style="color: black;">帮忙</span>。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/9cfdcdd2515c4b33bcd3b1252c5362cc~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728825419&x-signature=PdBE0vU%2FjfJ4antSnu4f3ys%2BGKU%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">作者的一系列游戏技术总结</p>
</div>
外链发布论坛学习网络优化SEO。 一看到楼主的气势,我就觉得楼主同在社区里灌水。
页:
[1]