游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

如何创造出真正有趣的游戏AI

发布时间:2016-01-14 16:25:43 Tags:,,,,

作者:Darran Jamieson

为计算机对手创造优秀的人工智能是非常困难的。为一款国际象棋般的游戏编写程序是极具挑战性的;而添加具有说服力的AI甚至需要花费比创造游戏本身更长的时间。当我们在创造这样的AI时我们该怎么做?我们是否应该检查面板上每个可能的移动,或者我们是否只需要让它随机移动?AI需要做什么,或者最重要的是,我们该如何确保AI足够有趣?

优秀的AI与有趣的AI

AI这一词真的具有非常广泛的概念,并且AI类型也是取决于游戏。像《太空入侵者》,《马里奥》或《炮塔防御》等非对称游戏都允许玩家能够轻松地穿越大量敌人。因为“团队”(玩家vs其余的一切)是不平衡的,所以这些游戏总是倾向于使用较为愚蠢的AI。而像《星际争霸》,《街头霸王》或《文明》等对称游戏则期待玩家能够公平地击败对手,所以这类型游戏需要更复杂的AI。

然而对游戏来说最重要的还是乐趣。玩家喜欢挑战,也不希望一直输。实际上,像西洋棋等游戏已经得到“解决”,即意味着我们能在这类型游戏中创造一个所向无敌的AI。

当我和团队致力于我们的计算机/桌面游戏《Infected》时,我们必须确保第一个关卡的AI不会太吓人,从而避免吓跑玩家。一开始游戏AI较简单,计算机主要将展开进攻,即它会完全专注于高分游戏而未考虑防御。

尽管这时候的AI较弱,我们还是发现一些新玩家很容易被打压或对此失去兴趣。我们多次修改了AI,但是对于某些玩家来说它仍然具有很大的挑战。最终我们还是决定删除AI从而确保游戏每次都能够随机发展。尽管有些玩家还是会遭遇失败,但这一做法有效提高了玩家留存,并让我们能在之后关卡中再次加入复杂的AI。

我们可以在各种不同的游戏中看到“太优秀的”AI的问题:就像带有bot的第一人称射击游戏拥有360度视角,或者在打斗游戏中玩家将对抗带有完美反应能力的bot。与这些AI对抗并不能真正教授玩家如何有效玩游戏:这只能教授他们如何面对bot,并尝试着找出一些能够轻松消灭它们的方法。

然而这并不是说所有的AI都应该很弱,优秀的AI也具有多面性。比起一个每次都能完美完成游戏的AI,赋予AI适应能力(游戏邦注:从而增添游戏玩法的多样性)能够提供给玩家更多娱乐性。

赋予它们人性

在完成《Infected》后,我们简单规划了游戏续集《Infected 2》。游戏仍是使用同样的前提,但却是基于提供更大的规模,即与经典的桌面游戏《Risk》相似。因为游戏变得更大,所以我们必须大规模地完善AI:确保玩家能够在更长的游戏中仍然拥有乐趣,并且在这里也能够让多个AI相互抗衡。

我们尝试了之前的AI并发现了一些问题。这一AI是可预测的,但我们仍可以去完善它。但是还有一个更大的问题是关于AI的态度以及它的游戏方式。

这里主要存在三大问题:

首先:与AI对抗并不是特别有趣。

其次:打败AI并不能带来特别奖励。

再次:玩家很容易作弊。

在游戏中与其他玩家对抗是有趣的,但是与AI对抗却不是这样。尽管游戏中的挑战级别还是不变,游戏玩法也不变,那为什么玩家对抗AI与玩家对抗玩家之间存在如此巨大的差别?

要知道人类有一样东西是计算机并不具有的:情感。

而获得情感便是我们玩游戏的部分内容;我们喜欢刺激的胜利感,我们也讨厌痛苦的挫败感。我们喜欢在朋友面前炫耀自己的胜利,而当朋友背叛自己时我们也会想要向他们复仇。游戏总是与我们的情感紧密联系在一起,这也是AI不曾体验到的,而这也是作为开发者的我们想要效仿的内容。

活力

为什么与AI游戏并不有趣?

因为人工智能太过人工化。所有的bot都是基于同样的方式游戏,并且他们的移动模式都是可预测的。

我们需要让它们能够脱颖而出。于是我们便添加了一些个性:鲁莽的,自卫的,具有探索精神的。AI将赋予特定策略一些人为感,然后将转向那些攻击模式。

甚至在基本形式中,这也取得了一个巨大的进步:每一次游戏都不再相同,并且敌人的移动变得难以预测,玩家很难再制定一份单一的“游戏获胜”策略。当游戏开始时如果AI是随机的,那么玩家便不能预测之后的游戏会如何展开。

AI的特性并非一个全新理念。《文明》便已经赋予了主角特性(Gandhi非常喜欢攻击别人),《神话时代》的AI也能决定自己是否能够使用像龟缩或冲刺等策略,还有《虚幻竞技场》的bot能够选择自己喜欢的武器。

gandhi-civ(from tutsplus)

gandhi-civ(from tutsplus)

为什么打败AI不具有奖励性?

这里存在的主要问题是,每一轮游戏中AI都是以“最佳移动”的方式在游戏。它只是在评估游戏面板而不存在对于外交的奖励。如果它需要攻击你的话它就会这么做。如果你回击它的话,它也毫不在意。它只是将游戏作为一个待解决的数学题,而不是与复杂的人类玩家对抗的游戏。所以与人工智能的对抗便只会让人觉得这是一款人工游戏。

对此我们的解决方法是源自1989年一款名为《核战争》的Amiga游戏。在《核战争》中,你能对抗各个世界的领导者并尝试着对他们的国家发动核进攻。不管谁只要能够成功生存下来便能赢得游戏。尽管游戏很简单,但是看到敌人被仇恨蒙蔽了双眼并深陷战斗中还是非常有趣的。

这一“朋友和敌人”系统使用了一个非常简单的参数:幸福。每个世界的领导者都拥有各种面部表情,从而让玩家能够轻松地判断他对自己的态度。显然,攻击别人总是很快让他们不悦。此外你的敌人不只是会对你生气,他们也会彼此生气。这意味着一颗导弹有可能逐步升级为一场致命的战斗。

再一次地,这一系统也出现在许多游戏中,其中也包括了《文明》。一个拥有高度“幸福感”的帝国更有可能与你结盟并赠与你礼物,而一个讨厌你的敌人可能会引进大量资源去摧毁你的城市。

通过添加基本的幸福指标到游戏中,我们便能够创造出友谊与竞争。当你在游戏中添加惩罚机制,或者当游戏中出现团队和联盟时,游戏会变得更刺激。瞬间游戏变得更有个性,且游戏行动也变得更有分量。我们同样也发现可行的幸福指标非常重要,如果缺少了它玩家便不能理解到底发生了什么。就像单纯的笑脸图标能够直接传达出敌人不悦的情况,并且基于特定行动去观察脸部表情的变化能够让玩家更清楚地了解这些行动的结果。

囚徒困境悖论是非常有名的游戏理论概念,许多程序员也花了很多时间尝试着去创造反复囚徒困境中可抗衡的终极bot。但是让人奇怪的是多年以来获胜策略仍然非常简单:即我们所谓的争锋相对,这只是在复制对手的行动。

AI是如何作弊的?

《Infected 2》中有一个问题是,AI通常没什么远见。AI的目标是在每一轮游戏中获得最多分数:如果这意味着做出最糟糕的移动,它们也会这么做。

我们可以在如下情节中看到这点:

Alice,Bob和Carol正在玩战争游戏。

Alice拥有100个士兵。Bob拥有75个士兵。Carol拥有150个士兵。

不管是Alice还是Bob都不能打败Carol。

然而如果Alice和Bob联合在一起便能打败Carol。

