Skip to Content
Swift游戏开发经典实例
book

Swift游戏开发经典实例

by Jonathon Manning, Paris Buttfield-Addison
January 2020
Intermediate to advanced
356 pages
6h 4m
Chinese
China Electric Power Press Ltd.
Content preview from Swift游戏开发经典实例
人工智能和行为
281
敌军损失的数量减去我军损失的数量。
我方拥有的金钱数减去敌人拥有的金钱数。
只计算我方拥有的积分,忽略敌方拥有的得分。
计算出每一种可能动作的得分之后,统计出其中的最高得分,并让计算机将这个获
得了最高得分的动作作为玩家的下一步动作。
讨论
本节采用的这种算法通常叫作“暴力”算法。对于复杂游戏,这种算法会变得极其
复杂。对于策略游戏来说,需要关心的是经济、单位的动作等,如果每个单位有
3
种可能的动作,玩家拥有
10
个单位,则最终可能的状态会超过
59000
种。要解决
这个问题,我们只能减少参与计算的状态数量。
如果要将这个问题变得更简单,则只有让
AI
在计算状态时变得更粗放。假设有一
个策略游戏中,我们攻击其他玩家时会消耗一定的点数,开发科技、建设防御也同
样会消耗点数。每一个回合,
AI
都需要计算出采取每个策略会消耗多少点数以及
所带来的效益。一旦决定要采用的策略,你就可以投入到攻击、科研或者防御行为
中去,
AI
模块负责处理剩下的细节问题。
9.12
判断对象能否
看见
其他对象
问题
我们想知道一个对象(捕猎者)到底能不能看到另一个对象(猎物),假设捕猎者
所面对的方向、捕猎者的视界,以及捕猎者和猎物的位置是已知的。
解决方案
首先,需要定义捕猎者能够看多远的距离,以及它的视界有多广。还需要知道捕猎
者当前所面对的方向。最后,还需要知道捕猎者和猎物的位置。
首先判断猎物距离捕猎者有多远。如果猎物距捕猎者的距离超过一定的距离,则捕
猎者就无法看见猎物:
282
9
// Target ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
FreeBSD® Unleashed

FreeBSD® Unleashed

Brian Tiemann, Michael C. Urban
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Swift学习手册

Swift学习手册

Jon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787519840129