检查数字高度图中的闭合路径
我正在开发一个游戏,我需要检查给定数字高度图中的闭合路径: 服务器和客户端使用此高度图来设置正确的坐标以进行移动等... 现在,当用户走在“特殊”瓷砖上时,它会亮起...... 我的问题是: 当用户在这些图块上行走时,会创建一条包含空图块的闭合路径,服务器应自动填充此路径中的图块...
它应该执行如下操作: http://www.youtube.com/watch?v=kAVUNE2NTUQ - 1:32
我确信我必须在这里或那里使用一些数学,但我不知道如何...... 我可以做一个“for”循环,但它太长了,而且问题是服务器需要在用户每次行走时执行循环...... 预先感谢您的回答,希望有人能帮助我。
PS:我正在使用 C#
编辑:当用户在图块上行走时,服务器会自动将高度图 [X, Y] 替换为代表用户颜色的整数
I'm working on a game, and I have the necessity to check a closed path in a given numerical heightmap:
The server and the client use this heightmap to set the right coords to move etc...
Now, when an user walks on a "special" tile, it lights...
My problem is:
When an user, walking on these tiles creates a closed path with empty tiles in it, the server should automatically fill the tiles in this path...
It should do something like this:
http://www.youtube.com/watch?v=kAVUNE2NTUQ - 1:32
I'm sure I've to use some maths here or there, but I dunno how...
I could do a "for" cycle, but it would be too long, and the problem is that the server needs to do the cycle every time an user walks...
Thanks in advance for your answers, hope someone could help me.
PS: I'm using C#
EDIT: When an user walks on a tile, the server automatically replaces the heightmap[X, Y] with an integer that represents the color of the user
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该问题可以分为两个部分:
The problem can be divided into two parts:
假设您有一个矩形区域,左上角位于 (0, 0),右下角位于 (M, N)。然后可以使用以下伪代码填充算法:
Let's assume you have rectangular field with upper left corner in (0, 0) and bottom right in (M, N). Then you can use the following pseudocode fill algorithm:
“问题是服务器每次用户行走时都需要执行循环”...
您可以通过为游戏中的每个图块分配一个唯一的整数、具有包含图块数量的数组,以及然后对于每个步骤,在数组中标记此图块。当然,还要检查该图块之前是否已经走过(即是否在数组中标记),如果有,则有一个循环(可能是零面积)。这种方法没有循环遍历已走的图块等,而只是对每个步骤进行一次查找。
"the problem is that the server needs to do the cycle every time an user walks"...
You can eliminate the cycling over walked tiles by assigning each tile in the game a unique integer, having an array with the number of tiles, and then for each step mark this tile in the array. Of course, also check whether the tile has been walked before (i.e. whether it's marked in the array), and if it has, you have a loop (maybe of zero area). This approach has no cycling over walked tiles, etc, but just a single look-up for each step.