这里的问题在于AI将做任何能够帮助自己获得最多分数的事。在上述情节中,这便意味着Alice将攻击Bob:从短期角度看来,这是最出色的行动,但从长期角度看来,这却糟糕透顶。如果Alice选择这么做,那么她不仅会摧毁自己,她也是在处罚Bob。而Bob对此将非常难过。

这种情况是很难避免的,因为从宏观层面看待事情是最简单的AI不可能做到的。我们尝试着通过避免玩家在失败时或刚遭遇攻击时不再被攻击而保证其中的“公平性”。尽管并不是所有游戏都适用同一个简单的解决方法,但我们都需要意识到玩家讨厌因为莫名其妙的原因遭遇攻击这一事实。

尽管《Infected 2》并未通过测试阶段,但它却教会了我们一些宝贵的经验教训。最重要的是,只是与敌人bot对抗是远远不够的:玩家都希望能够参与到游戏中,创造竞争并消灭所有与自己对抗的人。

有效设置AI

发行于几年前的《虚幻竞技场》似乎超越了竞争范围。尽管它的设计是基于多人游戏,但是bot却优秀到能够得到单人玩家的认可。也许按照今天的标准它的AI还很糟糕,但是《虚幻竞技场》却拥有超越其它游戏的AI。

我们可以从游戏的一张截图看看这款游戏的一个bot是如何诞生的:

screenshot(from tutsplus)

screenshot(from tutsplus)

技能是决定bot行为的主要元素:新手bot速度较慢,并且需要站稳了才能射击,转弯速度也很慢,而较高级别的bot速度较快,能够灵活地躲闪,且拥有更广的视野,还能够使用高级的武器组合技能。

之后bot可以在精确度,敏捷性和射击水平等方面得到进一步提升。而它们的“特性”则是取决于战斗类型和武器,并且将决定bot是否能够近距离接触或尝试着从远距离狙击对手。在32个bot中每个bot都是经过特别定制的,即意味着你将面对32种不同的个性。

而所有的这些元素都能够创造出更具人性的bot。尽管没有这些复杂的内容游戏也可能非常出色,但这些元素却能够为游戏添加额外的乐趣层面。

结论

最后你需要问自己:你想从AI中获得什么?敌人将义无反顾地冲向玩家并径直走向维修区,还是你想要创造一些能够呈现出与玩家之间更有个性的互动的内容?不管你最终做出怎样的选择,你都必须牢记三大要点:

如果bot能够犯错,它们便会更具有人性,而不再只是“一张纸牌”。

如果bot是基于独特的个性(游戏邦注:或情感,如仇恨)在游戏,那么游戏便更有可能呈现出不可预测且刺激的游戏玩法。

如果bot尝试放宽视野去玩游戏,不再目光短浅,玩家便更能够感受到游戏的公平性。

本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转发,如需转载请联系:游戏邦

Making AI Fun: When Good Enough is Good Enough

by Darran Jamieson

Making good artificial intelligence for computer opponents is difficult. Programming a game like draughts isn’t terribly challenging; adding convincing AI, however, might take longer than making the game itself. But what are we doing when we make this AI? Is it important for it to examine every possible move on the board, or can we cheat and just make it move randomly? What does an AI need to do, and (most importantly) how can we ensure that the game is fun?

Good AI vs Fun AI

The term “AI” is a really broad concept, and the type of AI depends on the game. Asymmetric games, such as Space Invaders, Mario, or Tower Defence, allow the player to cut through swathes of enemies effortlessly. Since the “teams” (player vs everything else) are unbalanced, these games tend to use dumb AI. Symmetric games, such as Starcraft, Street Fighter or Civilisation, expect the player to beat opponents on equal footing, and so require more complex AI.

However, games have to be fun, first and foremost. Players enjoy a challenge, not losing repeatedly. In fact, some games such as Checkers have been “solved”, meaning it is possible to build an AI which plays an unbeatable game.

