Files
bk_bishe_pi/maze_code/maze_main.cpp

43 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<iostream>
#include<string>
#include<vector>
#include"eyebot++.h"
#include"maze_parameter.h"
#include"maze_func.h"
using namespace std;
/*---下面是主函数---*/
int main()
{
explore(); //使用递归算法构建地图
wall[0][0][0] = 1;
const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度
const int mazesize_y = mark[0].size(); //获取探索结束之后的迷宫的Y轴长度
int copy_mark[mazesize_x * mazesize_y] = {}; //复制一份mark数组并转换为一维数组便于后续频繁读取提升性能并初始化为0
int copy_wall[(mazesize_x + 1) * (mazesize_y + 1) * 2] = {}; //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能并初始化为0
array_copy_mark(mazesize_x, mazesize_y, copy_mark); //复制一份mark数组并转换为一维数组便于后续频繁读取提升性能
array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能
output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息
output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息
int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0
array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1
flood(map, copy_wall); //洪水填充算法
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); //移动到指定目标点
output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向
}