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

阐述游戏AI设计的两个禁忌及解决方法

发布时间:2012-09-11 17:19:17 Tags:,,

作者:Jon Shafer

我在过去年几负责了多款游戏的AI设计工作,我从中收获的一个最基本,可能也是最令人沮丧的经验就是:创建一个出色的AI真是出奇地困难。不但制作一个符合最低标准的AI很难,即使你真的做出一个极为智能的AI也并不意味着它就是一个优秀的AI。毕竟,没有玩家希望自己被一个无情的对手彻底打倒。有些人只是希望在游戏中过把角色扮演瘾,或者希望AI能够手下留情,即便它真的很强大。即使是那些追求挑战性的玩家也并不希望输掉每场游戏。

recipe_book(from gamasutra)

recipe_book(from gamasutra)

那么,设计师或AI程序员在这一点上首先要准备什么对策呢?无论你负责的是哪种工作,答案都一样:确定你的目标。

重中之重

“编写AI太难了”已经不算什么新鲜的经验之谈了,但开发者还必须掌握另一点:让玩家看到并且相信才是最重要的。AI可以作弊,扮演或脱离某个角色,制定愚蠢的决策,怎么样都可以——让玩家乐在其中才是关键。开发者常会遇到自己完全没想到的功能竟会成为玩家最大的乐趣来源这种情况,“什么,你在游戏中最喜欢的东西居然是帽子?它只用一天时间就可以添加到游戏中!”切中要害是所有游戏开发中的最重要之事,但它对AI来说尤为关键。

AI与其他任何系统一样,如果玩家并不能从中获得乐趣,那么它编写得再好也不会有价值。开发者通常很容易被不时涌现的大量难题所困,却没有发现自己在无法为游戏体验增色的内容上花了太多精力。编写AI特别容易遇到这种情况,因为多数时候你无法知道自己的代码运行效果是否同预期一致,更别提它是否将有出色表现了。

那么,现在你已经制定了一些目标,并打算老老实实地遵循这些目标。下一步就是确定游戏AI可能发生哪些错误。如果玩家认为AI太随机或太愚蠢,那么这个AI设计就是失败的。AI开发者的职责就是尽量避免这些错误。我们首先来谈谈怎样让AI显得更合理而不仅仅是随机性。

不可设计随机AI

让AI降低随机化的一个策略就是减少其随机性。这是很明显的答案,但要注意如何让AI呈现预见性或奇异性则是一个重要的设计决策。也许在战争开始的时候,就可以通过单个回合让玩家确定所有AI单位的进攻强度,而非AI每回进攻的时候就制作一个随机强度。这些是值得开发者考虑的技巧,但最终选择哪种方式则要取决于游戏目标以及设计师想要游戏呈现的感觉。

另一个策略可能有点违反直觉,即让AI解释游戏当前发生的状况,以此让AI看起来更智能一些。某个首领是否正在组建大部队以图摧毁人类?让AI来“报信”!

你可能会想,这就是提前通知玩家,令其做好应对准备,这样AI就无法真正打垮玩家。但同时这也可以提高玩家警惕,让他们开始担忧AI下一步行动是什么,这样他们就会预先制定计划。等到AI确实带上大队人马现身时,玩家就会开始想:“没错,看来AI果然早就算计好这一步了”。如此,玩家就会更注意AI接下来的动向,比起简单地偷袭,这会让AI显得更为智能。

玩家并不清楚AI私低下有什么举动,并且他们也不在乎这一点。开发者应该向玩家呈现自己的劳动成果。开发者可以花些时间制作看似“无价值的”AI,让后者呈现电脑所知道的情况,即使这与实际游戏玩法影响不大。数行可令AI呈现智慧感的代码所发挥的作用,可能比一个庞大而复杂的智能AI系统要管用得多。

当然,AI可以神通广大,无所不能,但最重要的是它能够恰如其分地呈现在玩家面前。这就涉及了下一个重要内容……

不可设计愚蠢的AI

