台球人工智能

发布于 2024-08-31 12:16:00 字数 273 浏览 9 评论 0原文

我用 Java 实现了一个台球游戏,一切正常。这是一款多人游戏,但尽管如此,也应该可以单独玩。为此,我尝试实现一个简单的 KI。目前,KI 只是随机选择脉冲的方向和随机强度(不知道正确的英文单词)。当然,这个人工智能非常糟糕,不太可能挑战玩家。

于是我就想过改进KI,但是有几个很难解决的问题。首先我想到的是选择最近的球并尝试将其直接放入最近的洞中。这并没有那么糟糕,但如果中间有其他球,它就不再起作用了。此外,这并不能解决计算脉冲强度的问题。

那么有什么一般性的建议吗?或者有什么想法吗?最佳实践?

Im implementing a pool billiard game in Java and it all works fine. It is a multiplayer game, but nevertheless, it should also be possible to play it alone. For this purpose I'm trying to implement a simple KI. At the moment, the KI choose just randomly a direction and a random intensity of the impulse (don't know the correct english word for that). Of course this AI is very poor and unlikely to ever challenge a player.

So i thought about improving the KI, but there are several hard to solve problems. First I thought of just choosing the nearest ball and to try to put it directly into the nearest hole. This isn't that bad, but if there other balls in the line between, it isn't really working anymore. Additionally this dosn't solve te problem of calculating the intensity of the impulse.

So are there any general advice? Or any ideas? Best practices?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦初启 2024-09-07 12:16:00

计算游戏的一“步”结果需要多少 CPU 时间和内存?您有能力分析不止一招吗?如果做起来相对便宜,只需选择 N 个随机方向/脉冲,计算结果并选择最好的一个。您可以消除一些“棘手”的情况,即在多次碰撞后球落入袋中。另外,为了简化,您可以限制每次移动的模拟时间(即不要等到所有球都停止,只需计算前 T 秒)。

这样,您就可以拥有不同级别的计算机玩家 - 较高的 N(和 T)对应于较高的游戏级别。

How much CPU time and memory does it take to calculate the results of one "move" of the game? Can you afford to analyze more than one move? If it's relatively cheap to do, just pick N random directions/impulses, calculate the results and pick the best one. You may eliminate some "tricky" cases, when ball goes to pocket after too many collisions. Also, to simplify, you can limit the simulation time for each move (i.e. don't wait until all the balls stop, just calulate the first T seconds).

This way, you can have computer players of different level - the higher N (and T) correspond to higher play level.

爱的故事 2024-09-07 12:16:00

根据台球比赛的不同,您通常有两个任务

评估桌子上的情况(获得可能的击球)

  • 在完美的场景(完美的瞄准,完美的击球)中,所有可能的击球都同样困难且如果您只考虑直接击球到一个球,那么您需要分析的最多只有 6 个球 xn 个球的情况(分析简单的标准 - 击中两个球只需要额外的 n^2 个球 x 6 个球的情况)。对于每种情况,确定它们是否可能都需要简单的分析(除非您正在进行非常现实的碰撞模拟)。因此,在非常简单的模拟中,您可能想要尝试构建所有可能的情况并对它们进行排名。要分析离岸击球,您可能需要镜像球和洞。

  • 或者,在列举可能的情况时,您可以简单地对桌子进行线扫描,标记非法投篮的区域,并枚举和构建潜在的投篮,例如......

角度1、球1、口袋2
角度2、球1、口袋3
角度3、球1、球2、口袋1
angle4,cushion2,ball2,pocket1

  • 对于更好的 AI,你想要模拟缺陷,例如,通过在某个点 x 击球(可能定义为远离直接击球的角度)来进行击球,让我们假设将有是 dx 的错误(由于瞄准不良、击球不良或其他原因)——这反过来会导致球的方向错误,该错误会随着距球袋的距离而增加。这提供了一种按难度对射击进行排名的方法 - 射击对瞄准/射击错误的敏感度(某些射击比其他射击更容易)。这取决于从白球到球以及从球到洞的路径长度。

  • 还要考虑的一件事是白球进洞或其他非法击球的风险

< strong>选择击球(不仅基于难度,还基于潜在收益)

  • 您还需要考虑策略(简单的击球可能会让您在下一轮中一无所获),
  • 这不仅是第一次射击有多容易,以及第二次射击有多难(为此,您可以再次对模拟情况进行评估,在这里您可以根据玩家的射击次数来使玩家变得更强或更弱也可以向前看;你也可以赋予你的球员个性 - 寻找解决方案深度优先或广度优先)
  • 在选择策略时,你应该寻找难度总和最小的击球组合(你可能需要评估后面击球的重要性)考虑到你会错过的可能性)
  • 根据比赛的情况,你可能会考虑引入安全击球,这纯粹是位置比赛,其目的不是立即将球打入袋中,而是迫使对手犯错误或缓解局势您自己(在其他情况下进行此类击球会很有帮助 - 例如,当您无法击中任何东西但需要分开几个球或将它们移离缓冲垫时)。在这种情况下,您需要从末尾开始。
  • 所有这一切都在现实物理中变得更加复杂:旋转、现实碰撞、弹跳、现实缓冲、提示滑动等。

