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

分享《吃豆人》制作档案第四章:角色控制

发布时间:2013-12-12 16:44:30 Tags:,,,

作者:Jamey Pittman

“首先,你得学习如何控制怪物。看看红鬼、粉鬼和蓝鬼怎么集合的?控制两个怪比控制四个怪更容易。”——Chris Ayra,《吃豆人》的资深玩家

现在我们将更详细地分析Blinky、Pinky、Inky和Clyde,以便深入地理解为什么当处于追击模式时它们的行为会如此不同。它们追踪目标贴图的寻径逻辑是一样的,那么为什么追击吃豆人时每只鬼的行为都不同?答案有点简单:它们并不总是把吃豆人的贴图当作目标。在追击模式中,每只鬼都有计算自己的目标贴图的特定方法,这导致它们的独特个性。有些鬼把吃豆人占用的贴图当作目标,而其他的把它当作寻找下一个贴图的中间目标。有时候,鬼的目标贴图与吃豆人完全没有关系!不管鬼的目标贴图是什么,只要吃豆人撞上鬼,仍然会损失一条命。(请点击此处阅读本系列第一章第二章第三章第五章

据说,在发布《吃豆人》以前,岩谷彻和他的团队花了好几个月时间只是调整和改进鬼AI的活动。他们的努力体现在最终产品上:岩谷彻的团队用非常简单的逻辑和非常少的代码就让玩家误以为鬼的寻径非常复杂。

Blinky:这种红鬼的个性被恰当地形容为“影子”。在日本语中,玩家用“oikake”这个词来形容它的个性,这个词的意思是“撞上或追赶”。在迷宫中,Blinky似乎总是第一只发现吃豆人的鬼。它是四种鬼中最危险的一只,一旦发现吃豆人就会穷追到底。

Blinky(from home.comcast.net)

Blinky(from home.comcast.net)

在追击模式中,Blinky的定位方法是所有鬼中最简单最直接的,那就是把吃豆人的当前贴图作为自己的目标。在上图中,我们可以看到Blinky的目标贴图正是吃豆人当前占用的贴图。直接定位吃豆人的寻径逻辑导致Blinky成为一只非常顽固难缠的鬼。

关卡开始时,所有鬼的移动速度都是一样的,但Blinky的速度会根据迷宫里剩下的圆点的数量,每一回合速度翻一倍。当红鬼处于这种加速的状态时,就会被玩家叫作“Cruise Elroy”,但似乎没有人知道这个叫法是怎么来的或者它是什么意思。比如在第一关,当迷宫中只剩下20个圆点时,Blinky就会变成Elroy,且移动速度会变得至少和吃豆人一样快。更重要的是,它的分散模式行为在这时也会被修改,即把吃豆人的当前贴图当作自己的固定目标贴图,无论这个关卡中的剩余分散周期是多少(当进入/退出分散周期时,它仍然反转方向)。这导致Elroy继续追击吃豆人,而其他三只鬼还是像平常一样朝自己的角落前进。其实那还不算最坏的情况,当只剩下10个圆点时,Elroy会再次提速,这样就比吃豆人移动得还快了。随着关卡进展,即使当前剩下的圆点比前一关卡中的多,Blinky也会变成Elroy。下表显示了Elroy在每个关卡中变化的圆点计数和速度:

table A(from home.comcast.net)

table A(from home.comcast.net)

如果吃豆人被杀死,确定Blinky变成Elroy就更复杂了。当吃豆人死亡时,鬼和吃豆人就会被重置到起始位置;当继续玩时,Blinky的“Cruise Elroy”能力就被暂时闲置,直到橙鬼(Clyde)不再鬼屋里上下跳,朝着门口移动。直到这时,Blinky的速度和分散行为会保持正常状态,不管迷宫里还剩下多少圆点。一旦这个临时限制结束,Blinky就会根据圆点当前计数重新改变它的行为。

Pinky:被昵称为“粉粉”的粉鬼的移动被形容为“敏捷的”。在日本语中,它的个性被形容为“machibuse”,意思是“埋伏”,也许是因为它总是能够出乎意料地跑到吃豆人前面,截断玩家的去路。它的移动速度与Inky和Clyde一样,这意味着“敏捷的”其实是对“machibuse”的误译。Pinky和Blinky似乎经常合力围堵吃豆人。

在追击模式中,Pinky并没有把吃豆人的贴图直接当成目标。相反地,它选择距离吃豆人当前方向四个贴图的地方作为目标。下图显示了粉鬼如何根据吃豆人的方向确定目标:

Pinky1(from home.comcast.net)

Pinky1(from home.comcast.net)

如果吃豆人向左移动,Pinky的目标贴图就是向左距离吃豆人当前贴图四个贴图的地方。如果吃豆人向右移动,Pinky的目标就是相应地改成右边。如果吃豆人向下移动,那么粉鬼的目标誻 下向距离吃豆人四个贴图的地方。如果吃豆人向上移动,Pinky的目标就是向上和向左距离吃豆人四张贴图的地方。之所以产生这个有趣的结果是因为计算Pinky朝吃豆人移动的逻辑代码有一个小错误。这部分代码对于其他三种情况来说是运行正常的,但当吃豆人向上移动时,就会触发一个误把向左移动计算在内的漏洞(Inky的逻辑也存在这个问题)。Don Hodges的网站上有一篇好文章从代码的角度详尽地分析了这个漏洞,还提供了源代码和解决方案。

Pinky2(from home.comcast.net)

Pinky2(from home.comcast.net)

因为它的定位逻辑,Pinky成为最容易对付的鬼。通过改变方向,你就可以操纵它的下一步行动(如上图所示)。如果你面朝Pinky很近,它在撞上你之前就会转向。这是因为吃豆人距离Pinky太近,而Pinky现在的目标贴图在它的后面。在上图中,Pinky选择向上移动,因为向左移动会使它离目标贴图更远。有一种叫作“假转向”的技术,即玩家抖动控制杆导致吃豆人迅速改变方向,使鬼也随之改变方向。事实上,抖动是不必要的,当面临十字路口时,在Pinky决定走哪个方向以前快速反转方向就能把它甩掉了。

Inky:蓝鬼的个性被形容为“害羞的”。在日本语中,玩家用“kimagure”形容它,意思是“变幻无常的、情绪化的或脾气不稳定的”。Inky显然是四只鬼中最难预测的。有时候,它会像Blinky一样疯狂地追击吃豆人,有时候它会像Pinky一样跳到玩家前面,有时候它甚至会像Clyde一样漫步闲逛!事实上,Inky可能是所有鬼中最危险的一只,因为它的行为太没有规律可循了。“害羞的”并没有翻译出“kimagure”的意思,反而误导玩家以为Inky见到吃豆人时会害羞地跑开,但这种情况并不总是发生。

InkyA(from home.comcast.net)

InkyA(from home.comcast.net)

在追击模式中,蓝鬼使用的定位方式是四只鬼中最复杂的。它需要吃豆人的当前贴图/方向和Blinky的当前贴图来计算它的最终目标。为了确定Inky的目标,我们必须首先找到在吃豆人前进方向平移两个贴图(在上图中用绿色框出来的贴图)的贴图。现在想象一下,在红鬼的当前贴图的中心到平移贴图的中心之间画一个矢量,然后把这个矢量的长度翻一倍,使之超过位移贴图。新的、延展的矢量所指的贴图就是Inky的目标。

InkyB(from home.comcast.net)

InkyB(from home.comcast.net)

因为在介绍Pinky部分已经讨论过的原因,当吃豆人向上移动时,Inky的计算会产生向上两个和向左两个方向移动的错误(如上图所示)。另外三个方向(左、右、下)产生预期的结果:在吃豆人前进的方向上平移两个贴图。

Inky的定位逻辑导致,当Blinky离吃豆人很远时,它也会远离吃豆人,但随着Blinky逼近,Inky的目标贴图也会更近。这就解释了为什么当吃豆人远离Blinky时,Inky的行为似乎变化多端。与Plinky一样,Inky的路线通常会因为吃豆人转向或“假转向”而被改变。这对Inky的决策产生多大的或多小的影响,与那时候Blinky的位置有直接的关系。

Clyde:橙鬼的个性是“迟钝的”。在日本语中,他的个性被形容为“otoboke”,意思是“假装无知”,它的昵称是“Guzuta”,意思是“掉队的人”。事实上,Clyde的移动速度与Inky和Pinky是一样的,所以他的个性描述也有点儿误导玩家。它是最后一个出现的鬼,它与其他鬼的显著区别是,它对吃豆人表现得很害羞,当它没有在自己的角落里巡逻时,它就自顾自地玩。尽管没有像其他三种鬼那么危险,但他的行为有时候似乎也很难预测,所以仍然应该觉得它是危险的。

ClydeJ(from home.comcast.net)

ClydeJ(from home.comcast.net)

在追击模式中,Clyde的定位逻辑是根据它与吃豆人的接近程度变化的(在上图表现为绿色贴图)。它首先计算它的贴图和吃豆人的贴图之间的几何距离。如果二者之间的距离是8个或以上贴图,那么Clyde就与Blinky一样,把吃豆人所在的贴图当作目标。如果二者之间的距离少于8个贴图,那么Clyde就会像处于分散模式一样,朝着角落前进,直到它与吃豆人的距离拉开到8个或以上贴图。在上图中,因为这种定位逻辑,Clyde困在一个无限循环中(只要吃豆人一直处于那个位置)。虽然占用虚线边界外的任意贴图,Clyde的目标是吃豆人。在进入这个区域时,Clyde改变主意朝着他在分散模式下的目标前进。一旦它退出那个边界,他的目标就会再次变回吃豆人的当前贴图。结果是,Clyde会一直转圈,直到吃豆人移动到其他地方或模式发生变化。一旦你理解它的定位方式,你很容易就能避开Clyde。只要记住:如果你挡住它回到角落的路或它到达十字路口为了避开你,你却挡住了它的路,它就仍然是危险的。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

The Pac-Man Dossior

by Jamey Pittman

CHAPTER 4:

Meet The Ghosts

“First, you’ve got to learn how to control the monsters. See how the red, pink and blue are grouped together? It’s easier to control two monsters than four monsters.”—Chris Ayra, champion Pac-Man player

In the last chapter, we learned how a ghost follows a target tile through the maze. Now we will take a closer look at Blinky, Pinky, Inky, and Clyde to better understand why they behave so differently when in chase mode. They all share the same pathfinding logic for chasing a target tile, so how is it each one behaves differently when following Pac-Man? The answer is delightfully simple: Pac-Man’s tile is not always the target. Every ghost has a distinct method for calculating its target tile in chase mode, resulting in their unique personalities. Some of the ghosts use Pac-Man’s actual tile as the target; others only use it as an intermediate step to find another tile. Sometimes a ghost is targeting a tile that has absolutely nothing to do with Pac-Man at all! Regardless of where a ghost’s target tile is at the time, Pac-Man will still be killed if he gets in that ghost’s way.

Rumor has it Toru Iwatani and his team spent months doing nothing but tweaking and refining the ghost A.I. routines before releasing Pac-Man to the world. Their efforts show in the final product: Itawani’s team created the illusion of complex pathfinding by using very simple logic and very little code.

Blinky: The red ghost’s character is aptly described as that of a shadow and is best-known as “Blinky”. In Japan, his character is represented by the word oikake, which means “to run down or pursue”. Blinky seems to always be the first of the ghosts to track Pac-Man down in the maze. He is by far the most aggressive of the four and will doggedly pursue Pac-Man once behind him.

Of all the ghosts’ targeting schemes for chase mode, Blinky’s is the most simple and direct, using Pac-Man’s current tile as his target. In the pictures above, we can see Blinky’s target tile is the same as Pac-Man’s currently occupied tile. Targeting Pac-Man directly in this way results in a very determined and tenacious ghost who is tough to shake when he’s right behind you.

All ghosts move at the same rate of speed when a level begins, but Blinky will increase his rate of speed twice each round based on the number of dots remaining in the maze (if Pac-Man dies this is not necessarily true – more on this in a moment). While in this accelerated state, Blinky is commonly called “Cruise Elroy”, yet no one seems to know where this custom was originated or what it means. On the first level, for example, Blinky becomes Elroy when there are 20 dots remaining in the maze, accelerating to be at least as fast as Pac-Man. More importantly, his scatter mode behavior is also modified at this time to keep targeting Pac-Man’s current tile in lieu of his typical fixed target tile for any remaining scatter periods in the level (he will still reverse direction when entering/exiting a scatter period). This results in Elroy continuing to chase Pac-Man while the other three ghosts head for their corners as normal. As if that weren’t bad enough, when only 10 dots remain, Elroy speeds up again to the point where he is now moving faster than Pac-Man. As the levels progress, Blinky will turn into Elroy with more dots remaining in the maze than in previous rounds. Refer to Table A.1 in the appendices for dot counts and speeds for both Elroy changes, per level.

Determining when Blinky turns into Elroy can become more complicated if Pac-Man is killed. The ghosts and Pac-Man are reset to their starting positions whenever a life is lost and, when play continues, Blinky’s “Cruise Elroy” abilities are temporarily suspended until the orange ghost (Clyde) stops bouncing up and down inside the ghost house and moves toward the door to exit. Until this happens, Blinky’s speed and scatter behavior will remain normal regardless of the number of dots remaining in the maze. Once this temporary restriction is lifted, however, Blinky will resume changing his behavior based on the dot count.

Pinky: Nicknamed “Pinky”, the pink ghost’s character is described as one who is speedy. In Japan, he is characterized as machibuse, meaning “to perform an ambush”, perhaps because Pinky always seems to be able to get ahead of you and cut you off when you least expect it. He always moves at the same speed as Inky and Clyde, however, which suggests speedy is a poor translation of the more appropriate machibuse. Pinky and Blinky often seem to be working in concert to box Pac-Man in, leaving him with nowhere to run.

In chase mode, Pinky behaves as he does because he does not target Pac-Man’s tile directly. Instead, he selects an offset four tiles away from Pac-Man in the direction Pac-Man is currently moving (with one exception). The pictures below illustrate the four possible offsets Pinky will use to determine his target tile based on Pac-Man’s orientation:

If Pac-Man is moving left, Pinky’s target tile will be four game tiles to the left of Pac-Man’s current tile. If Pac-Man is moving right, Pinky’s tile will be four tiles to the right. If Pac-Man is moving down, Pinky’s target is four tiles below. Finally, if Pac-Man is moving up, Pinky’s target tile will be four tiles up and four tiles to the left. This interesting outcome is due to a subtle error in the logic code that calculates Pinky’s offset from Pac-Man. This piece of code works properly for the other three cases but, when Pac-Man is moving upwards, triggers an overflow bug that mistakenly includes a left offset equal in distance to the expected up offset (we will see this same issue in Inky’s logic later). Don Hodges’ website has an excellent article giving a thorough, code-level analysis of this bug, including the source code and a proposed fix—click here to go there now.

Pinky is the easiest ghost to exert control over thanks to his targeting scheme. By changing direction, you can dictate where Pinky will turn next when he is nearby (see above picture). If you are facing off closely with Pinky, he will turn before he reaches you if he can. This happens due to the fact Pac-Man has come close enough to Pinky for Pinky’s target tile to now be behind him. In the picture above, Pinky chooses to turn up at the intersection because moving left would have taken him further away from his target tile. The longest-lived example of this is the technique known as “head faking”. This is where the player shakes the joystick to cause Pac-Man to rapidly change direction back and forth, hopefully causing a ghost to change course in the process. As it turns out, the shaking is not necessary—one well-timed, quick reversal of direction towards Pinky just before he decides what to do at an upcoming intersection is all that is needed to get him off your tail.

Inky: The light-blue ghost is nicknamed “Inky” and his character is described as one who is bashful. In Japan, he is portrayed as kimagure, meaning “a fickle, moody, or uneven temper”. Perhaps not surprisingly, Inky is the least predictable of the ghosts. Sometimes he chases Pac-Man aggressively like Blinky; other times he jumps ahead of Pac-Man as Pinky would. He might even wander off like Clyde on occasion! In fact, Inky may be the most dangerous ghost of all due to his erratic behavior. Bashful is not a very good translation of kimagure, and misleads the player to assume Inky will shy away from Pac-Man when he gets close which is not always the case.

Inky uses the most complex targeting scheme of the four ghosts in chase mode. He needs Pac-Man’s current tile/orientation and Blinky’s current tile to calculate his final target. To determine Inky’s target, we must first establish an intermediate offset two tiles in front of Pac-Man in the direction he is moving (represented by the tile bracketed in green above). Now imagine drawing a vector from the center of the red ghost’s current tile to the center of the offset tile, then double the vector length by extending it out just as far again beyond the offset tile. The tile this new, extendend vector points to is Inky’s actual target as shown above.

For the same reasons already discussed in Pinky’s case, an overflow error occurs with the intermediate offset tile generated for Inky’s calculation when Pac-Man is moving up resulting in an offset tile that is two tiles above and two tiles to the left (see above picture). The other three orientations (left, right, down) produce the expected result of an offset two tiles in front of Pac-Man in the direction he is moving.

Inky’s targeting logic will keep him away from Pac-Man when Blinky is far away from Pac-Man, but as Blinky draws closer, so will Inky’s target tile. This explains why Inky’s behavior seems more variable as Pac-Man moves away from Blinky. Like Pinky, Inky’s course can often be altered by Pac-Man changing direction or “head-faking”. How much or how little effect this will have on Inky’s decisions is directly related to where Blinky is at the time.

Clyde: The orange ghost is nicknamed “Clyde” and is characterized as one who is pokey. In Japan, his character is described as otoboke, meaning “pretending ignorance”, and his nickname is “Guzuta”, meaning “one who lags behind”. In reality, Clyde moves at the same speed as Inky and Pinky so his character description is a bit misleading. Clyde is the last ghost to leave the pen and tends to separate himself from the other ghosts by shying away from Pac-Man and doing his own thing when he isn’t patrolling his corner of the maze. Although not nearly as dangerous as the other three ghosts, his behavior can seem unpredictable at times and should still be considered a threat.

During chase mode, Clyde’s targeting logic changes based on his proximity to Pac-Man (represented by the green target tile above). He first calculates the Euclidean distance between his tile and Pac-Man’s tile. If the distance between them is eight tiles or more, Clyde targets Pac-Man directly just as Blinky does. If the distance between them is less than eight tiles, however, Clyde switches his target to the tile he normally uses during scatter mode and heads for his corner until he gets far enough away to start targeting Pac-Man again. In the picture above, Clyde is stuck in an endless loop (as long as Pac-Man stays where he is) thanks to this scheme. While occupying any tile completely outside the dashed perimeter, Clyde’s target is Pac-Man. Upon entering the area, Clyde changes his mind and heads for his scatter target instead. Once he exits the perimeter, his target will change back to Pac-Man’s current tile again. The end result is Clyde circling around and around until Pac-Man moves elsewhere or a mode change occurs. Clyde is fairly easy to avoid once you understand his targeting scheme. Just remember: he is still dangerous if you manage to get in his way as he runs back to his corner or before he can reach an intersection to turn away from you.(source:home.comcast)


上一篇:

下一篇: