Files
bk_bishe_pi/maze_code/maze_func_flood.cpp
2025-05-14 12:34:56 +08:00

72 lines
1.5 KiB
C++

#include<iostream>
#include<string>
#include<vector>
#include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h"
using namespace std;
void flood(int *map, int *copy_map, int *copy_wall)
{
int num = 0;
int size_x = mark.size();
int size_y = mark[0].size();
map[0][0] = 0;
copy_map[0][0] = 0;
do
{
for (i = 0; i < size_x; i++)
{
for (j = 0; j < size_y; j++)
{
if (! map[i][j] == -1)
{
if (i > 0)
{
if (! copy_wall[i][j][1] && map[i-1][j] = -1) //左边格子
{
copy_map[i-1][j] = map[i][j] + 1;
num++;
}
}
if (i < size_x - 1)
{
if (! copy_wall[i+1][j][1] && map[i+1][j] = -1) //右边格子
{
copy_map[i+1][j] = map[i][j] + 1;
num++;
}
}
if (j > 0)
{
if (! copy_wall[i][j][0] && map[i][j-1] = -1)
{
copy_map[i][j-1] = map[i][j] + 1;
num++;
}
}
if (j < size_y - 1)
{
if (! copy_wall[i][j+1][0] && map[i][j+1] = -1)
{
copy_map[i][j+1] = map[i][j] + 1;
num++;
}
}
}
}
}
for (i = 0; i < size_x; i++)
{
for (j = 0; j < size_y; j++)
{
map[i][j] = copy_map[i][j];
}
}
} while (map[target_x][target_y] == -1 && num < (size_x * size_y))
}