diff --git a/bot_code_turn/maze_func_explore.cpp b/bot_code_turn/maze_func_explore.cpp index 7ef79b4..197d2d4 100644 --- a/bot_code_turn/maze_func_explore.cpp +++ b/bot_code_turn/maze_func_explore.cpp @@ -22,9 +22,32 @@ bool check_mark() bool S_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) { - W_mark = mark[x-1][y]; + if (!wall[x][y][1]) + { + W_mark = mark[x-1][y]; + } + else + { + W_mark = true; + } } else { @@ -33,7 +56,14 @@ bool check_mark() if (y > 0) { - S_mark = mark[x][y-1]; + if (!wall[x][y][0]) + { + S_mark = mark[x][y-1]; + } + else + { + S_mark = true; + } } else { @@ -42,28 +72,21 @@ bool check_mark() if (x < size_x - 1) { - E_mark = mark[x+1][y]; + if (!wall[x+1][y][1]) + { + E_mark = mark[x+1][y]; + } + else + { + E_mark = true; + } } else { E_mark = true; } - - if (y < size_y - 1) - { - N_mark = mark[x][y+1]; - } - else - { - N_mark = true; - } - - bool N_road = (!wall[x][y+1][0] && N_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) + if (N_mark && W_mark && S_mark && E_mark) { check = true; } diff --git a/bot_code_turn/maze_func_flood.cpp b/bot_code_turn/maze_func_flood.cpp index 521f98d..51828dd 100644 --- a/bot_code_turn/maze_func_flood.cpp +++ b/bot_code_turn/maze_func_flood.cpp @@ -11,7 +11,7 @@ void flood(int *map, int *copy_wall) int num = 0; int size_x = mark.size(); int size_y = mark[0].size(); - map[0] = 0; + map[rob_x0 * (size_y) + rob_y0] = 0; do { diff --git a/bot_code_turn/maze_func_output.cpp b/bot_code_turn/maze_func_output.cpp index c9697cb..3798f4d 100644 --- a/bot_code_turn/maze_func_output.cpp +++ b/bot_code_turn/maze_func_output.cpp @@ -17,6 +17,7 @@ void output_arr2D(int size_x, int size_y, int *arr) } cout << endl; } + cout << endl; } /*---打印数组wall---*/ @@ -46,6 +47,7 @@ void output_arrwall(int size_x, int size_y, int *arr) } cout << endl; } + cout << endl; } void output_arrpath(int size, int *arr) @@ -55,4 +57,5 @@ void output_arrpath(int size, int *arr) cout << arr[i] << " "; } cout << endl; + cout << endl; } diff --git a/bot_code_turn/maze_main.cpp b/bot_code_turn/maze_main.cpp index 869b445..b576d56 100644 --- a/bot_code_turn/maze_main.cpp +++ b/bot_code_turn/maze_main.cpp @@ -11,10 +11,11 @@ using namespace std; int main() { explore(); //使用递归算法构建地图 - //~ wall[0][0][0] = 1; + BOTturn(2 - rob_dir); + VWWait(); + rob_dir = 2; explore(); - const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度 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_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组,并转换为一维数组,便于后续频繁读取提升性能 + cout << "访问数组打印:" << endl; output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息 + cout << "地图打印:" << endl; 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 array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1 flood(map, copy_wall); //洪水填充算法 + cout << "路径打印:" << endl; output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息 const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定) int path[len] = {}; //创建最短路径结果地图并初始化为0 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数组信息,及小车每一步的行驶方向 - + + drive_path(len, path); //移动到指定目标点 } diff --git a/bot_code_turn/maze_parameter.cpp b/bot_code_turn/maze_parameter.cpp index 692fd6c..919afac 100644 --- a/bot_code_turn/maze_parameter.cpp +++ b/bot_code_turn/maze_parameter.cpp @@ -49,7 +49,10 @@ int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分 const int eI_max = 200; //定义积分限幅 /*---目标点的坐标---*/ -const int target_x = 3; //声明目标点的X坐标 -const int target_y = 4; //声明目标点的Y坐标 +// const int target_x = 3; //声明目标点的X坐标 +// const int target_y = 4; //声明目标点的Y坐标 + +int target_x; //声明目标点的X坐标 +int target_y; //声明目标点的Y坐标 /*---定义结束---*/ diff --git a/bot_code_turn/maze_parameter.h b/bot_code_turn/maze_parameter.h index b4b3a4d..c8a0c0e 100644 --- a/bot_code_turn/maze_parameter.h +++ b/bot_code_turn/maze_parameter.h @@ -38,7 +38,10 @@ extern int err, err_old, err_sum, err_diff; //定义误差,上一次误差 extern const int eI_max; //定义积分限幅 /*---目标点坐标---*/ -extern const int target_x; //声明目标点的X坐标 -extern const int target_y; //声明目标点的Y坐标 +// extern const int target_x; //声明目标点的X坐标 +// extern const int target_y; //声明目标点的Y坐标 + +extern int target_x; //声明目标点的X坐标 +extern int target_y; //声明目标点的Y坐标 /*---声明结束---*/