AI大军上门了,那么现在又该如何?让我们首先确定一下优先顺序。

避免AI显得愚笨这一比让其显得智能更重要。我的意思是什么呢?

AI被贴上“坏”标签并不是发生在它无法准确无误地执行某项操作的时候,而是在它甚至无法使尽全力杀死人类军队中的一个伤员的时候。

开发者首先要重视的就是减少AI所犯的这种明显错误。假如AI可以执行某项特殊行动,但若没有剔除其所有的“愚昧性”,这个功能并不会有多大意义。玩家只要发现AI的一个愚蠢行动,他们就会立即对自己的电脑对手失去信任感,而游戏所呈现的真实幻象也会消失殆尽。

那么,优秀的AI一般都不笨。那么,我们又该如何制作“智能”的AI?在这里我不会详述算法等具体内容,但我认为有必要提及一些普遍原则。

关键就在于分清主次,并贯穿始终。专注于制作通常很简单,但在特殊方面有过人之处的AI。千万不可制作各个方面都无懈可击的人工对手。AI背后的行动环节越少,程序员就越容易为其添加性能并优化现有内容。

要创建一个支持频繁改动的系统。AI是游戏中最常迭代的内容之一,因此要简化这个系统。假如每次开启AI代码都会让人抓狂,这就会极大降低开发者改进游戏的积极性。

让AI尽量快速地执行简单的任务,这一点非常重要。只有基本功能到位了,才可以再添加复杂功能。AI是游戏开发中少数几个崇尚简洁性的环节之一。其设计本身并不是问题,但如果在其中投入过多时间却可能产生不必要的复杂性,并且转移人们对高级目标的注意力。

神经网络和基因算法等高级AI技术极为强大,并且可以做出一些惊人的效果,但不幸的是对多数游戏而言,它们很可能是“祸害”,尤其是那些需经历多次迭代的游戏(游戏邦注:而通常情况下,游戏经过越多次迭代就有可能越完善)。用一句话强调上述观点,那就是:AI越简单,其可行性就越高,并且越容易优化。

设计师和AI

假如游戏设计师及AI程序员并非同一人,那么任何复杂游戏(尤其是战略游戏)中的AI成功的机率就会大大降低。

AI本质上只是众多游戏系统中的一个环节。所以让非游戏设计师来部署整个游戏中的这么一个重要环节,是不是有点不合适?设计师需花大量时间和精力确定所有系统的目标及关注点——AI也是其中之一。简单地将这项任务移交给程序员,往往容易酿成大错。程序员的职责是编写高效、稳定且易于维护的代码,确保游戏体验具有趣味性才是设计师的职责所在。这些目标并不具有一致性,如果不提供一个方向,程序员一般只会像对待自己往常的工作那样创建系统和编码。

但这并不是说如果游戏设计和AI设计不是同一个人或团队完成,这个游戏项目就必败无疑。但这确实需要双方团队具有高度组织性和警觉性。设计团队需要确保所有AI行为的目标,都像其他系统一样清楚标示出来。

即使是这样,设计AI也仍然具有其他游戏系统鲜见的挑战性,因此最理想的情况是游戏设计师和AI程序员就是同一个人。电脑可能擅长处理某方面事物(例如同时管理多个侦察单位),但在某此方面可能缺乏可行性(比如在27个回合中推出三次交叉进攻)。如果设计AI的人同时了解技术局限性以及玩法可行性,那么就相对更有可能实现项目中的AI目标。

总结

当AI程序员不是件容易的差事。这一工作的成果通常并不明显,而这其中又多归咎于一些很大很显示的问题。但这些灰色区域也有一些创新空间。坚定地专注于终极目标以及避免将简单事情复杂化,可能有助于AI开发者成功实现目标。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

The Recipe for Good AI

by Jon Shafer

You can read more of Jon’s thoughts on design and project management at his website. You can also find him on Twitter.

