资源简介
我最近写了一个拼图游戏,给大家看看 、、、、

代码片段和文件信息
//#include
#include “stdafx.h“
#include “jg.h“
using namespace std;
CSloveJG::CSloveJG(string state)
{
m_initalstate = state;
m_filename = state;
m_vopen.clear();
m_vclosed.clear();
m_vG.clear();
m_vslove.clear();
}
CSloveJG::~CSloveJG()
{
}
bool CSloveJG::iscanslove()
{
string strTmp = “123456780“;
string s0 = m_initalstate;
int i0igij;
i0 = ig = 0;
for( i = 0;i <= 8; i++)
{
if (s0[i] == ‘0‘)
continue;
for( j = 0;j < i; j++)
{
if (s0[j]==‘0‘)
continue;
if ((s0[j]-‘0‘)<(s0[i]-‘0‘))
i0++;
}
}
for( i = 0;i <= 8; i++)
{
if (strTmp[i] == ‘0‘)
continue;
for( j = 0;j < i; j++)
{
if (strTmp[j] == ‘0‘)
continue;
if ((strTmp[j]-‘0‘) < (strTmp[i]-‘0‘))
ig++;
}
}
return((i0-ig)%2 == 0);
}
bool computer_f(pJGState s1 pJGState s2)
{
if((s1->g+s1->h) > (s2->g+s2->h))
return true;
else
return false;
}
int CSloveJG::computer_h(pJGState js)
{
char* ps = js->state;
string s = “012345678“;
string sg = “123456780“; //目标状态序列
char* psg = (char*)sg.c_str();
int h = 0;
int temptempg;
for(int i = 0;i <= 8;i++)
{
if(s[i] == ‘0‘)
continue; //0的距离已经包含在其他数字的移动过程中,所以应该舍去
temp = strchr(pss[i])-ps;
tempg = strchr(psgs[i])-psg;
h += abs(temp/3-tempg/3) + abs(temp%3-tempg%3);
}
return h;
}
void CSloveJG::copystate(pJGState s1 pJGState s2)
{
s1->father = s2->father;
s1->g = s2->g;
s1->h = s2->h;
strcpy(s1->state s2->state);
return;
}
pJGState CSloveJG::BornState(pJGState ps int r int father)
{
int position = strchr(ps->state‘0‘)-ps->state;
char * pTmpstr = new char[10];
strcpy(pTmpstr ps->state);
string sn = pTmpstr;
pJGState pSon = new JGState[sizeof(pSon)];
pSon->state = new char[10];
switch (r)
{
case 1: //下
if (position/3 == 2 )
{
delete [] pSon->state;
delete [] pSon;
return NULL;
}
sn[position] = sn[position+3];
sn[position+3] =‘0‘;
strcpy(pSon->state(char*)sn.c_str());
pSon->father = father;//vclosed.size()-1;
pSon->h = computer_h(pSon);
pSon->g =ps->g+1;
delete [] pTmpstr;
return pSon;
case 2: //下
if (position/3 == 0 )
{
delete [] pSon->state;
delete [] pSon;
return NULL;
}
sn[position] = sn[position-3];
sn[position-3] = ‘0‘;
strcpy(pSon->state(char*)sn.c_str());
pSon->father = father;//vclosed.size()-1;
pSon->h = computer_h(pSon);
pSon->g = ps->g+1;
delete [] pTmpstr;
return pSon;
case 3: //左
if (position%3 == 2 )
{
delete [] pSon->state;
delete [] pSon;
return NULL;
}
sn[position] = sn[position+1];
sn[position+1] =‘0‘;
strcpy(pSon->state(char*)sn.c_str());
pSon->father = father;//vclosed.size()-1;
pSon->h = computer_h(pSon);
pSon->g = ps->g+1;
delete [] pTmpstr;
return pSon;
case 4: //右
if (position%3 == 0 )
{
delete [] pSon->state;
delete [
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 242 2009-04-27 21:59 jiugong\435071268
文件 68013 2009-04-01 14:44 jiugong\Debug\jg.obj
文件 0 2009-04-01 14:44 jiugong\Debug\jg.sbr
文件 4162560 2009-04-01 15:21 jiugong\Debug\jiugong.bsc
文件 614465 2009-04-01 15:21 jiugong\Debug\jiugong.exe
文件 276660 2009-04-01 15:21 jiugong\Debug\jiugong.ilk
文件 28848 2009-04-01 14:44 jiugong\Debug\jiugong.obj
文件 7079500 2009-04-01 14:39 jiugong\Debug\jiugong.pch
文件 484352 2009-04-01 15:21 jiugong\Debug\jiugong.pdb
文件 407528 2009-04-01 14:39 jiugong\Debug\jiugong.res
文件 0 2009-04-01 14:44 jiugong\Debug\jiugong.sbr
文件 48603 2009-04-01 15:21 jiugong\Debug\jiugongDlg.obj
文件 0 2009-04-01 15:21 jiugong\Debug\jiugongDlg.sbr
文件 105915 2009-04-01 14:39 jiugong\Debug\StdAfx.obj
文件 1374561 2009-04-01 14:39 jiugong\Debug\StdAfx.sbr
文件 271360 2009-04-27 21:59 jiugong\Debug\vc60.idb
文件 471040 2009-04-01 15:21 jiugong\Debug\vc60.pdb
文件 5379 2009-04-01 14:44 jiugong\jg.cpp
文件 1015 2009-04-01 14:39 jiugong\jg.h
文件 440604 2009-04-01 14:36 jiugong\jiugong.aps
文件 1058 2009-04-27 21:59 jiugong\jiugong.clw
文件 2077 2009-03-29 20:41 jiugong\jiugong.cpp
文件 4294 2009-04-01 14:48 jiugong\jiugong.dsp
文件 522 2009-03-29 20:41 jiugong\jiugong.dsw
文件 1335 2009-03-29 20:41 jiugong\jiugong.h
文件 66560 2009-04-27 22:00 jiugong\jiugong.ncb
文件 274944 2009-04-27 22:00 jiugong\jiugong.opt
文件 248 2009-04-27 21:59 jiugong\jiugong.plg
文件 5324 2009-04-01 14:36 jiugong\jiugong.rc
文件 6748 2009-04-01 15:21 jiugong\jiugongDlg.cpp
............此处省略15个文件信息
- 上一篇:多种FLASH图片切换效果
- 下一篇:sjl06加密机模拟程序
相关资源
- SVR算法程序可运行
- 计算机图形学 边填充算法实现代码
- 福建师范大学历年算法考卷
- 栈的实现及应用,六种基本算法
- 基于MFC扩展CListCtrl子项显示图片并叠
- Windows异步套接字网络编程
- 黑白棋(带简单AI)
- Bresenham算法绘制线段并利用“橡皮筋
- 介绍几种压缩算法及《笨笨数据压缩
- VC 获得文件属性 获取文件的创建时
- 基于MVC模式的会员管理系统
- 改进的BP神经网络算法
- silicon lab公司的收音IC SI47XX全套开发工
- 读者写者问题(读者优先,写者优先
- A星算法_原理讲解_例子
- MFC程序-碰撞的小球
- vc 柱形图 CBarChart
- 云模型的相关算法cloud
- 旋转矩阵求欧拉角的简单算法
- 用vc 写的导线测量,针对刚学测绘的
- 用VC 编写的仿QQ聊天室程序源代码
- 栅栏填充算法源码(VC)
-
Cme
taFileDC的使用示例 - ado数据库MFC图书管理系统vs2010
- mfc单文档窗体画线与写字
- RSA算法源码
- 关联分析Apriori算法实现
- [免费]relax算法成像
- 简单的房屋租赁系统
- .net网站服装销售系统(MVC)
评论
共有 条评论