//**************************************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. Bzoj 3694: 最短路 树链剖分

    3694: 最短路 Time Limit: 5 Sec  Memory Limit: 256 MBSubmit: 67  Solved: 34[Submit][Status][Discuss] Des ...

  2. 3 weekend110的job提交的逻辑及YARN框架的技术机制 + MR程序的几种提交运行模式

    途径1: 途径2: 途径3: 成功! 由此,可以好好比较下,途径1和途径2 和途径3 的区别. 现在,来玩玩weekend110的joba提交的逻辑之源码跟踪 原来如此,weekend110的job提 ...

  3. [html][css]让文字在div中居中的方法[转]

    转至:http://dreamweaver.abang.com/od/divcss/a/vertical-align.htm 一.行高(line-height)法 如果要垂直居中的只有一行或几个文字, ...

  4. JSP实现数据库(MySQL)查询——Java Web练习(二)

    1.创建数据库表student(数据库test01) 2.修改success.jsp页面,修改后的页面整体代码如下: <%@ page language="java" imp ...

  5. MySQL自定义查询字段排序

    同事在做抽奖排名的时候有个问题 需要按照 一等奖 二等奖 三等奖 未中奖 的形式输出数据 问到我如何排序. 数据库设计如下 用一个prize_code字段标示了是否中奖 1是一等奖 2是二等奖 3是三 ...

  6. svn 被锁定

    遇到svn被锁定,clearup 不管用一直报错 用命令行解决了 问题 : command line -> cmd>svn help>svn cleanup>exit

  7. SAP HANA STRING_AGG

    HANA Version 1.00.73.00.389160 不支持STRING_AGG,所以只能,,,,,,,, DROP PROCEDURE ""."ZCONCAT_ ...

  8. HighCharts基本使用实例(入门)

    HighCharts 摘要 HighCharts是眼下最为流行的图表插件,应用范围广泛,眼下支持曲线图.区域图.3D图.柱状图.饼图.散列图.混合图等,而且还支持一些拓展的特殊图表,如:仪表图.极地图 ...

  9. 检测到有潜在危险的Request.Form值

    由于在.net中,Request时出现有HTML或Javascript等字符串时,系统会认为是危险性值.立马报出“从客户端 中检测到有潜在危险的Request.Form值”这样的错. 用encodeU ...

  10. FC网络学习笔记01

    1.Fibre Channel 也就是“网状通道”的意思,简称FC,可以称其为FC协议.FC网络或FC互联. 2.像TCP/IP一样,FC协议集同样具备TCP/IP协议集以及以太网中的概念,比如FC交 ...