When my team and I were working on our computer/board game Infected, we had to make the first level’s AI intentionally awful so as not to scare players off. The game AI was initially rather simplistic, and the computer would play hyper aggressively, focusing entirely on high scoring plays with no thought of defence or board presence.

Even though the AI was poor, we found that new players would get crushed and lose interest. We revised the AI several times, although it still proved too much of a challenge for players. Eventually, we simply removed the AI, so the game would just make a random move every time. Although some players still managed to lose, this massively improved player retention, allowing us to reintroduce the “serious” AI at higher levels.

The problem of “too good” AI can be seen in a variety of games: FPS games with bots that have 360 degree vision, or beat-’em-ups against bots with perfect reflexes. Playing against these AIs doesn’t actually teach the player to play the game well: it teaches them to “game” the bots, to try to find a flaw in the algorithm which allows easy kills.

This isn’t to say that all AI should be poor, but rather that good AI is multi-faceted. It makes mistakes, but tries to avoid falling into the same predictable patterns. Giving the AI the ability to adapt—and, therefore, to provide variance in gameplay—will likely provide much more entertainment for the player than an AI that plays the same perfect game every time.

Making Them Human

After making Infected, we briefly toyed around with a sequel, Infected 2. It was the same premise, but on a larger scale, similar to the classic board game Risk. Because the game was larger, it was important to have drastically improved AI: something which could keep the player entertained over the course of a much longer game, and where multiple AIs could compete against each other.

We plugged in the old AI, and there were several issues with it. The AI was predictable, but that was something that could be improved with a little work. The larger issue was regarding the general attitude of the AI, and how it played.

There were three main problems:

Firstly, playing against the AIs wasn’t particularly fun.

Secondly, beating the AI wasn’t particularly rewarding.

Thirdly, the AI would “cheat” by deliberately throwing the game.

The game was fun against other players, but not against the AI. Although there was still the same level of challenge, why was there such a massive disparity between player against the AI and playing against another person, if the gameplay was the same?

We then remembered that humans have one thing computers don’t: emotions.

Part of playing a game is getting emotional; we love a thrilling victory, we hate a crushing defeat. We love to rub our victories in our friends’ faces, and we become petty and vengeful when they betray us. Games are intrinsically linked to our emotions, and it’s something that an AI can never experience… but it is something that we developers can emulate.

The Vital Spark

Why wasn’t playing the AI fun?

Because the artificial intelligence was so obviously artificial. All the bots played the same way; they all had the same approaches to the game; they were all equally predictable in their movement patterns.

We needed something to make them stand out from each other. So we introduced personalities: reckless, defensive, explorer. The AI would give an artificial weight to certain strategies, and then move in those attack patterns.

Even in a basic form, this was a massive improvement: no longer was every game the same, but it added unpredictability to enemy moves and made it harder to formulate a single “game winning” strategy. If the AIs were randomised when the game started, then the player wouldn’t be able to predict how the game would unfold.

Personalities on AI is not a new idea. Civilisation gives personalities to its leaders (Gandhi famously loves to nuke people), Age of Mythology AIs determine how likely they are to use strategies such as turtling or rushing, and Unreal Tournament bots have favourite weapons.

Why Wasn’t Beating the AI Rewarding?

The main issue was that the AI played what it viewed as a “best move” every round. It simply assessed the game board, with no regard to diplomacy. If it needed to attack you it would. If you attacked it back, it simply didn’t care. It viewed the game as a mathematical puzzle to be solved, rather than a game against complex human players. Playing against our artificial intelligence resulted in an artificial game.

Our solution came from an Amiga game from 1989 called Nuclear War. In Nuclear War, you fought against various world leaders and tried to nuke their country from existence. Whoever managed to survive would win. Although simplistic, it was surprisingly fun watching your enemies get caught in personal vendettas and throw warheads at each other.

This “friends and enemies” system used a very simple metric: happiness. Each world leader had a variety of facial expressions which made it easy to judge their attitude towards you. Unsurprisingly, nuking people tended to make them unhappy very quickly. In addition, your enemies wouldn’t just get upset with you, but with each other. This meant that a single wayward missile could escalate into a sustained fight to the death.

