From 058e95ad280f01ecf33dd1a1b89453087124ba80 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 28 Jul 2020 17:27:38 +0800 Subject: [PATCH] update engine --- src/engine/HRD_analy.cpp | 4 +- src/engine/HRD_analy.h | 98 +++++++++++++++++++------------------- src/engine/HRD_cal.h | 64 ++++++++++++------------- src/engine/HRD_group.h | 82 +++++++++++++++---------------- src/engine/HRD_statistic.h | 54 ++++++++++----------- 5 files changed, 151 insertions(+), 151 deletions(-) diff --git a/src/engine/HRD_analy.cpp b/src/engine/HRD_analy.cpp index a025c4b..ade3eee 100644 --- a/src/engine/HRD_analy.cpp +++ b/src/engine/HRD_analy.cpp @@ -319,11 +319,11 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的 for (j = 0; j < Layer[i].size(); j++) { if ((Layer[i][j]->code >> 32) == 0xD) { // 2 * 2块在出口位置 min_solution_step = i; // 找到最少步数 - j = Layer[i].size(); // 跳出两层循环 - i = Layer.size(); + goto get_min_solution_step; // 跳出两层循环 } } } +get_min_solution_step:; if (min_solution_step == -1) {return;} // 无解则退出 for (i = 0; i < Layer[min_solution_step].size(); i++) { // 遍历最少步所在层 if ((Layer[min_solution_step][i]->code >> 32) == 0xD) { // 判断是否为解 diff --git a/src/engine/HRD_analy.h b/src/engine/HRD_analy.h index 948a5ec..1f6f415 100644 --- a/src/engine/HRD_analy.h +++ b/src/engine/HRD_analy.h @@ -6,57 +6,57 @@ using namespace std; class HRD_analy { - public: - ~HRD_analy(); - struct Case_cal { - bool freeze[4][5]; // true -> no move ; false -> can move - unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space - unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 - unsigned long long code; - unsigned int layer_num; - unsigned int layer_index; - vector *source_case; - vector *next_case; - }; - vector < vector > Layer; // 储存全部层数据的节点 - Case_cal Parse_dat; - bool quiet = false; // true -> 静默模式 false -> 输出运算情况 - // 布局的基本参数 - int stop_point_num; // 端点的个数 - int min_solution_step; // 最少的步数 - int min_solution_num; // 最少步解的个数 - vector min_solution_case; // 所有最少步解 - vector solution_step; // 所有解对应的步数 - int solution_num; // 解的个数 - vector solution_case; // 所有解 - int farthest_step; // 最远布局的步数 - int farthest_num; // 最远布局的个数 - vector farthest_case; // 所有最远的布局 +public: + ~HRD_analy(); + struct Case_cal { + bool freeze[4][5]; // true -> no move ; false -> can move + unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space + unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 + unsigned long long code; + unsigned int layer_num; + unsigned int layer_index; + vector *source_case; + vector *next_case; + }; + vector < vector > Layer; // 储存全部层数据的节点 + Case_cal Parse_dat; + bool quiet = false; // true -> 静默模式 false -> 输出运算情况 + // 布局的基本参数 + int stop_point_num; // 端点的个数 + int min_solution_step; // 最少的步数 + int min_solution_num; // 最少步解的个数 + vector min_solution_case; // 所有最少步解 + vector solution_step; // 所有解对应的步数 + int solution_num; // 解的个数 + vector solution_case; // 所有解 + int farthest_step; // 最远布局的步数 + int farthest_num; // 最远布局的个数 + vector farthest_case; // 所有最远的布局 - unsigned long long Change_int(char str[10]); - string Change_str(unsigned long long dat); - bool Check_Code(unsigned long long code); - bool Parse_Code(unsigned long long code); - bool Is_Mirror(unsigned long long code); - void Analyse_Case(unsigned long long code); - void Output_Detail(string File_name); - void Free_Data(); - void Output_All_Path(string File_name); - bool Output_Path(vector target, string File_name); - void Output_Graph(unsigned long long code, unsigned int square_width, unsigned int square_gap, char str[2]); + unsigned long long Change_int(char str[10]); + string Change_str(unsigned long long dat); + bool Check_Code(unsigned long long code); + bool Parse_Code(unsigned long long code); + bool Is_Mirror(unsigned long long code); + void Analyse_Case(unsigned long long code); + void Output_Detail(string File_name); + void Free_Data(); + void Output_All_Path(string File_name); + bool Output_Path(vector target, string File_name); + void Output_Graph(unsigned long long code, unsigned int square_width, unsigned int square_gap, char str[2]); - private: - Case_cal *now_move_case; - vector *Layer_hash = new vector [0x10000]; // 哈希表 - unsigned int now_move_num, now_move_index; // 当前扫描节点的层编号 / 当前扫描节点的层中编号 - bool Parse_Code(Case_cal &dat, unsigned long long code); - void Get_Code(Case_cal &dat); - void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - void Find_Next_Case(Case_cal &dat_raw); - void Add_Case(Case_cal *dat); - void Calculate(unsigned long long code); - bool Search_Case(unsigned long long code, Case_cal* &dat); +private: + Case_cal *now_move_case; + vector *Layer_hash = new vector [0x10000]; // 哈希表 + unsigned int now_move_num, now_move_index; // 当前扫描节点的层编号 / 当前扫描节点的层中编号 + bool Parse_Code(Case_cal &dat, unsigned long long code); + void Get_Code(Case_cal &dat); + void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + void Find_Next_Case(Case_cal &dat_raw); + void Add_Case(Case_cal *dat); + void Calculate(unsigned long long code); + bool Search_Case(unsigned long long code, Case_cal* &dat); }; #endif diff --git a/src/engine/HRD_cal.h b/src/engine/HRD_cal.h index 069e4e3..fd5e3ab 100644 --- a/src/engine/HRD_cal.h +++ b/src/engine/HRD_cal.h @@ -6,40 +6,40 @@ using namespace std; class HRD_cal { - public: - ~HRD_cal(); - unsigned long long Change_int(char str[10]); - string Change_str(unsigned long long dat); - bool Check_Code(unsigned long long code); - vector Calculate(unsigned long long code); - vector Calculate_All(unsigned long long code); - vector Calculate(unsigned long long code, unsigned long long target); +public: + ~HRD_cal(); + unsigned long long Change_int(char str[10]); + string Change_str(unsigned long long dat); + bool Check_Code(unsigned long long code); + vector Calculate(unsigned long long code); + vector Calculate_All(unsigned long long code); + vector Calculate(unsigned long long code, unsigned long long target); - private: - struct Case_cal { - bool freeze[4][5]; // true -> no move ; false -> can move - unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space - unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 - unsigned long long code; - }; - vector List; // 主队列 储存每个节点的信息 - vector *List_hash = new vector [0x10000]; // 哈希表 - vector List_source; // 储存上一步编号 用于溯源 - 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; // 判断是否已找到目标 +private: + struct Case_cal { + bool freeze[4][5]; // true -> no move ; false -> can move + unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space + unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 + unsigned long long code; + }; + vector List; // 主队列 储存每个节点的信息 + vector *List_hash = new vector [0x10000]; // 哈希表 + vector List_source; // 储存上一步编号 用于溯源 + 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 Parse_Code(Case_cal &dat, unsigned long long code); - void Get_Code(Case_cal &dat); - void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - void Find_Next_Case(Case_cal &dat_raw); - void Add_Case(Case_cal *dat); - void cal(unsigned long long code); - void init_data(); - vector Get_Path(unsigned int result_num); + bool Parse_Code(Case_cal &dat, unsigned long long code); + void Get_Code(Case_cal &dat); + void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + void Find_Next_Case(Case_cal &dat_raw); + void Add_Case(Case_cal *dat); + void cal(unsigned long long code); + void init_data(); + vector Get_Path(unsigned int result_num); }; #endif diff --git a/src/engine/HRD_group.h b/src/engine/HRD_group.h index b42299c..71e20ff 100644 --- a/src/engine/HRD_group.h +++ b/src/engine/HRD_group.h @@ -6,51 +6,51 @@ using namespace std; class HRD_group { - public: - unsigned long long Change_int(char str[10]); - string Change_str(unsigned long long dat); - void Batch_Analyse(unsigned long long seed, string name_farthest, string name_solution, bool is_output_solution); - bool Multi_Analyse(string seed_File_name, string name_farthest, string name_solution, bool is_output_solution); +public: + unsigned long long Change_int(char str[10]); + string Change_str(unsigned long long dat); + void Batch_Analyse(unsigned long long seed, string name_farthest, string name_solution, bool is_output_solution); + bool Multi_Analyse(string seed_File_name, string name_farthest, string name_solution, bool is_output_solution); - private: - struct Case_cal { - unsigned long long code; - unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space - unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 - }; - struct Case { - unsigned long long code; - int layer_num; - bool flag; - unsigned int addr_2x2; - vector next; - }; - struct Case_detail { - unsigned long long code; - int farthest_step; - int farthest_num; - vector farthest_case; +private: + struct Case_cal { + unsigned long long code; + unsigned char status[4][5]; // 0xFF -> undefined ; 0xFE -> space + unsigned char type[15]; // 0 -> 2 * 2 ; 1 -> 2 * 1 ; 2 -> 1 * 2 ; 3 -> 1 * 1 + }; + struct Case { + unsigned long long code; + int layer_num; + bool flag; + unsigned int addr_2x2; + vector next; + }; + struct Case_detail { + unsigned long long code; + int farthest_step; + int farthest_num; + vector farthest_case; - int min_solution_step; - int min_solution_num; - vector min_solution_case; + int min_solution_step; + int min_solution_num; + vector min_solution_case; - int solution_num; - vector solution_case; - vector solution_step; - }; - vector Next_Case_dat; // 储存Find_Next_Case找到的结果 - bool Output_solution_case; // 是否输出全部solution_case + int solution_num; + vector solution_case; + vector solution_step; + }; + vector Next_Case_dat; // 储存Find_Next_Case找到的结果 + bool Output_solution_case; // 是否输出全部solution_case - bool Parse_Code(Case_cal &dat, unsigned long long code); - void Get_Code(Case_cal &dat); - void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); - vector Find_Next_Case(unsigned long long code); - void Case_detail_init(Case_detail &dat); - Case_detail* Analyse_Case(Case *start); - void Analyse_Group(vector dat); - void Output_detail(Case_detail *dat); + bool Parse_Code(Case_cal &dat, unsigned long long code); + void Get_Code(Case_cal &dat); + void Find_Sub_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + void Build_Case(Case_cal &dat, int &num, int x, int y, bool addr[4][5]); + vector Find_Next_Case(unsigned long long code); + void Case_detail_init(Case_detail &dat); + Case_detail* Analyse_Case(Case *start); + void Analyse_Group(vector dat); + void Output_detail(Case_detail *dat); }; #endif diff --git a/src/engine/HRD_statistic.h b/src/engine/HRD_statistic.h index 523da07..59bbe30 100644 --- a/src/engine/HRD_statistic.h +++ b/src/engine/HRD_statistic.h @@ -6,35 +6,35 @@ using namespace std; class HRD_statistic { - public: - void Find_All_Case(string File_name); - void All_Statistic(); +public: + void Find_All_Case(string File_name); + void All_Statistic(); - private: - struct Case { - unsigned int id; - bool is_mirror; - unsigned long long code; - unsigned char jiang_num; - unsigned char bing_num; - unsigned char style_num; - unsigned int group_num; - unsigned int group_index; - }; - struct Case_group { - unsigned int id; - unsigned long long code; - unsigned int group_num; - unsigned int group_index; - }; - vector All_Case; // 记录所有布局的信息 +private: + struct Case { + unsigned int id; + bool is_mirror; + unsigned long long code; + unsigned char jiang_num; + unsigned char bing_num; + unsigned char style_num; + unsigned int group_num; + unsigned int group_index; + }; + struct Case_group { + unsigned int id; + unsigned long long code; + unsigned int group_num; + unsigned int group_index; + }; + vector All_Case; // 记录所有布局的信息 - void Get_seed(); - void Find_All_Case(); - void Sort_All_Case(); - vector Split_Group(vector dat); - void Output_All_Case(string File_name); - void Output_main_table(string File_name); + void Get_seed(); + void Find_All_Case(); + void Sort_All_Case(); + vector Split_Group(vector dat); + void Output_All_Case(string File_name); + void Output_main_table(string File_name); }; #endif