AStar 在 C# 中的具体情况

发布于 2024-08-24 03:32:51 字数 721 浏览 11 评论 0原文

在一次实习中,我在以下情况中使用了 A* 算法:

  • 单位形状是高度和宽度为 1 的正方形,
  • 我们可以从另一个矩形代表的区域出发,但不能在这些区域之外旅行在预先定义的区域中,
  • 我们可以通过门从一个矩形到达另一个矩形,由相应方形边缘上的一段表示。

以下是我已经做过但没有让我的老板满意的两件事:

1 : 我创建了以下课程: -a Door 类,其中包含 2 个独立方块的位置和门的方向(上、左、下、右), -a Map 类,其中包含门列表,代表可步行区域的矩形列表 和代表地面方块的 2D 数组(通过枚举获取附加信息) - A* 算法的类(节点、AStar)

2: -a MapCase 类,通过枚举包含有关案例效果和门的信息(设置 [FLAGS] 属性,以便能够累积每个案例的多个信息) -a Map 类,仅包含 MapCase 类的二维数组 - A* 算法的类(仍然是 AStar 节点)。

由于第二个版本比第一个版本更好(无用计算更少,映射类架构更好),我的老板对我的映射类架构仍然不满意。

A* 和节点类很好并且易于维护,所以我认为现在不必更深入地解释它们。

所以我想问:有人有一个好主意来实现 A* 与问题规范(矩形可步行,但具有正方形单位面积,穿过门)?

他说,问题的网格愿景(即二维数组)不应该是解决问题的正确方法。

我希望我在揭露我的问题时已经很清楚了..

谢谢

KiTe

To an intership, I have use the A* algorithm in the following case :

  • the unit shape is a square of height and width of 1,
  • we can travel from a zone represented by a rectangle from another, but we can't travel outside these predifined areas,
  • we can go from a rectangle to another through a door, represented by a segment on corresponding square edge.

Here are the 2 things I already did but which didn't satisfied my boss :

1 :
I created the following classes :
-a Door class which contains the location of the 2 separated squares and the door's orientation (top, left, bottom, right),
-a Map class which contains a door list, a rectangle list representing the walkable areas
and a 2D array representing the ground's squares (for additionnal infomations through an enumeration)
- classes for the A* algorithm (node, AStar)

2 :
-a MapCase class, which contains information about the case effect and doors through an enumeration (with [FLAGS] attribute set on, to be able to cummulate several information on each case)
-a Map classes which only contains a 2D array of MapCase classes
- the classes for the A* algorithm (still node an AStar).

Since the 2 version is better than the first (less useless calculation, better map classes architecture), my boss is not still satisfied about my mapping classes architecture.

The A* and node classes are good and easily mainainable, so I don't think I have to explain them deeper for now.

So here is my asking : has somebody a good idea to implement the A* with the problem specification (rectangle walkable but with a square unit area, travelling through doors)?

He said that a grid vision of the problem (so a 2D array) shouldn't be the correct way to solve the problem.

I wish I've been clear while exposing my problem ..

Thanks

KiTe

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

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

发布评论

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

评论(1

拍不死你 2024-08-31 03:32:51

您可以使用具有加权边的节点,而不是多维数组。这非常适合 A* 搜索您需要的距离和连接。如果距离均为 1,那么您可以忽略权重。

Rather than a multi-dimensional array you could use nodes with weighted edges. This fits well as for the A* search you need the distances and connections. If the distancs are all 1 then you can ignore the weightings.

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