Once again, this system has been used in many games, including Civilisation. An enemy nation with a high level of “happiness” is more likely to ally with you and send you gifts, whereas an enemy that hates you might invest a lot of resources into crushing your cities.

By adding a rudimentary happiness meter into our game, we allowed friendships and rivalries to brew. A game is more exciting when you develop a nemesis, or when teams and alliances form. Suddenly, the game became personal, and actions felt like they had weight. We also found that a visible happiness meter was important, otherwise the player wouldn’t understand what was happening. A simple happy face icon immediately conveys the idea that enemies can get “upset”, and watching the face change upon taking certain actions made it clear what consequences these actions were having.

The prisoner’s dilemma is a well known game theory concept, and many programmers have spent time trying to build the ultimate bot to compete in the iterated prisoner’s dilemma. Curiously, the winning strategy for many years was also the simplest: known as tit-for-tat, it simply copied the opponent’s move.

How Would the AI Cheat?

The problem in Infected 2 was often that the AI was simply looking at the short term perspective. The AI aims to maximise its score every turn: if this meant making an overall poor move, then it would do it anyway.

The easiest way to imagine it is this scenario:

Alice, Bob and Carol are playing war.

Alice has 100 soldiers. Bob has 75 soldiers. Carol has 150.

Neither Alice nor Bob can beat Carol.

However, Alice and Bob combined can beat Carol.

The problem was that the AI would do whatever would score it the most points. In the above scenario, that meant Alice would attack Bob: in the short term, an excellent move, but in the long term, disastrous. Not only is Alice making a move which dooms herself, she is condemning Bob to certain defeat as well. Bob is understandably upset.

This sort of situation is difficult to avoid, as seeing the bigger picture requires a complex reasoning beyond most simple AI. We tried to ensure “fairness” by making players less likely to be attacked if they were losing, or if they had been attacked recently. While not every game can apply a simple solution, its important to realise that players hate being attacked for no apparent reason.

While Infected 2 never made it past the alpha stage, it taught us some valuable lessons. Most importantly, that it’s not enough to just play against enemy bots: you want to be involved in the game, develop rivalries, and crush all those who stand against you.

AI Done Right

Many years ago, a game was published that seemed leaps and bounds ahead of the competition. Although a multiplayer game by design, the bots were good enough that it could be enjoyed single player. And, although by today’s standards it is poor, this game—Unreal Tournament—had AI which blew other games out the water.

We can look at an in-game screenshot to see some of what went into making a bot:

Skill was the main factor in determing bot behaviour: novice bots were slow, had to stand still to shoot, and were slow to turn around, while the higher level bots were faster, could dodge, had a bigger field of view and could use advanced weapon combo techniques.

Bots could then be futher modified with accuracy, alertness, camping, and strafing levels. “Personality” would be determined by combat style and favourite weapon, determining whether the bot liked to get up close and personal, or try and snipe from a distance. Bots would also taunt the player and seek revenge. Each of the 32 bots could be individually customised, meaning you could have 32 distinct personalities. Certain bots, such as Loque, became notorious amongst players.

All of these factors helped create bots which felt more human. While the game would still be good without this sophistication, it adds an extra, almost imperceptible layer of fun.

Conclusion

At the end of the day, you need to ask: what do you want from your AI? Are the enemies going to mindlessly rush the player and walk head-first into pits, or are you trying to develop something more, something that provides a more personal level of interaction with the player? Whatever you decide, remember three key points:

If bots make mistakes, then they feel more human, and less like a “pack of cards”.

If they deliberately make plays based on individual personality (or emotion, like revenge), then unpredictable and exciting gameplay is more likely to emerge.

If bots try to play cleverly, rather than short-sightedly, they are more likely to make the game fair to our eyes.(source:tutsplus)

 


上一篇:

下一篇: