//**************************************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. Dot Net设计模式—MVC模式

    1 MVC设计模式简介 MVC结构是为那些需要为同样的数据提供多个视图的应用程序而设计的,它很好的实现了数据层与表示层的分离.MVC作为一种开发模型,通常用于分布式应用系统的设计和分析中,以及用于确定 ...

  2. (转载)TRS的WCM6漏洞权限绕过以及绕过密码的登陆方式

    转载于:http://www.2cto.com/Article/201302/191261.html 1.由来:建立在 TRS的WCM6可直接获取管理员密码 漏洞的基础上   2.首先访问wcm目录, ...

  3. POI2001 金矿

    问题描述 金矿的老师傅年底要退休了.经理为了奖赏他的尽职尽责的工作,决定在一块包含 n(n ≤ 15000) 个采金点的长方形土地中划出一块长度为 S ,宽度为 W 的区域奖励给他(1 ≤ s , w ...

  4. 如何使用chown?

    以test为例,目前test归root用户拥有,也归root组拥有 [root@localhost home]# ls -al total 36 drwxr-xr-x    6 root     ro ...

  5. Tab选项卡切换卡JS效果

    <script type="text/javascript"> /* tab切换选项卡js效果 writed by *** 2010.08.13 1.currentid ...

  6. eclipse设置项目发布到tomcat webaap下

    之前用myeclipse,自动deploy到web app下.目前的项目换了eclipse,项目被发布到本地,通过一个链接到tomcat中,很不习惯. 设置的地方很隐晦,在tomcat中,而不是在pr ...

  7. 三种纯CSS实现三角形的方法

    看到像上图这样的 tip 的小三角,你会怎么办? 切个图上去?恩,不错,简单,兼容性也一级棒,不但好控制,那点小东西也增加不了多少图片的大小.但有没有更好更讲究技巧的办法呢?哈哈,那必须有啊,而且还不 ...

  8. javascript如何监听页面刷新和页面关闭事件

    本文转之http://www.qqtimezone.top 在我们的日常生活中,时常遇到这么一种情况,当我们在点击一个链接.关闭页面.表单提交时等情况,会提示我们是否确认该操作等信息. 这里就给大家讲 ...

  9. iOS开发总结-UITableView 自定义cell和动态计算cell的高度

    UITableView cell自定义头文件:shopCell.h#import <UIKit/UIKit.h>@interface shopCell : UITableViewCell@ ...

  10. tar linux 打包 压缩 gzip 命令说明

    参数:-c  :建立一个压缩档案的参数指令(create 的意思):-x  :解开一个压缩档案的参数指令!-t  :查看 tarfile 里面的档案!      特别注意,在参数的下达中, c/x/t ...