资源简介
通过alpha-belta剪枝的极大极小值算法实现简单的五子棋+A*算法与IDA*算法解决走迷宫问题

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef struct point{
int xy;
int fxgxhx;
int pxpy;
bool visited;
struct point *next;
}*Point;
Point Qpath;
int entry_xentry_y;
int exit_xexit_y;
int rowcol;
int maze[200][200];
int Visited[200][200];
char Path[200][200];
char PATH[200];
int Manhattan_dis(int x int y){
return abs(x - exit_x) + abs(y - exit_y);
}
bool QueueEmpty(Point Q){
if(Q->next == NULL) return true;
return false;
}
void EnQueue(Point QPoint q){
if(QueueEmpty(Q)){
Q->next=q;
return;
}
Point p = Q->next;
while(p->next!=NULL&&p->fx < q->fx)
p = p->next;
q->next = p->next;
p->next = q;
Visited[q->x][q->y] = 1;
}
void EnQueue_1(Point QPoint q){
if(QueueEmpty(Q)){
Q->next=q;
return;
}
Point p = Q->next;
while(p->next!=NULL&&p->fx > q->fx)
p = p->next;
q->next = p->next;
p->next = q;
}
void DeQueue(Point QPoint &p){
p = Q->next;
Q->next=p->next;
}
void Build_Maze(char *filename){
ifstream in;
string input;
in.open(filename);
int depth = 0;
int flag = 0 m = -1;
while(getline(ininput)){
int length = input.length();
int i = 0j = 0;
while(i < length){
if(input[i] == ‘0‘) maze[depth][j++] = 0;
else if(input[i] == ‘1‘) maze[depth][j++] = 1;
i++;
}
depth++;
if(m < j) m = j;
if(m > j) flag = 1;
}
col = depth - flag; row = m;
}
void Get_entry_and_exit(){
int i;
for(i = 0; i < row; i++){
if(maze[0][i] == 0){
entry_x = 0;
entry_y = i;
}
if(maze[col - 1][i] == 0){
exit_x = col - 1;
exit_y = i;
}
}
for(int j = 0; j < col; j++){
if(maze[j][0] == 0){
entry_x = j;
entry_y = 0;
}
if(maze[j][row - 1] == 0){
exit_x = j;
exit_y = row - 1;
}
}
}
Point Generate_Point(int x int y int gx int px int py){
Point Entry = (Point)malloc(sizeof(point));
Entry->x = x;Entry->y = y;
Entry->px = px; Entry->py = py;
Entry->gx = gx; Entry->hx = Manhattan_dis(entry_xentry_y);Entry->fx = Entry->gx + Entry->hx;
Entry->next = NULL;
return Entry;
}
void A_STAR(){
Q = Generate_Point(-1-10-1-1);
path = Generate_Point(-1-10-1-1);
Point Entry = Generate_Point(entry_xentry_y0-1-1);
EnQueue(QEntry);
Point p = (Point)malloc(sizeof(point));
while(!QueueEmpty(Q)){
DeQueue(Qp);
EnQueue_1(pathp);
if(p->x == exit_x && p->y == exit_y){
return;
}
int x = p->x y = p->y gx = p->gx;
if( x + 1 < col && maze[x+1][y] == 0 && Visited[x+1][y] == 0){
Point q = Generate_Point(x + 1 y gx + 1 x y);
EnQueue(Qq);
}
if( y + 1 < row && maze[x][y+1] == 0 && Visited[x][y+1] == 0){
Point q = Generate_Point(x y + 1 gx + 1 x y);
EnQueue(Qq);
}
if( x - 1 >= 0 && maze[x-1][
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4673 2019-05-12 16:41 ai_1.1.cpp
文件 5707 2019-05-12 16:40 ai_1.2.cpp
文件 12251 2019-06-21 17:02 ai_2.cpp
文件 916 2019-05-12 00:44 input1.txt
文件 3647 2019-05-12 14:09 input2.txt
文件 122 2019-06-21 17:04 output.txt
文件 55 2019-05-12 16:31 output_astar_1.txt
文件 133 2019-05-12 16:36 output_astar_2.txt
文件 56 2019-05-12 20:16 output_ida_1.txt
文件 133 2019-05-12 16:36 output_ida_2.txt
- 上一篇:winfrom 显示指定svg
- 下一篇:STM Isp 器
相关资源
- 北航人工智能原理课大作业源代码,
- A*算法的2D演示(带源码)
- Python版的A*寻路算法
- A Pathfinding Project Pro v4.2.2.rar
- 论文研究 - Connect-4博弈对Minimax算法洞
- unity寻路插件:A*Pathfinding
- A*DijkstraBFS路径搜寻算法演示程序
- 简单A*算法罗马尼亚度假问题
- UNITY自动寻路插件 A* Pathfinding Project
- A*算法和基于深度优先的八数码问题
- ARA* AD*室内机器人导航算法研究
- 基于稀疏A*航迹规划算法
- A星算法实现路径规划
- A*算法解决旅行商问题
- a* 算法 人工智能 拼图游戏
- 十进制加法器课程设计常规型微程序
- 搜索算法演示程序
- 模拟红蓝军对战程序
- A*算法旅行商问题实验报告和代码
- A*算法的具体思想我见过的写的最好的
- 一种基于A* 算法的动态多路径规划算
- A星算法伪代码
- A*算法 计算九宫格数字移动问题
- 老外牛逼A*寻路算法
- 基于A*算法的路径规划
- 八数码 + 迭代深搜 +A*
- AStar寻路算法有图形界面
- 传教士和野人问题(MC问题)的A*算法
- A*全局路径规划器ros
- 人工智能_滑动积木块—A*算法
评论
共有 条评论