//**************************************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的更多相关文章

  1. Artificial intelligence(AI)

    ORM: https://github.com/sunkaixuan/SqlSugar 微软DEMO: https://github.com/Microsoft/BotBuilder 注册KEY:ht ...

  2. (转) Artificial intelligence, revealed

    Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...

  3. Artificial Intelligence Language

    Artificial Intelligence Language Objective We know, a true AI program should have ability to underst ...

  4. 拼写纠正 Artificial Intelligence: A Modern Approach

    Artificial Intelligence: A Modern Approach http://mindhacks.cn/2008/09/21/the-magical-bayesian-metho ...

  5. Artificial Intelligence Research Methodologies 人工智能研究方法

    Computer Science An Overview _J. Glenn Brookshear _11th Edition To appreciate the field of artificia ...

  6. UVa 537 Artificial Intelligence?

    题目大意:输入一个字符串,根据物理公式P=U*I,已知其中两个量,求第三个量,结果保留两位小数.   Artificial Intelligence?  Physics teachers in hig ...

  7. PAIP: Paradigms of Artificial Intelligence Programming

    PAIP: Paradigms of Artificial Intelligence Programming PAIP: Paradigms of Artificial Intelligence Pr ...

  8. c#-Artificial Intelligence Class

    NET Artificial Intelligence Class http://www.codeproject.com/KB/recipes/aforge_neuro/neuro_src.zip

  9. EECS 649 Introduction to Artificial Intelligence

    EECS 649 Introduction to Artificial IntelligenceExamElectronic Blackboard Submission Due: April 24, ...

  10. (转)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 ...

随机推荐

  1. cssText设置css样式

    js中用cssText设置css样式 (2012-08-21 10:40:22) 转载▼ 标签: js   如果网页中一个 id为“no”的标签,暂且当div标签来tell:想要在js中设置这个div ...

  2. container_of宏剖析

    container_of宏剖析//该宏位于include/linux/kernel.h 1.定义格式 /** * container_of - cast a member of a structure ...

  3. [经典] atoi && itoa

    atoi原型:int atoi(const char *nptr) atoi,需要考虑的内容: 1. 第一个字符为"-"时为负,系数为-1:为"+"时为正,系数 ...

  4. HibernateTemplate的find(String querystring)返回值具体解释

    项目源代码中出现例如以下代码: HibernateTemplate ht =-- List<Object[]> tempList = ht.find(String querystring) ...

  5. 苹果电脑出现 .DS_Store文件,删除不掉怎么处理?

    今天早上打开电脑,发现桌面上出现一个.DS_Store文件.可是出现的莫名其妙,也就没在意,可是重复删除之后还是出现.后来查了一下网上的资料,才知道,昨天我加入git的时候,为了看见 .git这个隐藏 ...

  6. Android TextView中有图片有文字混合排列

    Android TextView中有图片有文字混合排列 1.使用html.fromHtml 2.新建ImageGetter 3.使用<img src>标签 demo: 1.设置文字 ((T ...

  7. CCProgressTimer用法

    bool HelloWorld::init(){ if ( !CCLayerColor::initWithColor(ccc4(255, 255, 2555, 255))){ return false ...

  8. Cocos2d的特性

    从本质上说,Cocos2d是一个图形引擎,封装了复杂的图形接口,通过抽象出精灵.动作等概念,降低了游戏开发难度,简化了开发过程.Cocos2d-x为保证游戏能方便地移植到不同平台上,又在此基础上做了很 ...

  9. iOS 开发之 ReactiveCocoa(进阶)

    Map : 映射 UITextField *textField =[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 40)]; t ...

  10. java 窗口的一些示例代码,可直接运行

    代码链接如下: http://pan.baidu.com/s/1gdlCI4N 有应用SWING,也有应用AWT,可视情况而定. 窗口程序运行需要jdk1.7环境(测试可用).