在游戏中使用 C# 基于气味的寻路

发布于 2024-11-06 07:41:54 字数 62 浏览 1 评论 0原文

想知道是否有人知道如何使用气味来实现寻路。周围节点的气味越浓,就是‘敌人’所靠近的方向。

谢谢

Was wondering if anyone has knowledge on implementing pathfinding, but using scent. The stronger the scent in the nodes surrounding, is the way the 'enemy' moves towards.

Thanks

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

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

发布评论

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

评论(5

嘿看小鸭子会跑 2024-11-13 07:41:54

是的,我做了关于这个主题的大学期末项目。

这个想法的应用之一是寻找最短路径
正如你所说,这个想法是“气味”会随着时间的推移而衰减。但两点之间最短的路径将具有最强烈的气味。

看看这个 论文

你到底想知道什么??

Yes, I did my university final project on the subject.

One of the applications of this idea is for finding the shortest path.
The idea is that the 'scent', as you put it, will decay over time. But the shortest path between two points will have the strongest scent.

Have a look at this paper.

What did you want to know exactly??

滴情不沾 2024-11-13 07:41:54

不太清楚问题是什么 - 但这似乎是描述蚁群优化问题的另一种方式< /a>:

计算机科学和运维
研究,蚁群优化
算法(ACO)是一种概率算法
解决计算问题的技术
问题可以简化为
通过图表找到好的路径。

Not quite clear what the question is in particular - but this just seems like another way of describing the Ant colony optimization problem:

In computer science and operations
research, the ant colony optimization
algorithm (ACO) is a probabilistic
technique for solving computational
problems which can be reduced to
finding good paths through graphs.

兔小萌 2024-11-13 07:41:54

好吧,想一想。

我的想法是将游戏区域划分为 32x32 的部分(或者你的角色的任何尺寸)。然后每隔 x 秒运行一些检查(因此,如果它们保持静止,它们周围的瓷砖将有更多的“气味”),以计算出任何给定瓷砖上的气味有多强烈。一些例子可能是: 1) 如果你跨越了图块,则添加 3; 2) 如果你跨越了相邻的图块,则加 1。

然后添加随着时间的推移而退化之类的东西,每 x 秒将每个图块减少 1,直到它达到零。

您需要担心的最后一件事是使用人工智能来跟踪这条路径。我建议将人工智能放在某个地方,并告诉它找到具有气味的节点,然后转到具有更高/相等值气味的相邻节点。还要担心交叉所采取的路径。如果玩家沿着一条路径前进,然后沿着另一个方向返回,请确保 AI 始终只走循环返回的路径。
人工智能最后要考虑的是添加一点错误。让AI时不时走错路。或者更容易失去踪迹。

这些是关键点,我相信你可以通过更多的头脑风暴想出更多的要点。

Well, think about it for a minute.

My idea would to divide the game field into sections of 32x32 (or whatever size your character is). Then run some checks every x seconds (so if they stay still the tiles around them will have more 'scent') to figure out how strong a scent is on any given tile. Some examples might be: 1) If you cross over the tile, add 3; 2) if you crossed over an adjacent tile, add 1.

Then add things like degradation over time, reduce every tile by 1 every x seconds until it hits zero.

The last thing you will need to worry about is using AI to track this path. I would recommend just putting the AI somewhere, and telling it to find a node with a scent, then goto an adjacent node with a higher/equal value scent. Also worry about crossing off paths taken. If the player goes up a path, then back down it another direction, make sure the AI does always just take the looped back path.
The last thing to look at with the AI would be to add a bit of error. Make the AI take the wrong path every once in a while. Or lose the trail a little more easily.

Those are the key points, I'm sure you can come up with some more, with some more brainstorming.

梦情居士 2024-11-13 07:41:54

每次游戏更新(或其他一些不太频繁的时间范围),都会增加目标对象(红色斑点)所在位置附近节点的气味值。

将所有节点气味值减少一定的衰减量至零。

在黄色斑点的思考/移动功能中,获取要移动到的可用节点。向气味值最高的节点移动。

根据节点的数量,“减少所有节点气味值”可以进行优化,例如,可以维护要减少的非零节点的列表。

Every game update (or some other, less frequent time frame), increase the scent value of nodes near to where the target objects (red blobs) are.

Decrease all node scent values by some fall-off amount to zero.

In the yellow blob's think/move function get available nodes to move to. Move towards the node with the highest scent value.

Depending on the number of nodes the 'decrease all node scent values' could do with optomisation, e.g. maybe maintaining a a list of non-zero nodes to be decreased.

贱人配狗天长地久 2024-11-13 07:41:54

我发现气味模型和寻路之间存在很大的矛盾。对于自然界中的猎人来说,通过气味寻找路径意味着准确地找到跟随对象所使用的路径。在游戏中,寻路意味着找到两点之间最快的路径。这是不一样的。
1. 在对气味进行建模时,您将计算该点的气味浓度,即周围浓度的总和乘以不同的因子。寻找从该点开始的最快路径意味着取周围点计算的时间的最小值,乘以不同的参数。
2. 计算气味时应使用递归模型 - 气味向各个方向传播,包括向后。在寻路的情况下,如果您找到了目标周围点的最短路径,它们将不会改变。
3 气味水平可以上升和下降。在寻路中,当寻找最小值时,结果永远不会上升。

所以,气味模型实际上比你的目标复杂得多。当然,我所说的仅适用于标准情况,你可以有一些非常特别的东西......

I see a big contradiction between scent model and pathfinding. For a hunter in the nature finding the path by scent means finding exactly the path used by the followed subject. And in games pathfinding means finding the fastest path between two points. It is not the same.
1. While modelling the scent you will count the scent concentration in the point as the SUM of the surrounding concentrations multiplied by different factors. And searching for the fastest path from the point means taking the MINIMUM of the times counted for surrounding points, multiplied by the different parametres.
2. Counting the scent you should use recursive model - scent goes in all directions, including backward. In the case of the pathfinding, if you have found the shortest paths for points surrounding the target, they won't change.
3 Level of scent can rise and fall. In pathfinding, while searching for minimum, the result can never rise.

So, the scent model is really much more complicated than your target. Of course, what I have said, is true only for the standard situation and you can have something very special...

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