`
java-mans
  • 浏览: 11441699 次
文章分类
社区版块
存档分类
最新评论

Test

 
阅读更多

//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////

/*功能描述:
*Queen有3中动作模式:
*(1)单步模式
*(2)自动演示模式
*(3)自动求解最终答案模式
*接口:
*MoveNext()尝试往下移动,更新StepSaver内容,同时更新lastrow、lastcol,为下一步作准备
*Solve()求解主函数
*MoreSolve()更多解的求解调用入口
*/


Queen::Queen(
intn,intdelay)
{
if(n<1||n>32)
{
AfxMessageBox(_T(
"请选择2~32之间的数,当前n被强制设为32"));
n
=32;
}
N
=n;
lastcol
=(0),lastrow=(0),PlayDelay=(delay);
SampleSolve
=newStepSaver(N);
}

Queen::
~Queen()
{
deleteSampleSolve;

//necessary?
SampleSolve=0;
lastrow
=lastcol=0;
}

intQueen::Solve()
{
intret;
intcount=0;

do{
ret
=NextStep();
if(ret==FIND_ONE_SOLUTION)
count
++;
}
while(ret!=END_OF_SEARCH);

returncount;
}

intQueen::MoreSolve()
{

if(!SampleSolve)returnfalse;

SampleSolve
->UnSet(lastrow,lastcol);


if(lastcol>=N-1&&lastrow>=N-1)
returnfalse;
lastcol
=lastcol+1;
if(lastcol>=N)
lastrow
+=1;

returnSolve();
}



//单步演示,如论成功与否,每一步都要走
intQueen::NextStep()
{

introw=lastrow;//
intcol=lastcol;//

//先做出失败的假设,在returnfalse之前置好初值
lastrow=lastcol=N;

if(row>=N||col>=N)
returnEND_OF_SEARCH;//没有更多解了

//演示
Place(row,col);


//计算下一个待演示的位置
//当前是一个局部可用解,需要跳到下一行安排新的皇后,形成大一些的局部解
//若不是可用解,继续尝试在当前行安排当前皇后,或者退回到上一行接着上次的地方尝试。
//如果发现没有退路了,返回false
if(SampleSolve->IsCompatiable(row,col))
{
//标记当前可放位置
SampleSolve->Set(row,col);

//寻找下一个位置
row++;//nextline

///////////////////////////////////
///BUG!Fixme!
//////////////////////////////////
///if(row>=N)
///returnfalse;
///col=0
////////////////////////////////
///Fixed:
if(row>=N)//已经找到一个解。并且,需要寻找下一个解的初始出发点。
{
//row--;
col++;
while(row>=N||(row>=1&&col>=N)){//需要退格
row--;
col
=SampleSolve->GetCol(row);
SampleSolve
->UnSet(row,col);//先取消此行的摆放标记
col++;//得到待尝试格的col
}

//更新lastrow,lastcol
lastrow=row;
lastcol
=col;

if(row<=0&&col>=N)//已经退到了顶部之外,失败
returnEND_OF_SEARCH|FIND_ONE_SOLUTION;

returnFIND_ONE_SOLUTION;//

}
else{
col
=0;
}
}
else{
ASSERT(row
>=0);

col
++;//“一般情况”下的下一个位置

while(row>=1&&col>=N){//需要退格
row--;
col
=SampleSolve->GetCol(row);
SampleSolve
->UnSet(row,col);//先取消此行的摆放标记
col++;//得到待尝试格的col
}

if(row<=0&&col>=N)//已经退到了顶部之外,失败
returnEND_OF_SEARCH;
}

//更新lastrow,lastcol
lastrow=row;
lastcol
=col;

returnHAVE_NEXT_STEP;
}






BOOLQueen::Place(
intx,inty)
{
if(PlayDelay!=0){
SampleSolve
->TempSet(x,y);
((CQueenDlg
*)((CQueenDlg*)AfxGetApp()->m_pMainWnd))->UpdateCanvas();
//Sleep(PlayDelay);
SampleSolve->TempUnSet(x,y);
}
if(!SampleSolve->IsCompatiable(x,y))
returnfalse;
returntrue;
}

分享到:
评论

相关推荐

    parasoft c++Test9.0破解

    最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:plugins-c++Test For Visual Studio.7z

    Parasoft c++Test9.0破解文件

    c:\Program Files (x86)\Parasoft\C++test for Visual Studio\9.0\plugins\ 这个目录中 把plugins-Test for Virsual Studio.7z 中的文件覆盖到 c:\Program Files (x86)\Parasoft\Test for Visual Studio\9.0\...

    eNetTest 网管内网单机测速工具

    eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速工具eNetTest 网管内网单机测速...

    C++Test学习文档

    C++test 文档库包含以下各项: • C++test 用户手册 ( 当前指南): C++test 用户手册(当前指南):解释如何使用在 Eclipse 上构 建的 C++test 功能(如果您拥有单机版的 C++test),或者如何使用添加到 Eclipse 的...

    test3test3test3test3test3test3

    test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3

    Enabler Test Specification for SUPL V2.0

    This document describes in detail available test cases for SUPL V2.0, OMA-ERP-SUPL-V2_0. URL:http://www.openmobilealliance.org/ The test cases are split in two categories, conformance and ...

    C++ Test 7.2及9.2版本(附带许可证)学习资料!!

    内含 C++Test 两个版本的软件 、 VC++6.0(可以在Win 10 环境使用) 、 C++ Test 许可证书 、C语言编码规范(试用) 详细情况请见文章里面包含使用该软件的步骤及配置过程...

    c++ test9.5破解工具

    1.安装,安装时不能开vs,会安装失败 2.尽量选择独立安装一个配置cpptest_9_5 2.复制xtest.lic.client.dll...X:\Program Files\Parasoft\Test for Visual Studio\9.5\plugins\com.parasoft.xtest.libs.vstudio\Parasoft

    test.py_pythontest_python_

    test python programming language

    Cracking the GRE Mathematics Subject Test 4th Edition.pdf

    Getting a high score on the GRE Math Subject Test isn’t about memorizing everything there is to know about math–it’s about targeting your test preparation. We teach you only the information you’ll...

    software test automation effective use of test execution 自动化测试

    software test automation effective use of test execution 自动化测试

    LMS_Test.Lab中文操作指南.pdf

    LMS Test Lab是一款综合全面的振动噪声试验解决方案,其独特的工作流程设计界面,使得LMS Test Lab为系统的易用性、高效率和数据一致性确立了新的标准。为未来的振动噪声试验方式,提供了新的突破。 LMS Test Lab ...

    [Test Studio] 软件测试入门教程 (Test Studio 实现) (英文版)

    Embark on the exciting journey of test automation, execution, and reporting in Test Studio with this practical tutorial Overview Learn to use Test Studio to design and automate tests valued with ...

    C++test V1.3序列号

    C++test序列号 V1.3 C++Test是一个C/C++单元级测试工具,自动测试C/C++类、函数或部件,而不需要编写测试用例、测试驱动程序或桩调用代码。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和...

    Building a Successful Board-Test Strategy 2nd Edition

    Building a Successful Board-Test Strategy A successful test strategy is a byproduct of overall product life-cycle management. Anyone building such a strategy must consider the product's development, ...

    IPv6_Ready Self_Test

    Test Specification: 4.0.6 Self Test Tool: 5.0.0 Interoperability Test Scenario: 4.0.4 If you are going to run test from now, please use the newest version. However, in case the test specification ...

    c++test 中文使用说明

    C++Test是一个C/C++单元测试工具,自动测试任何C/C++类、函数或部件,而不需要您编写一个测试用例、测试驱动程序或桩调用。C++Test能够自动测试代码构造(白盒测试)、测试代码的功能性(黑盒测试)和维护代码的完整...

    workTest.rar

    从e:\mysql\test.sql中将文件中的SQL语句导入数据库中: 1.从命令行进入mysql,然后用命令CREATE DATABASE test2;创建数据库test2。 2.退出mysql 可以输入命令exit;或者quit; 3.在CMD中输入下列命令: c:\&gt;...

    Parasoftc++ Test 9.0破解文件

    最好用的单元测试工具,除了这里你是找不到9.0版本的破解的。 ... 独立的版本破解: ... 把lic_client.jar复制到 ... c:\Program Files (x86)\Parasoft\Test\9.0\plugins\...这个是:( plugins-Test for Virsual Studio.7z )

    TestComplete 7 破解

    把程序目录bin下:用TestComplete替换掉原有TestComplete 然后启动替换后的程序。 首次登陆按照如下设置: User Name: Eternal Shield Company Name: HOMEZ, Inc. Registration Code: 558B8FDC-6BF62C26-F83BF6FF

Global site tag (gtag.js) - Google Analytics