Depending on the game of the billiards you usually have two tasks

Assess the situation on the table (get possible shots)

  • In perfect scenario (perfect aim, perfect shot) all possible shots are equally hard and if you consider only direct shots to one ball there will be only maximum of 6 holes x n balls situations that you need to analyse (analysing simple canons - hitting two balls requires only extra n^2 balls x 6 holes situations). For each of these situations establishing if they are possible requires simple analysis (unless you are doing very realistic collision simulations). So in very simple simulations you might want to try to construct all possible situations and rank them. To analyse shots off the bank you might want to mirror the balls and holes.

  • Alternatively in enumerating the possible situations you might simply do a line scan of the table, marking the areas which are illegal for shots and enumerating and building potential shots like...

angle1, ball1, pocket2
angle2, ball1, pocket3
angle3, ball1, ball2, pocket1
angle4, cushion2, ball2, pocket1

  • For nicer AI you want to simulate imperfections, for example the shot is played by hitting a ball at some point x (maybe defined as an angle away from direct hit), let's assume that there will be an error (due to bad aim, or bad hit, or anything) of dx - this in turn will cause the ball to have an error in direction which will increase with the distance to the pocket. This gives one way to rank the shots by difficulty - the sensitivity of the shot in terms of error in aim/shot (some shots are easier then others). This will depend on the length of the path from white to the ball and from the ball to the hole.

  • One more thing to look at is the risk of white ball going in the hole, or other illegal shots

Choosing the shot (not only based on difficulty, but also on potential gain)

  • you will need to look at the strategy as well (an easy shot might leave you with nothing in the next round)
  • it is not only how easy is it to make a first shot, but also how hard will be the second shot (for this you could run the assessment of that simulated situation again, and here you could make the player stronger or weaker depending on how many shots he is able too look ahead; you can also give your player personality - looking for solutions depth first or breadth first)
  • in choosing strategy you should look for the combination of shots whose sum of difficulty is minimal (you might need to assess importance of the later shots taking into account probability that you will miss)
  • depending on the game you might consider introducing safety shots which are purely positional game and the aim is not to pocket the ball immediately but to either force the opponent to make a mistake or to ease a situation for yourself (there are other situations when playing such shots would be beneficial - for example when you can not hit anything but would need to split few balls or move them away from cushion). in this case you will need to start from the end.
  • all this gets much more complicated with realistic physics: spins, realistic collision, bounces, realistic cushions, cue slips, etc..
飘过的浮云 2024-09-07 12:16:00

我可以想到两种广泛的方法。

  1. 列出母球周围所有可能的球杆位置和力度级别,然后搜索该列表以找到第一个让您击沉球的位置。这是一个相当大的列表,您可以通过使用少量的力量水平并排除任何“明显”不好的击球来修剪它。

  2. 逆向工作——观察桌子上的每个球,看看是否可以让母球接触到它。然后计算出正确的球杆位置和力量水平,使其进入洞中。
    您可以扩展它来搜索树中的多球击球。

我最喜欢方案1;它可以让你找到能够同时击沉两个或更多球的情况。

I can think of two broad approaches.

  1. Make a list of all possible cue positions surrounding the cue ball and force levels, and then search the list to find the first one that lets you sink a ball. That's a fairly large list, you can trim it by using a small number of force levels and by excluding any "obviously" bad shots.

  2. Work backwards -- look at each ball on the table, and see if the cue ball can be made to contact it. Then work out the correct cue position and force level to make it go in the hole.
    You can expand this to search a tree for multiple-ball shots.

I like solution 1 the best; it lets you find situations where you would be able to sink two or more balls at one time.

别在捏我脸啦 2024-09-07 12:16:00

您可能会考虑将球显示为加权图。您可以将口袋作为特殊节点放入。然后,您根据从母球到特定球再到口袋的路径重量,选择要放入或击打的球。脉冲的强度也可以通过使用该权重的值来设置。然后,您可以使用物理引擎来确定射击是否可行。我从来没有尝试过这样的事情,所以一切都是理论上的,我不知道它是否具有实用性。而且,这种方法不包括让球杆或其他球弹来弹去,所以基本上它只适合直线击球。

You might consider as displaying the balls as a weighted graph maybe. You could put in the pockets as special nodes. You then chose which ball to put, or hit, depending on the weight of the path from the cue ball, to the specific ball and to the pocket. The intensity of the impulse can also be set by using the value of this weight. You can then use a physics engine to determine if the shot is at all possible. I have never tried such thing, so everything is theoretical and I do not know if it is at all practical. Also, such method does not include having the cue or the other balls bouncing around, so basically it will cater only for straight shots.

↙厌世 2024-09-07 12:16:00

我认为这不是随机的。您需要一个物理引擎来模拟球杆、球、缓冲器和口袋的相互作用。对我来说,它不太像人工智能,而更像物理。

I would think it's hardly random. You'd want a physics engine to model the interactions of cue, balls, bumpers, and pockets. It feels less like AI and more like physics to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文