资源简介
我最近写了一个拼图游戏,给大家看看 、、、、
代码片段和文件信息
//#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加密机模拟程序
相关资源
- 车辆路径问题的粒子群算法研究与应
- 中国地图着色
- 蚁群算法在机器人路径规划中的应用
- 基于博弈论的认知无线电功率控制算
- 小闹钟VC课程设计定时提醒任务功能。
- 软抠图算法流程,主要讲解柔和交织
- DevComponents.DotNetBar214.0.0.15破解版.rar
- Gardner算法FPGA开发工程
- msvcp120d .dll、msvcr120d.dll包括32位和64位
- 传说的stm32的DSP库包括fft算法及文档
- K-Means图像分割算法实现
- 椭圆曲线加密算法verilog代码强力推荐
- verilog冒泡排序算法
- VC数字图像处理 特效显示代码
- VC串口通信上位机控制单片机led灯亮灭
- 基于深度学习的图像语义分割算法综
- 中文地址名称识别算法设计和实现
- 欧姆龙PLC以太网通讯在线调试过OK
- 正向最大匹配中文分词算法
- 加密解密算法工具集
- 基于云计算环境的蚁群优化计算资源
- 《终极算法:机器学习和人工智能如
- rcnn、fast rcnn、faster rcnn和yolo的算法原
- 网络流:理论、算法与应用 Network F
- 基于Maven的SpringMVC整合UEditor,可单独
- VC画波形图,二进制读写文件
- vc_web.rar
- 案例11-二维图形几何变换算法.zip
- SVM分类算法.zip
- 多机调度(贪心算法).rar
评论
共有 条评论