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

如何创造出具有乐趣的游戏AI

发布时间:2015-04-14 16:44:37 Tags:,,,,

作者:Darran Jamieson

创造优秀的人工智能作为计算机对手是件很困难的事。为一款国际跳棋般的游戏编写程序极具挑战;而添加让人信服的AI可能需要比创造游戏本身花费更长的时间。但是当我们在创造AI时,我们真正在做些什么呢?检查游戏面板上每个可能的移动是否重要,或者我们能否作弊并让它随机移动?AI需要做什么以及(最重要的是)我们该如何确保游戏足够有趣?

优秀的AI vs.有趣的AI

“AI”这个词真的具有非常广泛的意义,AI的类型也是取决于游戏。就像《太空入侵者》,《马里奥》或《终极塔防》等非对称型游戏允许玩家能够轻松地穿越敌人的围攻。因为“团队”是不平衡的,所以这些游戏倾向于使用没有声音的AI。而像《星际争霸》,《街头霸王》以及《文明》等对称型游戏则希望玩家能够打败基于同等竞争条件的对手,所以它们便需要更复杂的AI。

而最重要的还是游戏应该具有乐趣。玩家喜欢挑战,不希望自己不断失败。实际上,像西洋棋等游戏如果被“解决”了便意味着它能够创造一个无敌的AI。

当我和团队致力于我们的计算机/桌面游戏《Infected》时,我们创造了具有第一级威胁性的AI,以避免不会在一开始就吓到玩家。最初的游戏AI较为简单,计算机将积极游戏,并完全专注于获得高分而未多加考虑防卫。

尽管AI很弱,但是我们发现一些新玩家仍会被击败并失去兴趣。我们多次修改了AI,但是对于某些玩家来说它仍然太具有挑战性。最终我们选择删除了AI,所以游戏每次都只是进行一些随机的移动。尽管一些玩家仍会失败,但这却有效地挽留了用户留存,并让我们能够在一些更高的关卡中重新引入“较厉害的”AI。

infected(from tutsplus)

infected(from tutsplus)

在各种类型的游戏中我们能够看到“太厉害的”AI问题:就像带有拥有360度的视野的bot的FPS游戏,或者针对带有完美反应的bot的打斗游戏。对抗这些AI并不能真正教会玩家如何有效地游戏:它只能教会玩家如何与bot“游戏”,尝试着在算法中找出能够轻松消灭对方的缺陷。

这并不是说所有的AI都是糟糕的,相反地,优秀的AI是具有多面性的。它可能会犯错,但却会尝试着避免掉进同样的特性中。比起让AI每次都能完美地玩游戏,提供给AI适应能力(从而赋予游戏玩法多样性)能够带给玩家更多娱乐感。

让他们像人类一样

在创造了《Infected》后,我们简单地规划了游戏续集《Infected 2》。游戏仍然是基于同样的假设,但从更大规模上来看,它与经典的桌面游戏Risk相似。因为游戏较大,所以我们必须创造出完善的AI:能够在较长的游戏过程中确保玩家具有乐趣,并且多个AI之间也能够相互竞争。

我们添加了早前的AI,并且发现它存在一些问题。AI是可预测的,但仍然存在一些可得到完善的内容。更大的问题还是关于AI的态度,即它是如何游戏的。

主要存在3大问题:

首先,与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游戏,《Nuclear War》。在《Nuclear War》中,玩家需要与各种世界领导者相抗衡并尝试着攻击他们的国家。任何能够成功活下来的人都将获得胜利。尽管游戏很简单,但是看到敌人陷入个人恩怨并彼此抗衡的时候玩家总是能够感受到巨大的乐趣。

这种“朋友和敌人”的系统使用了一种非常简单的度量标准:幸福感。每个世界领导者拥有各种面部表情从而让玩家能够很容易判断他们对自己的态度。不出所料,攻击别人会快速让他们感到不快。此外,你的敌人也不会只是对你生气,你也会对他们感到生气。这意味着你们彼此间的矛头将进一步升级为持续的致命打斗。

