From 0b8d29917f023c71b9e4208d37b2024db126bb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=A7=E5=8E=9F=E5=AD=90?= Date: Sat, 31 May 2025 23:28:45 +0800 Subject: [PATCH] =?UTF-8?q?2025.5.31=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E5=A4=B4=E6=96=87=E4=BB=B6=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_code_turn/maze_func.h | 3 +++ bot_code_turn/maze_func_array.cpp | 1 - bot_code_turn/maze_func_cin.cpp | 26 ++++++++++++++++++++++++++ bot_code_turn/maze_func_explore.cpp | 5 +++++ bot_code_turn/maze_func_flood.cpp | 1 - bot_code_turn/maze_func_output.cpp | 3 +-- bot_code_turn/maze_func_path.cpp | 3 ++- bot_code_turn/maze_main.cpp | 6 ++---- bot_code_turn/maze_parameter.cpp | 1 - 9 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 bot_code_turn/maze_func_cin.cpp diff --git a/bot_code_turn/maze_func.h b/bot_code_turn/maze_func.h index 5f97fb3..7419dd6 100644 --- a/bot_code_turn/maze_func.h +++ b/bot_code_turn/maze_func.h @@ -45,3 +45,6 @@ void output_arrwall(int size_x, int size_y, int *arr); //打印wall数组 void output_arrpath(int size, int *arr); //打印path数组 /*---以上为数组打印部分涉及到的函数声明---*/ +/*---以下为目标点输入函数声明---*/ +void cin_targey(); //输入目标点 +/*---以上为目标点输入函数声明---*/ \ No newline at end of file diff --git a/bot_code_turn/maze_func_array.cpp b/bot_code_turn/maze_func_array.cpp index a35850d..a7a323d 100644 --- a/bot_code_turn/maze_func_array.cpp +++ b/bot_code_turn/maze_func_array.cpp @@ -1,7 +1,6 @@ #include #include #include -#include"eyebot++.h" #include"maze_parameter.h" #include"maze_func.h" using namespace std; diff --git a/bot_code_turn/maze_func_cin.cpp b/bot_code_turn/maze_func_cin.cpp new file mode 100644 index 0000000..69b618e --- /dev/null +++ b/bot_code_turn/maze_func_cin.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include"maze_parameter.h" +#include"maze_func.h" +using namespace std; + +void cin_targey() +{ + int size_x = mark.size(); + int size_y = mark[0].size(); + + int num = 0; + do + { + if (!num) + { + cout << "您输入的目标点超出迷宫范围,请重新输入" << endl; + } + cout << "请输入目标点的X,Y坐标值 用空格隔开并回车" << endl; + cin >> target_x >> target_y; + cout << endl; + num++; + } while (target_x <= size_x && target_y <= size_y); + cout << endl; +} \ No newline at end of file diff --git a/bot_code_turn/maze_func_explore.cpp b/bot_code_turn/maze_func_explore.cpp index 197d2d4..87d80d1 100644 --- a/bot_code_turn/maze_func_explore.cpp +++ b/bot_code_turn/maze_func_explore.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include"eyebot++.h" #include"maze_parameter.h" #include"maze_func.h" @@ -117,6 +118,7 @@ void maze_entry(int x, int y, int dir, int open) else { cout << "error: mark or wall empty" << endl; + exit(1); } } wall[x][y+1][0] = !open; @@ -141,6 +143,7 @@ void maze_entry(int x, int y, int dir, int open) else { cout << "error: mark or wall empty" << endl; + exit(1); } } wall[x][y][1] = !open; @@ -165,6 +168,7 @@ void maze_entry(int x, int y, int dir, int open) else { cout << "error: mark or wall empty" << endl; + exit(1); } } wall[x][y][0] = !open; @@ -181,6 +185,7 @@ void maze_entry(int x, int y, int dir, int open) else { cout << "error: mark or wall empty" << endl; + exit(1); } } wall[x+1][y][1] = !open; diff --git a/bot_code_turn/maze_func_flood.cpp b/bot_code_turn/maze_func_flood.cpp index 51828dd..984edee 100644 --- a/bot_code_turn/maze_func_flood.cpp +++ b/bot_code_turn/maze_func_flood.cpp @@ -1,7 +1,6 @@ #include #include #include -#include"eyebot++.h" #include"maze_parameter.h" #include"maze_func.h" using namespace std; diff --git a/bot_code_turn/maze_func_output.cpp b/bot_code_turn/maze_func_output.cpp index 3798f4d..ac3b48d 100644 --- a/bot_code_turn/maze_func_output.cpp +++ b/bot_code_turn/maze_func_output.cpp @@ -1,6 +1,5 @@ #include #include -#include"eyebot++.h" #include"maze_func.h" using namespace std; @@ -57,5 +56,5 @@ void output_arrpath(int size, int *arr) cout << arr[i] << " "; } cout << endl; - cout << endl; + cout << endl; } diff --git a/bot_code_turn/maze_func_path.cpp b/bot_code_turn/maze_func_path.cpp index ec5338d..8daa9b4 100644 --- a/bot_code_turn/maze_func_path.cpp +++ b/bot_code_turn/maze_func_path.cpp @@ -1,7 +1,7 @@ #include #include #include -#include"eyebot++.h" +#include #include"maze_parameter.h" #include"maze_func.h" using namespace std; @@ -37,6 +37,7 @@ void build_path(int i, int j, int len, int *path, int *map, int *copy_wall) else { LCDPrintf("ERROR"); + exit(1); } } } diff --git a/bot_code_turn/maze_main.cpp b/bot_code_turn/maze_main.cpp index 420e0b3..84c200f 100644 --- a/bot_code_turn/maze_main.cpp +++ b/bot_code_turn/maze_main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include"eyebot++.h" #include"maze_parameter.h" #include"maze_func.h" @@ -32,10 +33,7 @@ int main() cout << endl; output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息 - cout << "请输入目标点的X,Y坐标值 用空格隔开并回车" << endl; - cout << endl; - cin >> target_x >> target_y; - cout << endl; + cin_targey(); //输入目标点,带超界检测 int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0 array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1 diff --git a/bot_code_turn/maze_parameter.cpp b/bot_code_turn/maze_parameter.cpp index c92efb0..25fd8fb 100644 --- a/bot_code_turn/maze_parameter.cpp +++ b/bot_code_turn/maze_parameter.cpp @@ -1,7 +1,6 @@ #include #include #include -#include"eyebot++.h" #include"maze_parameter.h" // #include"maze_func.h" using namespace std;