I’ve worked on AI in a number of games over the years. Every nugget of wisdom I’ve picked up along the way points to one basic, possibly depressing lesson: creating a good AI is exceptionally difficult. Not only is it tough to make one that simply meets the incredibly low bar of not completely falling on its face – but even if you make a really, really smart AI it doesn’t mean you’ve made a good AI. After all, not everyone wants to be ruthlessly eviscerated by a merciless opponent. Some people are looking to roleplay, or just would prefer the AI keep the gloves on even when it has an advantage. Even those who want a serious challenge wouldn’t enjoy losing every game.

So what is the first step for a designer or AI programmer in this quest to prepare a five-star meal? No matter your task, the answer is always the same: identify your goals.

What Really Matters

Okay, so the lesson of “writing AI is hard!” is neither particularly useful nor surprising, but there is another so important developers must embrace it: all that matters is what players see and believe. Really. That’s it. The AI can cheat, act in or out of character, make dumb decisions, whatever – as long as the player is having fun that’s what counts. Developers are often surprised by which features players get the most enjoyment out of. “Wait, your favorite part of the game is the hats? That only took a day to implement!” Getting the most bang for your buck is important in all aspects of game development, but it’s absolutely essential with AI – the biggest meal of the year calls for the best ingredients money can buy.

AI is just like any other system in that there is zero value in it being well-engineered if the player doesn’t actually get something out of it. It’s incredibly easy to get bogged down in the details of how to solve the myriad of difficult problems that pop up, and never step back and realize you’re spending a ton of effort on a feature that doesn’t really contribute to the actual experience of playing the game. The risk of this occurring is particularly high with AI because much of the time it’s hard to tell if your code is even doing what youthink it is, let alone doing it well.

Okay, so you’ve laid down some goals and have vowed to dutifully follow through on them. The next thing our recipe calls for is to identify what can go wrong with a game’s AI. The AI has failed if a player considers it to be either 1) too random, or 2) dumb. The job of an AI developer is to sidestep these pitfalls in any way possible. Let’s first talk about how to make an AI appear rational, and not simply random.

Preventing Random AI

A strategy for making an AI look less random is to actually make it less random. Sure, it sounds obvious, but how predictable or wacky an AI should behave is an important design decision. Perhaps instead of doing a random roll each time an AI unit can attack, a singleroll could be done at the beginning of the war to determine how aggressive all of the AI’s units will be. Techniques like this are always worth considering, but in the end the best approach will be dictated by the project goals and what kind of feel the designer wants the game to have.

Another tactic that, perhaps counter-intuitively, makes an AI seem much smarter is to have it explain what it’s doing. Is a leader building up a massive army that he plans on using to crush the human? Have him say so!

I know what you’re thinking, and sure, this gives the player advanced warning and makes it harder for the AI to actually, you know, crush the player. But at the same time it alsoengages the player, gets him or her to worry about what the AI’s up to, to start coming up with plans, to adapt. When the AI does eventually show up with a big army, the players will then think to themselves: “Ah ha! So the AI was actually planning this for a while.” Players will naturally pay more attention to what the AI says in the future. It also makes the AI appear more intelligent than if it had it simply executed a perfectly-timed sneak attack and never once made a peep about it.

Players have no idea what the AI is doing under the hood, and they don’t even care. It’s on the developers to make sure the fruits of their labor are seen. It can be worthwhile to spend time on “fluff” AI which shows off what the computer knows, even if there’s no actual gameplay effect at work. A few lines of code that generate an illusion of a smart AI will often have a much greater impact than a massive, complex system which results in an actually smart AI.

Of course, the AI can brag all it wants, but at the end of the day once it shows up on the player’s doorstep it still needs to fight competently! Which brings us to our dish’s next key ingredient…

Preventing Dumb AI

Okay, so the AI army has actually come a’knocking… now what? Well, let’s first establish what our priorities are.

It’s much more important for an AI to be not dumb than for it to be smart. What do I mean by that?

An AI is labeled “bad” not when it fails to execute a flawless pincer maneuver, but when it fails to use its full-strength God Unit to kill a wounded one belonging to the human. “This AI is so stupid, a real player would never have let that unit get away!”

