如何计算数组中的其他元素
基本上,我正在创建一个森林火灾程序,该程序取决于周围元素的风/干燥度。我有一个 var Trees [,] 数组,大小为 20 x 20。中间的方块设置为“着火”。单击按钮 1 后需要执行以下操作:评估着火方块周围的每个方块,以确定其他方块着火的概率。
Color[,] map = new Color[WIDTH, HEIGHT];
for (int x = 0; x < WIDTH; x++)
for (int y = 0; y < HEIGHT; y++)
{
if (x == WIDTH / 2 && y == HEIGHT / 2)
map[x, y] = Color.Red;
else
map[x, y] = Color.Green;
}
fireBox1.box = map;
这是我设置的 20 x 20 阵列,其中中间的方块着火。我只是不知道如何获取当前着火的方块周围的方块(数组元素)。
Basically I'm creating a forest fire program that depends on the wind / dryness of the surround elements. I have an array var Trees [,] that is 20 x 20. The middle square is set "on fire". This is what needs to be done once you click button1: Evaluate each square around the one that is set on fire to determine the probability for the others to catch fire.
Color[,] map = new Color[WIDTH, HEIGHT];
for (int x = 0; x < WIDTH; x++)
for (int y = 0; y < HEIGHT; y++)
{
if (x == WIDTH / 2 && y == HEIGHT / 2)
map[x, y] = Color.Red;
else
map[x, y] = Color.Green;
}
fireBox1.box = map;
This is the 20 x 20 array that I have setup with the middle square set on fire. I just have no idea how to get the squares (array elements) around the one that is currently on fire.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从一个简单的循环开始。
建立矩阵后,中心应该如下所示。
然后我们可以只循环遍历与中心点相接触的点。
因此,假设风向东吹,我们应该将其视为矩阵。
最终它会像这样扩展。
You can start with a simple loop.
After you have built your matrix the center should look like this.
Then we can loop through only the points that touch the center point.
So assuming we have wind blowing east we should see this as the matrix.
And eventually it will expand out like this.