2025.5.28第一次提交,仿真平台修复bug同步修复

This commit is contained in:
氧原子
2025-05-28 21:51:08 +08:00
parent 9d96af2ff3
commit 14b3d14170
6 changed files with 68 additions and 27 deletions

View File

@@ -22,7 +22,25 @@ bool check_mark()
bool S_mark; bool S_mark;
bool E_mark; bool E_mark;
if (y < size_y - 1)
{
if (!wall[x][y+1][0])
{
N_mark = mark[x][y+1];
}
else
{
N_mark = true;
}
}
else
{
N_mark = true;
}
if (x > 0) if (x > 0)
{
if (!wall[x][y][1])
{ {
W_mark = mark[x-1][y]; W_mark = mark[x-1][y];
} }
@@ -30,8 +48,15 @@ bool check_mark()
{ {
W_mark = true; W_mark = true;
} }
}
else
{
W_mark = true;
}
if (y > 0) if (y > 0)
{
if (!wall[x][y][0])
{ {
S_mark = mark[x][y-1]; S_mark = mark[x][y-1];
} }
@@ -39,8 +64,15 @@ bool check_mark()
{ {
S_mark = true; S_mark = true;
} }
}
else
{
S_mark = true;
}
if (x < size_x - 1) if (x < size_x - 1)
{
if (!wall[x+1][y][1])
{ {
E_mark = mark[x+1][y]; E_mark = mark[x+1][y];
} }
@@ -48,22 +80,13 @@ bool check_mark()
{ {
E_mark = true; E_mark = true;
} }
if (y < size_y - 1)
{
N_mark = mark[x][y+1];
} }
else else
{ {
N_mark = true; E_mark = true;
} }
bool N_road = (!wall[x][y+1][0] && N_mark); if (N_mark && W_mark && S_mark && E_mark)
bool W_road = (!wall[x][y][1] && W_mark);
bool S_road = (!wall[x][y][0] && S_mark);
bool E_road = (!wall[x+1][y][1] && E_mark);
if (N_road && W_road && S_road && E_road)
{ {
check = true; check = true;
} }

View File

@@ -11,7 +11,7 @@ void flood(int *map, int *copy_wall)
int num = 0; int num = 0;
int size_x = mark.size(); int size_x = mark.size();
int size_y = mark[0].size(); int size_y = mark[0].size();
map[0] = 0; map[rob_x0 * (size_y) + rob_y0] = 0;
do do
{ {

View File

@@ -17,6 +17,7 @@ void output_arr2D(int size_x, int size_y, int *arr)
} }
cout << endl; cout << endl;
} }
cout << endl;
} }
/*---打印数组wall---*/ /*---打印数组wall---*/
@@ -46,6 +47,7 @@ void output_arrwall(int size_x, int size_y, int *arr)
} }
cout << endl; cout << endl;
} }
cout << endl;
} }
void output_arrpath(int size, int *arr) void output_arrpath(int size, int *arr)
@@ -55,4 +57,5 @@ void output_arrpath(int size, int *arr)
cout << arr[i] << " "; cout << arr[i] << " ";
} }
cout << endl; cout << endl;
cout << endl;
} }

View File

@@ -11,10 +11,11 @@ using namespace std;
int main() int main()
{ {
explore(); //使用递归算法构建地图 explore(); //使用递归算法构建地图
//~ wall[0][0][0] = 1; BOTturn(2 - rob_dir);
VWWait();
rob_dir = 2;
explore(); explore();
const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度 const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度
const int mazesize_y = mark[0].size(); //获取探索结束之后的迷宫的Y轴长度 const int mazesize_y = mark[0].size(); //获取探索结束之后的迷宫的Y轴长度
@@ -24,21 +25,29 @@ int main()
array_copy_mark(mazesize_x, mazesize_y, copy_mark); //复制一份mark数组并转换为一维数组便于后续频繁读取提升性能 array_copy_mark(mazesize_x, mazesize_y, copy_mark); //复制一份mark数组并转换为一维数组便于后续频繁读取提升性能
array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能 array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能
cout << "访问数组打印:" << endl;
output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息 output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息
cout << "地图打印:" << endl;
output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息 output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息
cout << "请输入目标点的X,Y坐标值 用空格隔开并回车" << endl;
cin >> target_x >> target_y;
cout << endl;
int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0 int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0
array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1 array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1
flood(map, copy_wall); //洪水填充算法 flood(map, copy_wall); //洪水填充算法
cout << "路径打印:" << endl;
output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息 output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息
const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定) const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定)
int path[len] = {}; //创建最短路径结果地图并初始化为0 int path[len] = {}; //创建最短路径结果地图并初始化为0
build_path(target_x - 1, target_y - 1, len, path, map, copy_wall); //构建出最短路径path数组 build_path(target_x - 1, target_y - 1, len, path, map, copy_wall); //构建出最短路径path数组
drive_path(len, path); //移动到指定目标点
cout << "移动指令打印:" << endl;
output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向 output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向
drive_path(len, path); //移动到指定目标点
} }

View File

@@ -49,7 +49,10 @@ int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分
const int eI_max = 200; //定义积分限幅 const int eI_max = 200; //定义积分限幅
/*---目标点的坐标---*/ /*---目标点的坐标---*/
const int target_x = 3; //声明目标点的X坐标 // const int target_x = 3; //声明目标点的X坐标
const int target_y = 4; //声明目标点的Y坐标 // const int target_y = 4; //声明目标点的Y坐标
int target_x; //声明目标点的X坐标
int target_y; //声明目标点的Y坐标
/*---定义结束---*/ /*---定义结束---*/

View File

@@ -38,7 +38,10 @@ extern int err, err_old, err_sum, err_diff; //定义误差,上一次误差
extern const int eI_max; //定义积分限幅 extern const int eI_max; //定义积分限幅
/*---目标点坐标---*/ /*---目标点坐标---*/
extern const int target_x; //声明目标点的X坐标 // extern const int target_x; //声明目标点的X坐标
extern const int target_y; //声明目标点的Y坐标 // extern const int target_y; //声明目标点的Y坐标
extern int target_x; //声明目标点的X坐标
extern int target_y; //声明目标点的Y坐标
/*---声明结束---*/ /*---声明结束---*/