Developers should always focus first and foremost on eliminating the number of obviousmistakes an AI makes. It’s awesome if the AI is able to pull off that pincer move, but it’s nothing but a “nice to have” feature until all of the dumbness has been sifted out. If players spot just one stupid move they’ll immediately lose all faith in their computer opponents, and once that happens there’s no going back – the illusion is forever broken.

Okay, so a good AI isn’t dumb – fair enough. What about making it, you know, smart? I won’t go into specific algorithms or anything, but there are a few general principles worth noting.

The key is setting good priorities and following through on them (noticing a pattern?). Focus on making an AI that is generally simple, but strong in a few areas that will really stand out to players. Setting out to create artificial opponents that are unbeatable in every way is a fool’s errand (unless you have five years during which the gameplay rules never change – good luck with that!). The fewer moving parts an AI has under the hood, the easier it will be for a programmer to add new features and improve existing ones.

Build a system that is designed to change – a lot. A game’s AI is one of the pieces that needs the most iteration and you want it to be easy to jump in and change the behavior in ways that are obvious. The more fiddling that is necessary, the less likely it is that developers will be able to – or worse, want to – go in and change things. If opening up the AI code always results in a hearty sigh, it becomes much easier to give up and proclaim “ehhh, it’s fine the way it is!”

It’s crucial to get the AI performing simple tasks competently as quickly as possible. Once the basics are in place, complexity can always then be added. AI is one of the very few areas of game development where doing too much design can be harmful. The design itself is rarely the problem, but spending too much time on it before anyone sees in-game results often leads to superfluous complexity and a diminished focus on the high-level objectives.

Advanced AI techniques like neural networks and genetic algorithms are incredibly powerful and can do some amazing things – unfortunately, they’re terrible for most games, especially those which undergo significant iteration (and typically, the more iteration you do the better). To emphasize my point from above: the simpler an AI is, the more likely it is to work and to be easily improved. When the development team has less control over what’s going on it becomes much, much harder to achieve focused, narrowly-defined goals.

The Designer and the AI

The odds of your AI entrée being a hit with any complex game (particularly those in the strategy genre)  is dramatically reduced if the game designer and AI programmer aren’t the same person.

At its core, the AI is just one gameplay system among many. Do you want a non-designer making the plan for one of the most important and salient features in the entire game? A designer needs to spend significant time and effort establishing what the goals and focus should be for all systems – the AI is no exception. Simply handing off this to a programmer is usually a recipe for disaster. The job of a programmer is to write code that is efficient, robust, and easy to maintain – it’s a designer’s job to ensure the in-game experience is fun. Those goals do not naturally align. When no direction is given, programmers will typically architect and code a system just like they always would.

That’s not to say a game is outright doomed to failure should the game design be done by one person or team, and the AI by another. However, this does require both groups to be extremely organized and vigilant. The design team needs to make sure that all goals for expected AI behavior are clearly outlined, just as they would do with any other system.

Even so, designing an AI presents significant challenges that other gameplay systems lack, which is why it’s often preferable for the game designer and AI programmer to be one in the same. There are a number of problems that AI simply cannot solve in an environment where an answer is needed within seconds, at the very most. There are some tasks computers naturally excel at, and others that it finds nearly impossible – managing multiple scout units simultaneous is a piece of cake… building and launching a three-pronged, multi-theatre invasion in exactly 27 turns is, uh, not. While not always feasible, when the individual designing the AI also understands the technical limitations and opportunities in play it’s much more likely a project’s AI goals will be achieved.

Conclusion

Being an AI programmer is a tough job. The results of one’s work are often nebulous, and when they’re not it’s usually because of some big, obvious problem. But that grey area also leaves plenty of room for creativity and interesting problems to solve. A splash ofunwavering focus on the end goal and a pinch of avoiding getting bogged down in complexity for complexity’s sake should ultimately make for a rather tasty dish. Good luck in the AI kitchen!(source:gamasutra


上一篇:

下一篇: