91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 457KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-13
  • 語言: C/C++
  • 標簽: 8數碼??c++??源代碼??

資源簡介

參見我的博文:http://blog.csdn.net/j56754gefge/article/details/47170967 這是8數碼問題的一套完整解決方案,包括問題模型、搜索方法、界面表示等。有問題請給我發郵件,代碼里面有我mail

資源截圖

代碼片段和文件信息

#include?“Astar.h“
#include?
#include?
using?namespace?std;

int?Astar::node::search_mode;


Astar::Astar()
{
movement[0]?=?&node::up;?
movement[1]?=?&node::down;?
movement[2]?=?&node::left;?
movement[3]?=?&node::right;
}


unsigned?char??Astar::getInverseNumber(?unsigned?char?num[9]?)
{
unsigned?char?inverse_number?=?0;
for(?unsigned?char?i=0;?i<8;?i++?)
if(?num[i]?)
for(?unsigned?char?j=i+1;?j<9;?j++?)
if(?num[j]?&&?num[i]?>?num[j]?)
inverse_number++;
return?inverse_number%2;?//?0?or?1
}

bool??Astar::reachable(?unsigned?char?num[9]?)
{
unsigned?char?n?=?getInverseNumber(?num?);
unsigned?char?goal_inverse_number?=?getInverseNumber(?puzzle8::goal?);
return?n==goal_inverse_number;
}

int??Astar::seearch(?unsigned?char?init_state[9]?MODE?mode?)
{
node::search_mode?=?mode;
if(?!reachable(?init_state?)?)
return?-1;
node?*current?=?new?node;
current->state.set(?init_state?);
if(?current->isGoal()?){
delete?current;
return?0;
}
//?store?all?allocated?nodes?as?well?as?the?corresponding?eigen?value
map?caches;?//?all?nodes
map::iterator?cache_iter;
unsigned?long?long?key[4];
current->state.toEigenVal(?key?);
caches[key[0]]?=?current;
//?queue?each?leaf?node?according?to?its?priority
priority_queue?>?open_table;?//?nodes?to?expand
open_table.push(?make_pair(-current->cost()current)?);
//?search
bool?stopped?=?false;
for(?int?cnt=0;?!open_table.empty()?&&?!stopped;?cnt++?){
current?=?open_table.top().second;
open_table.pop();
//current->state.print();?cout< //?try?to?expand:?get?child?node‘s?eigen?value?to?test?if?it?has?been?found?before
current->state.children(?key?);
int?child_depth?=?current->depth?+?1;
for(?int?m=0;?m<4;?m++?){
if(?!key[m]?)
continue;
cache_iter?=?caches.find(?key[m]?);
bool?not_found?=?cache_iter==caches.end();
//?if?the?child?node?is?new?or?though?it?was?found?before?but?now?is?with?a?shallow?depth
//?then?we?should?indeed?create?it?add?it?to?our?queue
if(?not_found?||?child_depth?second->depth?){
node?*next?=?(current->*(movement[m]))();
if(?not_found?)
caches[key[m]]?=?next;
else
cache_iter->second?=?next;
open_table.push(?make_pair(-next->cost()next)?);
if(?next->isGoal()?){
current?=?next;
stopped?=?true;
break;
}
}
}
}
//?searching?is?done.?now?retrieve?path?by?backtracking
if(?!current->isGoal()?)
return?-1;
vector?move_path;
while(?current->parent?){
move_path.push_back(?current?);
current?=?current->parent;
}
int?search_depth?=?move_path.size();
search_result.resize(?search_depth?);
vector::iterator?result_itr?=?search_result.begin();
for(?vector::reverse_iterator?itr=move_path.rbegin();?itr!=move_path.rend();?itr++?)
*(resu

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-31?16:32??8數碼\
?????文件?????1173504??2015-07-31?16:29??8數碼\8數碼.exe
?????文件????????4101??2015-07-31?16:29??8數碼\Astar.cpp
?????文件????????2192??2015-07-31?16:28??8數碼\Astar.h
?????文件????????2150??2015-07-31?16:23??8數碼\demo.cpp
?????文件?????????259??2015-07-30?19:07??8數碼\puzzle8.cpp
?????文件????????5104??2015-07-31?16:28??8數碼\puzzle8.h
?????文件????????4324??2015-07-31?13:16??8數碼\puzzle_game.cpp
?????文件?????????660??2015-07-31?12:10??8數碼\puzzle_game.h

評論

共有 條評論