diff --git a/src/engine/HRD_analy.cpp b/src/engine/HRD_analy.cpp index c1af545..f09bf5e 100644 --- a/src/engine/HRD_analy.cpp +++ b/src/engine/HRD_analy.cpp @@ -27,7 +27,7 @@ void HRD_analy::Output_Graph(unsigned long long Code, unsigned int square_width, Parse_Code(dat, Code); for (y = 0; y < 5; y++) { // 遍历20个格 for (x = 0; x < 4; x++) { - if (exclude[x][y] == true || dat.status[x][y] == 0xFE) {continue;} // 该格为空或已被占用 + if (exclude[x][y] || dat.status[x][y] == 0xFE) {continue;} // 该格为空或已被占用 switch (dat.type[dat.status[x][y]]) { // type -> 0 / 1 / 2 / 3 case 0: // 2 * 2 width = height = 2; @@ -83,7 +83,7 @@ void HRD_analy::Output_Graph(unsigned long long Code, unsigned int square_width, cout << " "; } for (x = 0; x < width; x++) { - if (temp[x][y] == true) { + if (temp[x][y]) { cout << str; } else { cout << " "; @@ -111,7 +111,7 @@ void HRD_analy::Output_Detail(string File_name) { // 输出分析结果到文件 unsigned int i, j, k; ofstream output; vector case_list; - if (quiet == false) { + if (!quiet) { cout << "Output into: " << File_name << "..."; } output.open(File_name); @@ -174,7 +174,7 @@ void HRD_analy::Output_Detail(string File_name) { // 输出分析结果到文件 } } output.close(); - if (quiet == false) { + if (!quiet) { cout << "done" << endl; } } @@ -192,7 +192,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的 solution_num = 0; // 初始化solution solution_case.clear(); solution_step.clear(); - if (Check_Code(code) == false) {return;} // 若编码错误则退出 + if (!Check_Code(code)) {return;} // 若编码错误则退出 Calculate(code); // 计算分层数据 solution_flag.resize(Layer.size()); // 同步Layer的结构 for (i = 0; i < solution_flag.size(); i++) { @@ -232,7 +232,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的 } for (i = 0; i < Layer.size() - 1; i++) { // 遍历除最后一层外的所有层 for (j = 0; j < Layer[i].size(); j++) { // 遍历层内元素 - if (solution_flag[i][j] == true) { // 若该元素被标识 + if (solution_flag[i][j]) { // 若该元素被标识 case_list = (*(*Layer[i][j]).adjacent).next_case; for (k = 0; k < case_list.size(); k++) { // 遍历其下一步 solution_flag[i + 1][(*case_list[k]).layer_index] = true; // 标识 @@ -241,7 +241,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的 } temp.clear(); for (j = 0; j < Layer[i + 1].size(); j++) { // 遍历下一层内元素 - if (solution_flag[i + 1][j] == false) { // 得到未被标识的元素 + if (!solution_flag[i + 1][j]) { // 得到未被标识的元素 if (((*Layer[i + 1][j]).code >> 32) == 0xD) { // 若为解的布局 temp.push_back((*Layer[i + 1][j]).code); // 先加入到temp中方便排序 solution_step.push_back(i + 1); @@ -255,7 +255,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的 } } solution_num = solution_case.size(); - if (quiet == true) {return;} // 若quiet为true则不输出 + if (quiet) {return;} // 若quiet为true则不输出 cout << "---------------------------" << endl; cout << "farthest_step = " << farthest_step << endl; cout << "farthest_num = " << farthest_num << endl; @@ -297,7 +297,7 @@ void HRD_analy::Calculate(unsigned long long code) { Free_Data(); // 初始化数据结构 Case_cal *start = new Case_cal; (*start).adjacent = new Case_near; - if (Parse_Code(*start, code) == false) { // 若输入编码错误 退出 + if (!Parse_Code(*start, code)) { // 若输入编码错误 退出 delete (*start).adjacent; delete start; return; @@ -319,7 +319,7 @@ void HRD_analy::Calculate(unsigned long long code) { } now_move_num++; // 计算目标移到下一层第一个元素 now_move_index = 0; - if (quiet == false) { + if (!quiet) { cout << now_move_num << " -> " << Layer[now_move_num].size() << endl; } } else { // 不是最后一个元素 @@ -341,7 +341,7 @@ void HRD_analy::Add_Case(Case_cal *dat) { // 将计算得到的节点加入层 (*(*now_move_case).adjacent).next_case.push_back(repeat_case); // 记录子节点信息 for (x = 0; x < 4; x++) { // 遍历freeze表 for (y = 0; y < 5; y++) { - if ((*dat).freeze[x][y] == true) { // 将输入表合并到原先的表上 + if ((*dat).freeze[x][y]) { // 将输入表合并到原先的表上 (*repeat_case).freeze[x][y] = true; } } @@ -366,14 +366,14 @@ void HRD_analy::Find_Next_Case(Case_cal &dat_raw) { // 找到下一步移动的 Case_cal dat = dat_raw; for (y = 0; y < 5; y++) { // 仅保留空格位置的freeze为true for (x = 0; x < 4; x++) { - if (dat.status[x][y] != 0xFE && dat.freeze[x][y] == true) { // 不为空格但freeze为true + if (dat.status[x][y] != 0xFE && dat.freeze[x][y]) { // 不为空格但freeze为true dat.freeze[x][y] = false; // 重置为false } } } for (y = 0; y < 5; y++) { // 遍历整个棋盘 for (x = 0; x < 4; x++) { - if (dat_raw.freeze[x][y] == true) {continue;} // 遇到freeze为true的跳过 + if (dat_raw.freeze[x][y]) {continue;} // 遇到freeze为true的跳过 num = dat.status[x][y]; // 统一修改(x, y)块 dat.status[x][y] = 0xFE; dat.freeze[x][y] = true; @@ -513,7 +513,7 @@ void HRD_analy::Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4 } void HRD_analy::Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]) { // 实现移动并将结果发送到Add_Case - if (addr[x][y] == true) { // 重复 + if (addr[x][y]) { // 重复 return; // 退出 } else { addr[x][y] = true; // 加入位置数据 @@ -557,7 +557,7 @@ void HRD_analy::Get_Code(Case_cal &dat) { // 获取编码并存储在dat.code num = 0; for (y = 0; y < 5; y++) { // 遍历20个格 for (x = 0; x < 4; x++) { - if (temp[x][y] == true) {continue;} // 该格已被占用 + if (temp[x][y]) {continue;} // 该格已被占用 if (dat.status[x][y] == 0xFE) { // space num++; dat.code <<= 2; diff --git a/src/engine/HRD_cal.cpp b/src/engine/HRD_cal.cpp index da5192b..0cce608 100644 --- a/src/engine/HRD_cal.cpp +++ b/src/engine/HRD_cal.cpp @@ -8,7 +8,7 @@ vector HRD_cal::Calculate_All(unsigned long long Code) { // vector data; init_data(); // 初始化 mode = 0; // 设置模式为全集计算 - if (Check_Code(Code) == false) { // 编码错误 + if (!Check_Code(Code)) { // 编码错误 return data; // 返回空序列 } cal(Code); // 进行广搜 @@ -21,7 +21,7 @@ vector HRD_cal::Calculate_All(unsigned long long Code) { // vector HRD_cal::Calculate(unsigned long long Code, unsigned long long target) { // 寻找到target的最短路径 vector temp; - if (Check_Code(Code) == false || Check_Code(target) == false) { // 编码错误 + if (!(Check_Code(Code) && Check_Code(target))) { // 编码错误 return temp; // 返回空序列 } if (Code == target) { // 若输入为target @@ -32,7 +32,7 @@ vector HRD_cal::Calculate(unsigned long long Code, unsigned mode = 2; // 设置模式为寻找特定目标 target_code = target; cal(Code); // 进行广搜 - if (flag == true) { // 若找到目标 + if (flag) { // 若找到目标 return Get_Path(result); } else { // 未找到目标 init_data(); // 防止内存泄漏 @@ -42,7 +42,7 @@ vector HRD_cal::Calculate(unsigned long long Code, unsigned vector HRD_cal::Calculate(unsigned long long Code) { // 寻找最少步解 vector temp; - if (Check_Code(Code) == false) { // 编码错误 + if (!Check_Code(Code)) { // 编码错误 return temp; // 返回空序列 } if ((Code >> 32) == 0xD) { // 若输入已经为解 @@ -52,7 +52,7 @@ vector HRD_cal::Calculate(unsigned long long Code) { // 寻 init_data(); // 初始化 mode = 1; // 设置模式为寻解 cal(Code); // 进行广搜 - if (flag == true) { // 若找到解 + if (flag) { // 若找到解 return Get_Path(result); } else { // 无解 init_data(); // 防止内存泄漏 @@ -96,18 +96,17 @@ void HRD_cal::cal(unsigned long long Code) { // 广搜寻找目标 now_move = 0; // 设置起始搜索节点编号为0 result = 0; flag = false; // 设置为暂未找到 - if (Parse_Code(*start, Code) == false) { // 若输入编码错误 退出 + if (!Parse_Code(*start, Code)) { // 若输入编码错误 退出 delete start; return; } List.push_back(start); // 加入根节点 List_source.push_back(0); List_hash[0xffff & ((*start).code >> 16)].push_back(start); - while (1 == 1) { // 创建死循环 + while (now_move != List.size()) { // 找到所有元素后退出 Find_Next_Case(*List[now_move]); - if (flag == true) {break;} // 若找到则退出 + if (flag) {break;} // 若找到则退出 now_move++; - if (now_move == List.size()) {break;} // 已经找到所有元素则退出 } } @@ -119,7 +118,7 @@ void HRD_cal::Add_Case(Case_cal *dat) { // 将找到的布局加入队列中 // 通过freeze表合并来屏蔽不必要的移动 for (x = 0; x < 4; x++) { // 遍历freeze表 for (y = 0; y < 5; y++) { - if ((*dat).freeze[x][y] == true) { // 将输入表合并到原先的表上 + if ((*dat).freeze[x][y]) { // 将输入表合并到原先的表上 (*List_hash[hash_index][i]).freeze[x][y] = true; } } @@ -151,14 +150,14 @@ void HRD_cal::Find_Next_Case(Case_cal &dat_raw) { // 找到下一步移动的情 Case_cal dat = dat_raw; for (y = 0; y < 5; y++) { // 仅保留空格位置的freeze为true for (x = 0; x < 4; x++) { - if (dat.status[x][y] != 0xFE && dat.freeze[x][y] == true) { // 不为空格但freeze为true + if (dat.status[x][y] != 0xFE && dat.freeze[x][y]) { // 不为空格但freeze为true dat.freeze[x][y] = false; // 重置为false } } } for (y = 0; y < 5; y++) { // 遍历整个棋盘 for (x = 0; x < 4; x++) { - if (dat_raw.freeze[x][y] == true) {continue;} // 遇到freeze为true的跳过 + if (dat_raw.freeze[x][y]) {continue;} // 遇到freeze为true的跳过 num = dat.status[x][y]; // 统一修改(x, y)块 dat.status[x][y] = 0xFE; dat.freeze[x][y] = true; @@ -298,7 +297,7 @@ void HRD_cal::Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][ } void HRD_cal::Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]) { // 实现移动并将结果发送到Add_Case - if (addr[x][y] == true) { // 重复 + if (addr[x][y]) { // 重复 return; // 退出 } else { addr[x][y] = true; // 加入位置数据 @@ -337,7 +336,7 @@ void HRD_cal::Get_Code(Case_cal &dat) { // 获取编码并存储在dat.code 输 num = 0; for (y = 0; y < 5; y++) { // 遍历20个格 for (x = 0; x < 4; x++) { - if (temp[x][y] == true) {continue;} // 该格已被占用 + if (temp[x][y]) {continue;} // 该格已被占用 if (dat.status[x][y] == 0xFE) { // space num++; dat.code <<= 2; diff --git a/src/engine/HRD_group.cpp b/src/engine/HRD_group.cpp index f2e36a7..394bd84 100644 --- a/src/engine/HRD_group.cpp +++ b/src/engine/HRD_group.cpp @@ -21,7 +21,7 @@ bool HRD_group::Multi_Analyse(string seed_File_name, string name_farthest, strin seed.push_back(Change_int(str)); } for (unsigned int i = 0; i < seed.size(); i++) { // 判断编码正确性 - if (cal.Check_Code(seed[i]) == false) { + if (!cal.Check_Code(seed[i])) { cout << "input code error" << endl; // 发现错误编码 return false; // 退出 } @@ -43,7 +43,7 @@ bool HRD_group::Multi_Analyse(string seed_File_name, string name_farthest, strin void HRD_group::Batch_Analyse(unsigned long long seed, string name_farthest, string name_solution, bool is_output_solution) { // 根据群中一个布局分析整个群全部布局的参数 并将结果以csv格式输出到文件 HRD_cal cal; vector dat; - if (cal.Check_Code(seed) == false) {return;} // 编码错误 退出 + if (!cal.Check_Code(seed)) {return;} // 编码错误 退出 dat = cal.Calculate_All(seed); // 得到整个群 sort(dat.begin(), dat.end()); // 排列 Output_solution_case = is_output_solution; @@ -126,7 +126,7 @@ void HRD_group::Output_detail(Case_detail *dat) { } } output_solution << "," << (*dat).solution_num; - if (Output_solution_case == false) { + if (!Output_solution_case) { output_solution << endl; return; } @@ -143,40 +143,39 @@ void HRD_group::Output_detail(Case_detail *dat) { HRD_group::Case_detail* HRD_group::Analyse_Case(Case *start) { // 根据关系网计算布局的参数 unsigned int i, k; - vector Case_Stack; + vector case_list; Case_detail *dat = new Case_detail; // dat储存分析结果 Case_detail_init(*dat); // 初始化 (*dat).code = (*start).Code; (*start).Layer_num = 0; //令入口节点的层级为0 - Case_Stack.push_back(start); // 加入队列中 + case_list.push_back(start); // 加入队列中 i = 0; - while (1 == 1) { // 创建死循环 - if ((*Case_Stack[i]).addr_2x2 == 0xD) { // 2 * 2块在出口位置 - if ((*Case_Stack[i]).Flag == false) { // 未被标识 - (*dat).solution_case.push_back((*Case_Stack[i]).Code); // 判定为解 - (*dat).solution_step.push_back((*Case_Stack[i]).Layer_num); - (*Case_Stack[i]).Flag = true; // 进行标识 + while (i != case_list.size()) { // 找到所有元素后退出 + if ((*case_list[i]).addr_2x2 == 0xD) { // 2 * 2块在出口位置 + if (!(*case_list[i]).Flag) { // 未被标识 + (*dat).solution_case.push_back((*case_list[i]).Code); // 判定为解 + (*dat).solution_step.push_back((*case_list[i]).Layer_num); + (*case_list[i]).Flag = true; // 进行标识 } } - for (k = 0; k < (*Case_Stack[i]).Next.size(); k++) { // 检测目标布局的全部子布局 - if ((*(*Case_Stack[i]).Next[k]).Layer_num == -1) { // 若之前还未被搜索到 - (*(*Case_Stack[i]).Next[k]).Layer_num = (*Case_Stack[i]).Layer_num + 1; // 记录层级信息 - Case_Stack.push_back((*Case_Stack[i]).Next[k]); // 加入搜索队列 + for (k = 0; k < (*case_list[i]).Next.size(); k++) { // 检测目标布局的全部子布局 + if ((*(*case_list[i]).Next[k]).Layer_num == -1) { // 若之前还未被搜索到 + (*(*case_list[i]).Next[k]).Layer_num = (*case_list[i]).Layer_num + 1; // 记录层级信息 + case_list.push_back((*case_list[i]).Next[k]); // 加入搜索队列 } - if ((*Case_Stack[i]).Flag == true) { // 若已经标识 则感染下一层的子布局 - if ((*(*Case_Stack[i]).Next[k]).Layer_num == (*Case_Stack[i]).Layer_num + 1) { // 若为下一层 - (*(*Case_Stack[i]).Next[k]).Flag = true; // 标识 + if ((*case_list[i]).Flag) { // 若已经标识 则感染下一层的子布局 + if ((*(*case_list[i]).Next[k]).Layer_num == (*case_list[i]).Layer_num + 1) { // 若为下一层 + (*(*case_list[i]).Next[k]).Flag = true; // 标识 } } } i++; // 搜索下一个布局 - if (i == Case_Stack.size()) {break;} // 搜索完毕 退出 } // 计算最远布局 - (*dat).farthest_step = (*Case_Stack[Case_Stack.size() - 1]).Layer_num; // 得到最远步数 - for (int i = Case_Stack.size() - 1; i >= 0; i--) { // 逆向搜索 - if ((*Case_Stack[i]).Layer_num == (*dat).farthest_step) { // 如果是最远布局 - (*dat).farthest_case.push_back((*Case_Stack[i]).Code); // 加入记录 + (*dat).farthest_step = (*case_list[case_list.size() - 1]).Layer_num; // 得到最远步数 + for (int i = case_list.size() - 1; i >= 0; i--) { // 逆向搜索 + if ((*case_list[i]).Layer_num == (*dat).farthest_step) { // 如果是最远布局 + (*dat).farthest_case.push_back((*case_list[i]).Code); // 加入记录 } else { break; // 退出搜索 } @@ -239,7 +238,7 @@ vector HRD_group::Find_Next_Case(unsigned long long Code) { Next_Case_dat.clear(); // 清空序列 for (y = 0; y < 5; y++) { // 遍历整个棋盘 for (x = 0; x < 4; x++) { - if (exclude[x][y] == true) {continue;} + if (exclude[x][y]) {continue;} for (i = 0; i < 4; i++) { // 初始化 for (j = 0; j < 5; j++) { addr[i][j] = false; @@ -371,7 +370,7 @@ void HRD_group::Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4 } void HRD_group::Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]) { // 实现移动并将结果发送到Add_Case - if (addr[x][y] == true) { // 重复 + if (addr[x][y]) { // 重复 return; // 退出 } else { addr[x][y] = true; // 加入位置数据 @@ -409,7 +408,7 @@ void HRD_group::Get_Code(Case_cal &dat) { // 获取编码并存储在dat.code num = 0; for (y = 0; y < 5; y++) { // 遍历20个格 for (x = 0; x < 4; x++) { - if (temp[x][y] == true) {continue;} // 该格已被占用 + if (temp[x][y]) {continue;} // 该格已被占用 if (dat.status[x][y] == 0xFE) { // space num++; dat.code <<= 2; diff --git a/src/engine/HRD_statistic.cpp b/src/engine/HRD_statistic.cpp index a66959f..61a5f1f 100644 --- a/src/engine/HRD_statistic.cpp +++ b/src/engine/HRD_statistic.cpp @@ -217,7 +217,7 @@ void HRD_statistic::Find_All_Case() { // 找到所有编码 if (n % 4 == 3) {continue;} // 排除2 * 2块不可能在的位置 for (i = 0; i <= 0xFFFFFFFF; i++) { // 遍历编码低32位 Code = (n << 32) | i; // 生成Code - if (cal.Check_Code(Code) == true) { // 检查编码是否正确 + if (cal.Check_Code(Code)) { // 检查编码是否正确 Case *temp = new Case; (*temp).code = Code; (*temp).id = num; diff --git a/src/engine/main.cpp b/src/engine/main.cpp index c90aa6f..ef5aa45 100644 --- a/src/engine/main.cpp +++ b/src/engine/main.cpp @@ -319,7 +319,7 @@ void find_all_code(string File_name) { } void show_help() { - cout << "(version: v0.1)" << endl; + cout << "(version: v1.0)" << endl; cout << "Usage of HRD_engine:" << endl; cout << endl; cout << " --show [square_width]" << endl;