diff --git a/HRD_cal.cpp b/HRD_cal.cpp index 242bc6d..082ec7c 100644 --- a/HRD_cal.cpp +++ b/HRD_cal.cpp @@ -71,6 +71,7 @@ void HRD_cal::init_data() { // 初始化数据结构 List_hash[i].clear(); } List.clear(); + List_step_num.clear(); List_source.clear(); } @@ -79,7 +80,8 @@ void HRD_cal::cal(unsigned long long Code) { // 广搜寻找目标 (输入编 Parse_Code(*start, Code); // 解译输入编码 List.push_back(start); // 加入根节点 List_source.push_back(0); - List_hash[0xffff & ((*start).code >> 16)].push_back(Code); + List_step_num.push_back(0); + List_hash[0xffff & ((*start).code >> 16)].push_back(0); now_move = 0; // 设置起始搜索节点编号为0 result = 0; flag = false; // 设置为暂未找到 @@ -92,17 +94,27 @@ void HRD_cal::cal(unsigned long long Code) { // 广搜寻找目标 (输入编 } void HRD_cal::Add_Case(Case_cal *dat) { // 将找到的布局加入队列中 - unsigned int i; + unsigned int i, x, y; int hash_index = 0xffff & ((*dat).code >> 16); // 取得哈希索引 for (i = 0; i < List_hash[hash_index].size(); i++) { // 遍历索引内容 - if (List_hash[hash_index][i] == (*dat).code) { // 发现重复 + if ((*List[List_hash[hash_index][i]]).code == (*dat).code) { // 发现重复 + if (List_step_num[List_hash[hash_index][i]] == List_step_num[now_move] + 1) { // 若找到的目标比多现在一步 + for (x = 0; x < 4; x++) { // 遍历freeze表 + for (y = 0; y < 5; y++) { + if ((*dat).freeze[x][y] == true) { // 将输入表合并到原先的表上 + (*List[List_hash[hash_index][i]]).freeze[x][y] = true; + } + } + } + } delete dat; // 释放空间 return; // 退出 } } + List_hash[hash_index].push_back(List.size()); // 加入哈希索引 List.push_back(dat); // 加入到队列中 List_source.push_back(now_move); // 记录溯源信息 - List_hash[hash_index].push_back((*dat).code); // 加入哈希索引 + List_step_num.push_back(List_step_num[now_move] + 1); // 记录最少步数信息 if (mode == 1) { // 寻解模式 if ((0xF & ((*dat).code >> 32)) == 0xD) { // 2 * 2块在出口位置 flag = true; // 标志已找到目标 diff --git a/HRD_cal.h b/HRD_cal.h index 8da4e76..2fd867d 100644 --- a/HRD_cal.h +++ b/HRD_cal.h @@ -20,14 +20,15 @@ class HRD_cal { unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 unsigned long long code; }; - vector List; // ÿڵϢ - vector List_source; // һ Դ - vector List_hash[0x10000]; // ϣ - unsigned int now_move; // ǰڼĿı - unsigned int result; // õĿ + vector List; // 主队列 储存每个节点的信息 + vector List_source; // 储存上一步编号 用于溯源 + vector List_step_num; // 记录到根节点的最少步数 + vector List_hash[0x10000]; // 哈希表 + unsigned int now_move; // 当前正在计算的块的编号 + unsigned int result; // 得到的目标编号 unsigned long long target_code; unsigned char mode; // 0 -> Calculate_All / 1 -> Calculate_Solution / 2 -> Calculate_Target - bool flag; // жǷҵĿ + bool flag; // 判断是否已找到目标 bool Parse_Code(Case_cal &dat, unsigned long long Code); void Get_Code(Case_cal &dat);