-
大小: 3KB文件類型: .cpp金幣: 1下載: 0 次發布日期: 2021-01-03
- 語言: C/C++
- 標簽: c++??rengongzhine??bashuma??
資源簡介
人工智能的八數碼問題,廣度優先算法最為簡單,但是代碼數量相對較復雜。
代碼片段和文件信息
#include
struct?node
{
????int?xy[3][3];
????int?dir;
};
struct?node?sh[102]?end;
int?count?=?1;
void?init()
{
????printf(“輸入起始節點的位置:\n“);
????int?i?j;
????for?(i?=?0;?i?3;?i++)
????????for?(j?=?0;?j?3;?j++)
????????????scanf(“%d“?&sh[0].xy[i][j]);
????sh[0].dir?=?-1;
????printf(“輸入目標節點的位置:\n“);
????for?(i?=?0;?i?3;?i++)
????????for?(j?=?0;?j?3;?j++)
????????????scanf(“%d“?&sh[101].xy[i][j]);
????sh[101].dir?=?-1;
}
//找出0的位置
int?loction(int?num)
{
????int?i;
????for?(i?=?0;?i?9;?i++)
????????if?(sh[num].xy[i?/?3][i?%?3]?==?0)?
return?i;
}
//進行標記
long?long?sign(int?num)
{
????long?long??sum;
????sum?=?sh[num].xy[0][0]*100000000?+?sh[num].xy[0][1]*10000000?+?sh[num].xy[0][2]*1000000?+?sh[num].xy[1][0]*100000?+?sh[num].xy[1]
- 上一篇:BLDC 電機 加速算法
- 下一篇:SQP序列二次規劃算法小程序
評論
共有 條評論