再一次地,这一系统也出现在许多游戏中,包括《文明》。具有较高“幸福感”的敌方国家更有可能与你结盟并向你赠送礼物,而讨厌你的敌人也会投入更多资源去想办法摧毁你的城市。

通过添加基本的幸福指标到游戏中,我们能够在此酝酿友谊与竞争。当你创造一个强硬的对手或当团队和联盟形成时,游戏将变得更有趣。突然间游戏变得更有个性,行动也变得更有分量。我们同时也发现有形的幸福指标很重要,否则玩家便不能理解发生了什么。简单的笑脸图标也代表敌人的“沮丧”,基于特定行动而改变的脸部表情能够让玩家清楚地看到这些行动所具有的结果。

囚徒困境是有名的游戏理论概念,许多程序员花了许多时间尝试着创造终极bot在迭代的囚徒困境中竞争。有趣的是,维持多年的获胜策略仍然是最简单的:也就是我们所熟悉的以牙还牙,即复制对手的移动。

AI是如何作弊的?

《Infected 2》的问题在于AI经常着眼于短期视角。每一回合AI的目标都是提高分数:如果这意味着创造出糟糕的移动,不管怎样它之后还是会这么做。

想象这种情况的最简单方法是:

Alice,Bob和Carol身处于战斗中。

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

Alice和Bob都不能打败Carol。

然而Alice和Bob联合的话便能够打败Carol。

问题在于AI将竭尽全力去获得最多分数。在上述情况下,Alce将攻击Bob:就眼前来说,这是很好的选择,但从长期看来,这会带来灾难性的的结果。Alice不仅会做出伤害自己的行动,同时还会谴责Bob的战败。如此Bob的失落便是有道理的。

这种情境是难以避免的,就像更大的场景需要复杂的推理而不是简单的AI。我们尝试着在玩家失利后,或最近曾遭受到攻击时通过让他们避免遭遇攻击而确保“公平”。尽管并不是每一款游戏都会使用简单的解决方法,我们却必须意识到玩家无理由地讨厌被攻击。

尽管《Infectd 2》还未通过测试阶段,它却带给了我们一些非常有价值的教训。最重要的是只是与敌方bot相对坑是不够的:你总是想要参与到游戏中,创造竞赛,并消灭所有与你对抗的人。

使用得当的AI

多年前发行的一款游戏似乎一直走在竞争的优势地位。尽管从设计上来看那是一款多人游戏,但是游戏中的bote却非常出色,让玩家能够感受到单人游戏的乐趣。尽管从今天的标准看来,这款游戏,也就是《虚幻竞技场》并不是特别突出,但是它的AI却远超于许多其它游戏。

我们可以从游戏截图中看到其中bot的构成:

screenshot(from tutsplus)

screenshot(from tutsplus)

技能是决定bot行为的主要元素:新手bot行动较为缓慢,需要站着不动才能射击,并且只能缓慢地转身,而更高级别的bot则速度较快,能够躲避攻击,并且拥有更广阔的的视野,还能使用高级的武器组合技巧。

然后bot可以基于精确,机敏,露营与扫射等级别而得到进一步优化。bot的“个性”将由战斗风格与武器所决定,并决定bot是否想要靠近玩家或尝试着保持一定距离。bot同样也会嘲弄玩家并寻求复仇。在32个bot中,每一个bot都是基于个体定制,即意味着你将面对32个不同的个性。像Loque等bot在玩家之间便特别受欢迎。

所有的这些元素都能够创造出更具有人性的bot。尽管没有这些复杂的元素游戏也能够非常优秀,但这却能够添加一个细微的乐趣层面。

结论

最后,你需要问:你想要从AI中获得什么?敌人是否会盲目地冲向玩家并一头栽进坑里,还是你会尝试着创造出能够与玩家进行互动的更有个性的对手?不管你做出怎样的决定你都需要牢记这三个要点:

如果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:gamedevelopment)

 


上一篇:

下一篇: