Artificial Intelligence
//**************************************BEST-FS ALRORITHM IN ARTIFICAL INTELLIGENCE************************************** // Created by Clivia_zhou . 2014.7.29
#include <iostream>
using namespace std; //define functions
//Some function has'n finshied
typedef struct pqueue_t{}pqueue_t;
typedef struct queue_t{}queue_t;
typedef struct node_t
{
int g;
int h;
unsigned short board;
}node_t; void generateChildNodes(pqueue_t*,queue_t*,node_t*); void dePQueue(pqueue_t*,int*,int); bool isEmptyPQueue(pqueue_t*); void emitBoard(node_t*); bool checkPiece(unsigned short,int); bool searchQueue(queue_t*,unsigned short); void createNode(pqueue_t*,queue_t*,unsigned short,int); // The best_fs is the main function of best-first-search
void best_fs(pqueue_t *open_pq_p,queue_t* closed_q_p)
{
node_t *node_p;
int cost; while(!isEmptyPQueue(open_pq_p))
{ dePQueue(open_pq_p,(int*)&node_p,cost); if(node_p->g == )
{
printf("Found Solution(depth:%d):\n",node_p->h);
emitBoard(node_p);
break;
} generateChildNodes(open_pq_p,closed_q_p,node_p);
}
return ;
} //The generateChildNodes is the solution of every step
void generateChildNodes(pqueue_t *pq_p,queue_t *closed_q_p,node_t* node_p)
{
int i; unsigned short cboard1,cboard2; const int moves[] = {-,,,,-,,,,-,,,,-,,,}; for(i = ;i<;i++)
{
if(checkPiece(node_p->board,i))
{
cboard1 = cboard2 = (node_p->board & ~(<<( - i))); if(moves[i] == -)
{
cboard1 |= (<<(-(i + ))); if(!searchQueue(closed_q_p,cboard1))
{
(void)createNode(pq_p,closed_q_p,cboard1,node_p->h+);
}
} else if(moves[i] == )
{
cboard1 |= (<<(-(i + ))); if(!searchQueue(closed_q_p,cboard1))
{
(void)createNode(pq_p,closed_q_p,cboard1,node_p->h+);
} cboard2 |= (<<(-(i - ))); if(!searchQueue(closed_q_p,cboard2))
{
(void)createNode(pq_p,closed_q_p,cboard2,node_p->h+);
} } else if(moves[i] == )
{
cboard2 |= (<<( - (i-))); if(searchQueue(closed_q_p,cboard2))
{
(void)createNode(pq_p,closed_q_p,cboard2,node_p->h+);
}
}
}
}
return ;
}
Artificial Intelligence的更多相关文章
- Artificial intelligence(AI)
ORM: https://github.com/sunkaixuan/SqlSugar 微软DEMO: https://github.com/Microsoft/BotBuilder 注册KEY:ht ...
- (转) Artificial intelligence, revealed
Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...
- Artificial Intelligence Language
Artificial Intelligence Language Objective We know, a true AI program should have ability to underst ...
- 拼写纠正 Artificial Intelligence: A Modern Approach
Artificial Intelligence: A Modern Approach http://mindhacks.cn/2008/09/21/the-magical-bayesian-metho ...
- Artificial Intelligence Research Methodologies 人工智能研究方法
Computer Science An Overview _J. Glenn Brookshear _11th Edition To appreciate the field of artificia ...
- UVa 537 Artificial Intelligence?
题目大意:输入一个字符串,根据物理公式P=U*I,已知其中两个量,求第三个量,结果保留两位小数. Artificial Intelligence? Physics teachers in hig ...
- PAIP: Paradigms of Artificial Intelligence Programming
PAIP: Paradigms of Artificial Intelligence Programming PAIP: Paradigms of Artificial Intelligence Pr ...
- c#-Artificial Intelligence Class
NET Artificial Intelligence Class http://www.codeproject.com/KB/recipes/aforge_neuro/neuro_src.zip
- EECS 649 Introduction to Artificial Intelligence
EECS 649 Introduction to Artificial IntelligenceExamElectronic Blackboard Submission Due: April 24, ...
- (转)A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers
A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers. Updated 20 ...
随机推荐
- Unity 官方 Demo: 2DPlatformer 的 SLua 版本。
9月份时,趁着国庆阅兵的假期,将 Unity 官方 Demo: 2DPlatformer 移植了一个 SLua 版本,并放在了我的 GitHub 账号下:https://github.com/yauk ...
- datatables配置及数据传输
var merchant_url = "index.php?op=merchant"; var table_merchant_setting ={ "ajax" ...
- centOS 下解压 rar zip 文件
闲话不说,centos上如何安装rar.unrar在线解压缩软件呢?如果您的centos是32位的,执行如下命令: wget http://www.rarsoft.com/rar/rarlinux-3 ...
- octopress Endless Error With Gem Dependencies
因为重装系统的缘故,需要重新搭建octopress环境,在执行到: bundle install 会出现一些这样的错误:An error occurred while installing timer ...
- BigInteger Uva
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static ...
- linux 下查看网速的方法 (不需要安装任何软件)
sudo watch -n 1 "/sbin/ifconfig eth0 | grep -E \"字节|数据包\"" 若是英文版linux: sudo watc ...
- hdoj 3785 寻找大富翁【优先队列+sort排序】
寻找大富翁 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- oc学习之路----多级指针的使用和内存分析
---恢复内容开始--- 精髓:要熟悉指针的使用,首先要熟悉指针的各种状态存得是什么数据.(以一级指针 int *p1 二级指针:int **p2 三级指针:int ***p3为例) 一级指针:*p1 ...
- Idea实现WebService实例 转
作者:http://blog.csdn.net/dreamfly88/article/details/52350370 因为工作需要,数据传输部分需要使用webservice实现,经过两天的研究,实现 ...
- nginx定时备份access访问日志并重启nginx
用.sh脚本写了备份日志脚本 其实就是转移文件改名后重新建一个空文件 mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access ...