gpt4 book ai didi

algorithm - Pong: Racket 如何知道球会击中哪里?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:16:24 25 4
gpt4 key购买 nike

在实现 Pacman 和 Snake 之后,我正在实现下一个非常非常经典的游戏:Pong。

实现非常简单,但我只剩下一个小问题。当其中一个桨(我不确定它是否被称为桨)由计算机控制时,我很难将它定位在正确的位置。

球有一个当前位置、一个速度(目前是恒定的)和一个方向角。所以我可以计算出它将撞击计算机控制桨的侧面的位置。所以我可以把桨放在那里。但是然而在真实的比赛中,电脑的 Racket 是有可能打不中球的。我怎样才能实现这个概率?

如果我只使用计算机的 Racket 击中球的概率(假设为 0.5),问题就解决了,但我认为事情并没有那么简单。

从原始游戏来看,我认为概率取决于当前 Racket 位置与球将击中边界的位置之间的距离。

有人知道这是如何计算的吗?

最佳答案

引用非常有趣的书“Racing the Beam”(Google 图书:http://books.google.co.uk/books?id=DqePfdz_x6gC&lpg=PP1&dq=racing%20the%20beam&pg=PA40#v=onepage&q&f=false),原始技术是:

To help simulate the human error inherent in precise paddle positioning, The AI paddle skips its adjustment every eight frames. The resulting behaviour is visibly unnoticeable, but it allows the computer player's aim to drift enough that it occasionally misses the ball. It is also technically trivial to implement, requiring only a single mask and the binary AND operation, for which there exists a corresponding 6502 instruction. The programmer can test if the result is zero with another single opcode, branching if needed to skip the instructions that move the paddle.

Even this behaviour must be modified slightly for the game to work at all. If the AI player simply stopped tracking the ball every eight frames, it would be hopelessly out of sync within a few seconds. To prevent this, the AI follows a secondary ball-tracking scheme near the top and bottom of the playfield. If the ball collides with one of these walls while the paddle is also aligned with it, the paddle readjusts, recovering from any drift that had accumulated since the ball last struck the wall. The result is a stochastic misalignment and realignment of computer paddle and ball.

关于algorithm - Pong: Racket 如何知道球会击中哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4577814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com