- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
骑士周游(Knight tour)
骑士周游(Knight tour)
/ /练习7.24 B部分的解决方案:ex07_24.cpp
/骑士的旅行-访问版本
/运行一次旅行
#包含iostream
使用std::cout;
使用std::endl;
#包括iomanip
使用std::SEtW商店;
#包括文件cstdlib
使用STD::兰德;
使用std::srand;
#包括 CTime
使用STD::时间;
常量int大小= 8;
虚空ClearBoard(int [] [大小]);
无效的印刷板(const int [] [大小]);
布尔validmove(int,int,const int [] [大小]);
国际main()
{
棋盘大小[尺寸];
国际currentrow;
国际currentcolumn;
国际movenumber = 1;
国际testrow;
国际testcolumn;
智力水平[大小] = { 2, 1,1,2,2,1, 1, 2 };
国际垂直[尺寸] = { 1,2,2,1, 1, 2,2, 1 };
int类型;
布尔做;
布尔goodmove;
srand(time(0));
ClearBoard(板);//初始化阵列板
currentrow = rand() % 8;
currentcolumn = rand() % 8;
板[ currentrow ] [ currentcolumn ] = movenumber + +;
做=假;
/继续,直到骑士不能移动为止
而(!做的)
{
类型= 0;
testrow = currentrow +垂直[类型];
testcolumn = currentcolumn +水平[类型];
goodmove = validmove(testrow,testcolumn,板);
/测试如果需要的移动是有效的
如果(goodmove)
{
currentrow = testrow;
currentcolumn = testcolumn;
板[ currentrow ] [ currentcolumn ] = movenumber + +;
} /结束
其他的
{
如果移动不合法,尝试另一个动作。
为(int = 0;计算大小1)!goodmove;计数+ +)
{
类型= + +类型%的大小;
testrow = currentrow +垂直[类型];
testcolumn = currentcolumn +水平[类型];
goodmove = validmove(testrow,testcolumn,板);
测试新动作是否有效
如果(goodmove)
{
Currentrow = testrow;
Currentcolumn = testcolumn;
Currentrow Board [] [currentcolumn] = movenumber + +;
} / / end if
} / / end is
/ / if no valid moves, knight can no longer move
If (! Goodmove)
Done = true;
} / / end else
/ / if 64 moves have been made, the full tour is complete
If (movenumber - 1 = = 64)
Done = true;
} / / end while
Cout the tour ended with movenumber - 1 moves. \ n;
/ / test and display whether the full tour was made
If (movenumber - 1 = = 64)
Cout this was a full tour! \ n \ n ;
Else
Cout this was not a full tour. \ n \ n;
Cout the board for this test is: \ n \ n;
Printboard (board);
Return 0; / / indicates successful termination
} / / end main
/ / function to clear the chess board.
Void ClearBoard (int workboard [] [size])
{
/ / set all squares to zero
对于(int行= 0;行大小;行+ +)
{
为(int = 0;
工作板[行] [西] = 0;
结束
} //函数结束ClearBoard
印制
您可能关注的文档
- 韩氏分支(Han branch).doc
- 韩愈神道碑_皇甫(Han Yu Huangfu _ tombstone).doc
- 韩玉森教授筋出槽、骨错位(Professor Han Yusen's tendon groove and bone dislocation).doc
- 韩静霆母爱是船也是岸(Han Jingting a mother's love is a ship as well as an ocean).doc
- 韬晦术(明朝杨慎)(To operation (Ming Yang Shen)).doc
- 韭菜沟 - 副本4(Leek ditch - copy 4).doc
- 韭菜栽培技术(Leek cultivation techniques).doc
- 韩剧标准定律20条(Standard law of Korean drama 20).doc
- 韭菜的药用价值(Medicinal value of leek).doc
- 韩熙载夜宴图论文(The Han Xizai banquet map).doc
文档评论(0)