2025.5.31第一次提交优化代码结构,头文件等

This commit is contained in:
氧原子
2025-05-31 23:28:45 +08:00
parent 9ba913646c
commit 0b8d29917f
9 changed files with 39 additions and 10 deletions

View File

@@ -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 output_arrpath(int size, int *arr); //打印path数组
/*---以上为数组打印部分涉及到的函数声明---*/ /*---以上为数组打印部分涉及到的函数声明---*/
/*---以下为目标点输入函数声明---*/
void cin_targey(); //输入目标点
/*---以上为目标点输入函数声明---*/

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;

View File

@@ -0,0 +1,26 @@
#include<iostream>
#include<string>
#include<vector>
#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;
}

View File

@@ -2,6 +2,7 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef> #include<cstddef>
#include<cstdlib>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
@@ -117,6 +118,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y+1][0] = !open; wall[x][y+1][0] = !open;
@@ -141,6 +143,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y][1] = !open; wall[x][y][1] = !open;
@@ -165,6 +168,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y][0] = !open; wall[x][y][0] = !open;
@@ -181,6 +185,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x+1][y][1] = !open; wall[x+1][y][1] = !open;

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;

View File

@@ -1,6 +1,5 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include"eyebot++.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
@@ -57,5 +56,5 @@ void output_arrpath(int size, int *arr)
cout << arr[i] << " "; cout << arr[i] << " ";
} }
cout << endl; cout << endl;
cout << endl; cout << endl;
} }

View File

@@ -1,7 +1,7 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include<cstdlib>
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
@@ -37,6 +37,7 @@ void build_path(int i, int j, int len, int *path, int *map, int *copy_wall)
else else
{ {
LCDPrintf("ERROR"); LCDPrintf("ERROR");
exit(1);
} }
} }
} }

View File

@@ -1,6 +1,7 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstdlib>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
@@ -32,10 +33,7 @@ int main()
cout << endl; 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_targey(); //输入目标点,带超界检测
cout << 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

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
// #include"maze_func.h" // #include"maze_func.h"
using namespace std; using namespace std;