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 ...
随机推荐
- datatables配置及数据传输
var merchant_url = "index.php?op=merchant"; var table_merchant_setting ={ "ajax" ...
- java的好资料总结
1jvm的垃圾回收http://wenku.baidu.com/link?url=gf08pYxNxVC2ZR607Qv9gn1pkFs5T1Pp5YHxISBEFdcz0D1HdK-7YOuSDft ...
- UVA 10256 The Great Divide (凸包,多边形的位置关系)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148 [思路] 凸包 求出红蓝点的凸包,剩下的问题就是判断两个凸 ...
- JavaScript高级程序设计36.pdf
TreeWalker TreeWalker是NodeIterator的更高级的版本,除了包括nextNode()和previousNode()在内的相同功能外,这个类型还提供了用于不同方向上遍历DOM ...
- Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1774 Solved: 644[Submit][Status] ...
- [转] rtp h264注意点(FU-A分包方式说明)
总括: 一帧视频数据可以编码成多个H264的NALU, 每个NALU的开头为00 00 00 01: 一个RTP包可以传送 部分.一个或多个 NALU,看NALU的大小而定. 之前写过一篇文章,分析了 ...
- Yii 的AR单行数据自动缓存机制
相关的YII类: CActiveRecord CActiveRecordBehavior cache Active Record Active Record (AR) 是一个流行的 对象-关系映射 ( ...
- 学习动态性能表 v$sql
学习动态性能表 第三篇-(1)-v$sql V$SQL中存储具体的SQL语句. 一条语句可以映射多个cursor,因为对象所指的cursor可以有不同用户(如例1).如果有多个cursor(子游标)存 ...
- Java实现简单版SVM
Java实现简单版SVM 近期的图像分类工作要用到latent svm,为了更加深入了解svm,自己动手实现一个简单版的. 之所以说是简单版,由于没实用到拉格朗日,对偶,核函数等等.而 ...
- JS家的排序算法
由于浏览器的原生支持(无需安装任何插件),用JS来学习数据结构和算法也许比c更加便捷些.因为只需一个浏览器就能啪啪啪的调试了.比如下图我学习归并排序算法时,只看代码感觉怎么都理解不了,但是结合chro ...