简体   繁体   English

C#算法查找具有特定类型的最接近的图块

[英]c# algorithm to find nearest tile with specific type

Sorry for the title but i didn't know how to describe my problem in one sentence. 对不起,标题,但是我不知道如何用一句话描述我的问题。

So basicly i am trying to create something to make random dungeons. 因此,基本上,我正在尝试创建一些东西来制作随机的地牢。 I make rooms at random positions on a 2d grid and add doors to every room. 我在2D网格上的任意位置放置房间,并为每个房间添加门。 Then I get the first door and try to find the closest other door but I can't find a good algorithm to this, I tried a modified version of a* and also looked at flood-fill but that isnt what I need. 然后我得到了第一扇门,并试图找到最接近的另一扇门,但是我找不到一个合适的算法,我尝试了a *的修改版本,还查看了洪水填充,但这不是我所需要的。 I was thinking of some sort of spiral around the first door and check every tile we pass to see if its a door. 我在想第一扇门周围的螺旋形,检查我们经过的每块瓷砖,看看它是否是一扇门。 I have a list of all the doors in the level if that helps but there are a lot so i don't think it's a good idea to check the distance to every door. 如果有帮助,我会列出该级别中所有门的列表,但是列表很多,所以我认为检查到每个门的距离不是一个好主意。

Does anyone know if there is a good algorithm for this? 有谁知道这是否有一个好的算法?

If a game stores its objects in a quadtree , searching of existing items in a scene prioritized by proximity could be done. 如果游戏将其对象存储在四叉树中 ,则可以在按优先级排序的场景中搜索现有项目。 Instead of searching for a collision, one can search for an object of a specific type. 无需搜索冲突,而是可以搜索特定类型的对象。 This can be done with the is operator in C#. 可以使用C#中的is运算符来完成。 This question may be better suited for the Game Development Stack Exchange . 这个问题可能更适合于Game Development Stack Exchange

So you need to find the closest graph node with specific properties? 因此,您需要找到具有特定属性的最接近的图节点?

BFS ( breadth-first search) is your friend. BFS (广度优先搜索)是您的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何构建一个算法来查找一个组合,其总和最接近一个数字,其差异在c#的范围内 - How to build an algorithm to find a combination, which summation is nearest to a number and its difference is within a range in c# C#尝试查找特定的菜单类型 - C# Attempting to find a specific menu type 查找离今天最近的经常性日期 - C# - Find recurring date nearest to today - C# 在 C# 中找到 k 个最近邻 - Find k nearest neighbor in C# 类列表。 c#按类型搜索以找到元素x,然后在x周围的列表中搜索项目以找到最接近的元素Y。 - List of classes. c# search by type to find element x then search the items in the list around x to find the nearest element Y. 在动态加载的程序集dll中找到特定的c#类类型 - find specific c# class type in dynamically loaded assembly dll Unity 2D切片图—按类型C#对切片进行分组 - Unity 2D Tile Map — Group Tiles By Type C# C# - 从十进制数组中查找最接近的索引 - C# - Find the index of nearest value from decimal array 在 C# .NET 控制台应用程序中查找最近的车辆 position - Find the nearest vehicle position in C# .NET console app 在 c# 中的大文本文件中查找具有特定日期的第一行的最佳“试错”算法是什么? - What is the best 'Trial and Error' algorithm to find first row with specific date in large text file in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM