|
|
@ -1,4 +1,5 @@ |
|
|
|
#include <iostream> |
|
|
|
#include <sstream> |
|
|
|
#include <string> |
|
|
|
#include <fstream> |
|
|
|
#include <algorithm> |
|
|
@ -21,11 +22,46 @@ bool code_check(string str) { |
|
|
|
for (unsigned int i = 0; i < str.length(); i++) { |
|
|
|
code_str[i] = str[i]; |
|
|
|
} |
|
|
|
code_str[10] = '\0'; |
|
|
|
code_str[9] = '\0'; |
|
|
|
checked_code = cal.Change_int(code_str); |
|
|
|
return cal.Check_Code(checked_code); |
|
|
|
} |
|
|
|
|
|
|
|
void show_case(string str) { |
|
|
|
unsigned long long code; |
|
|
|
if (code_check(str) == false) { |
|
|
|
cout << "code error" << endl; |
|
|
|
cout << endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
code = checked_code; |
|
|
|
HRD_analy analy; |
|
|
|
char output_char[3] = "&%"; |
|
|
|
cout << endl; |
|
|
|
cout << "Code: " << analy.Change_str(code) << endl; |
|
|
|
analy.Output_Graph(code, 3, 1, output_char); |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void show_case(string str, string width) { |
|
|
|
unsigned long long code; |
|
|
|
if (code_check(str) == false) { |
|
|
|
cout << "code error" << endl; |
|
|
|
cout << endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
code = checked_code; |
|
|
|
HRD_analy analy; |
|
|
|
int square_width; |
|
|
|
char output_char[3] = "&%"; |
|
|
|
istringstream is(width); // 借用字符串流对象将string转为int
|
|
|
|
is >> square_width; |
|
|
|
cout << endl; |
|
|
|
cout << "Code: " << analy.Change_str(code) << endl; |
|
|
|
analy.Output_Graph(code, square_width, 1, output_char); |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void cal_case(string str) { |
|
|
|
unsigned long long code; |
|
|
|
vector <unsigned long long> dat; |
|
|
@ -68,11 +104,15 @@ void cal_case(string str, string File_name) { |
|
|
|
} |
|
|
|
File_Output.open(File_name); |
|
|
|
cout << "Data save at " << File_name << endl; |
|
|
|
File_Output << dat.size() - 1 << endl; |
|
|
|
for (unsigned int i = 0; i < dat.size(); i++) { |
|
|
|
File_Output << cal.Change_str(dat[i]); |
|
|
|
if (i + 1 != dat.size()) { |
|
|
|
File_Output << endl; |
|
|
|
if (dat.size() == 0) { |
|
|
|
File_Output << "-1"; |
|
|
|
} else { |
|
|
|
File_Output << dat.size() - 1 << endl; |
|
|
|
for (unsigned int i = 0; i < dat.size(); i++) { |
|
|
|
File_Output << cal.Change_str(dat[i]); |
|
|
|
if (i + 1 != dat.size()) { |
|
|
|
File_Output << endl; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cout << endl; |
|
|
@ -135,17 +175,37 @@ void cal_target(string str_1, string str_2, string File_name) { |
|
|
|
} |
|
|
|
File_Output.open(File_name); |
|
|
|
cout << "Data save at " << File_name << endl; |
|
|
|
File_Output << dat.size() - 1 << endl; |
|
|
|
for (unsigned int i = 0; i < dat.size(); i++) { |
|
|
|
File_Output << cal.Change_str(dat[i]); |
|
|
|
if (i + 1 != dat.size()) { |
|
|
|
File_Output << endl; |
|
|
|
if (dat.size() == 0) { |
|
|
|
File_Output << "-1"; |
|
|
|
} else { |
|
|
|
File_Output << dat.size() - 1 << endl; |
|
|
|
for (unsigned int i = 0; i < dat.size(); i++) { |
|
|
|
File_Output << cal.Change_str(dat[i]); |
|
|
|
if (i + 1 != dat.size()) { |
|
|
|
File_Output << endl; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cout << endl; |
|
|
|
File_Output.close(); |
|
|
|
} |
|
|
|
|
|
|
|
void cal_group(string str) { |
|
|
|
unsigned long long code; |
|
|
|
vector <unsigned long long> dat; |
|
|
|
if (code_check(str) == false) { |
|
|
|
cout << "code error" << endl; |
|
|
|
cout << endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
HRD_cal cal; |
|
|
|
code = checked_code; |
|
|
|
cout << "Start code: " << cal.Change_str(code) << endl; |
|
|
|
dat = cal.Calculate_All(code); |
|
|
|
cout << "Group size: " << dat.size() << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void cal_group(string str, string File_name) { |
|
|
|
unsigned long long code; |
|
|
|
vector <unsigned long long> dat; |
|
|
@ -172,6 +232,23 @@ void cal_group(string str, string File_name) { |
|
|
|
File_Output.close(); |
|
|
|
} |
|
|
|
|
|
|
|
void analy_case(string str, bool quiet) { |
|
|
|
unsigned long long code; |
|
|
|
vector <unsigned long long> dat; |
|
|
|
if (code_check(str) == false) { |
|
|
|
cout << "code error" << endl; |
|
|
|
cout << endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
HRD_analy analy; |
|
|
|
code = checked_code; |
|
|
|
cout << "Start code: " << analy.Change_str(code) << endl; |
|
|
|
analy.quiet = quiet; |
|
|
|
analy.Analyse_Case(code); |
|
|
|
cout << endl; |
|
|
|
analy.Free_Data(); |
|
|
|
} |
|
|
|
|
|
|
|
void analy_case(string str, string File_name, bool quiet) { |
|
|
|
unsigned long long code; |
|
|
|
vector <unsigned long long> dat; |
|
|
@ -193,6 +270,7 @@ void analy_case(string str, string File_name, bool quiet) { |
|
|
|
cout << "done" << endl; |
|
|
|
} |
|
|
|
cout << endl; |
|
|
|
analy.Free_Data(); |
|
|
|
} |
|
|
|
|
|
|
|
void analy_group(string str, string File_name_1, string File_name_2, bool is_all) { |
|
|
@ -211,13 +289,23 @@ void analy_group(string str, string File_name_1, string File_name_2, bool is_all |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void find_all(string File_name) { |
|
|
|
void analy_multi_group(string str, string File_name_1, string File_name_2, bool is_all) { |
|
|
|
HRD_group group; |
|
|
|
if (group.Multi_Analyse(str, File_name_1, File_name_2, is_all) == false) { |
|
|
|
cout << endl; |
|
|
|
return; |
|
|
|
} |
|
|
|
cout << "Data save at " << File_name_1 << " and " << File_name_2 << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void find_all() { |
|
|
|
HRD_statistic statistic; |
|
|
|
cout << "Warning: It will consume nearly 2GB of memory, please make sure there is enough memory!" << endl; |
|
|
|
cout << "Press ENTER to start..."; |
|
|
|
cin.get(); |
|
|
|
statistic.Find_All_Case(File_name); |
|
|
|
cout << "Data save at " << File_name << endl; |
|
|
|
statistic.All_Statistic(); |
|
|
|
cout << "Data save at All_Case.txt, main.csv, *-*-*.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
@ -226,7 +314,7 @@ void find_all_code(string File_name) { |
|
|
|
cout << "Warning: It will consume nearly 2GB of memory, please make sure there is enough memory!" << endl; |
|
|
|
cout << "Press ENTER to start..."; |
|
|
|
cin.get(); |
|
|
|
statistic.Make_main_table(File_name); |
|
|
|
statistic.Find_All_Case(File_name); |
|
|
|
cout << "Data save at " << File_name << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
@ -235,75 +323,102 @@ void show_help() { |
|
|
|
cout << "(version: v0.0)" << endl; |
|
|
|
cout << "Usage of HRD_engine:" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --show <code> [square_width]" << endl; |
|
|
|
cout << " Purpose: Visualize the <code>" << endl; |
|
|
|
cout << " exp: ./engine --show 1A9BF0C00" << endl; |
|
|
|
cout << " ./engine --show 1A9BF0C00 4" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --cal <code> [file_name]" << endl; |
|
|
|
cout << " [file_name]: for output the result" << endl; |
|
|
|
cout << " Purpose: find the min step solution from <code>" << endl; |
|
|
|
cout << " Purpose: Find the minimum step solution of <code>" << endl; |
|
|
|
cout << " exp: ./engine --cal 1A9BF0C00" << endl; |
|
|
|
cout << " ./engine --cal 1A9BF0C00 demo.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --cal-target <code> <target> [file_name]" << endl; |
|
|
|
cout << " [file_name]: for output the result" << endl; |
|
|
|
cout << " Purpose: find the min step path from <code> to <target>" << endl; |
|
|
|
cout << " Purpose: Find the shortest path from <code> to <target>" << endl; |
|
|
|
cout << " exp: ./engine --cal-target 4FEA13400 43EA73400" << endl; |
|
|
|
cout << " ./engine --cal-target 4FEA13400 43EA73400 demo.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --group <code> <file_name>" << endl; |
|
|
|
cout << " <file_name>: for output the result" << endl; |
|
|
|
cout << " Purpose: find all cases in the group where <code> loacted" << endl; |
|
|
|
cout << " exp: ./engine --group 4FEA13400 demo.txt" << endl; |
|
|
|
cout << " --group <code> [file_name]" << endl; |
|
|
|
cout << " Purpose: Find all elements of the group where <code> located" << endl; |
|
|
|
cout << " exp: ./engine --group 4FEA13400" << endl; |
|
|
|
cout << " ./engine --group 4FEA13400 demo.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --analy <code> <file_name>" << endl; |
|
|
|
cout << " <file_name>: for output the result" << endl; |
|
|
|
cout << " Purpose: analyse the case with <code> " << endl; |
|
|
|
cout << " exp: ./engine --analy 1A9BF0C00 demo.txt" << endl; |
|
|
|
cout << " --analy <code> [file_name]" << endl; |
|
|
|
cout << " Purpose: Detailed analysis of the <code> " << endl; |
|
|
|
cout << " exp: ./engine --analy 1A9BF0C00" << endl; |
|
|
|
cout << " ./engine --analy 1A9BF0C00 demo.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --analy-quiet <code> <file_name>" << endl; |
|
|
|
cout << " Purpose: the same function with analy but don't show the process" << endl; |
|
|
|
cout << " Purpose: The same function as --analy, but doesn't show the specific process" << endl; |
|
|
|
cout << " exp: ./engine --analy-quiet 1A9BF0C00 demo.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --analy-group <code> <file_name_1> <file_name_2>" << endl; |
|
|
|
cout << " <file_name_1>: for output the result of \"farthest\"" << endl; |
|
|
|
cout << " <file_name_2>: for output the result of \"solution\"" << endl; |
|
|
|
cout << " Purpose: analyse all cases in the group where <code> loacted" << endl; |
|
|
|
cout << " exp: ./engine --group 1A9BF0C00 farthest.csv solution.csv" << endl; |
|
|
|
cout << " --analy-group <code> <file_name_farthest> <file_name_solution>" << endl; |
|
|
|
cout << " <file_name_farthest>: As the output file of \"farthest\"" << endl; |
|
|
|
cout << " <file_name_solution>: As the output file of \"solution\"" << endl; |
|
|
|
cout << " Purpose: Analyze the whole group where <code> located" << endl; |
|
|
|
cout << " exp: ./engine --analy-group 1A9BF0C00 farthest.csv solution.csv" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --analy-group-integral <code> <file_name_farthest> <file_name_farthest>" << endl; |
|
|
|
cout << " Purpose: The same function as --analy-group, but all solution case will be output" << endl; |
|
|
|
cout << " exp: ./engine --analy-group-integral 1A9BF0C00 farthest.csv solution.csv" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --analy-group-all <code> <file_name_1> <file_name_2>" << endl; |
|
|
|
cout << " Purpose: the same function with analy-group but more output all solution cases" << endl; |
|
|
|
cout << " exp: ./engine --group-all 1A9BF0C00 farthest.csv solution.csv" << endl; |
|
|
|
cout << " --analy-multi-group <input_file_name> <file_name_farthest> <file_name_farthest>" << endl; |
|
|
|
cout << " <input_file_name>: As the input file of seeds" << endl; |
|
|
|
cout << " <file_name_farthest>: As the output file of \"farthest\"" << endl; |
|
|
|
cout << " <file_name_farthest>: As the output file of \"solution\"" << endl; |
|
|
|
cout << " Purpose: Analyze the whole group where each seed located" << endl; |
|
|
|
cout << " exp: ./engine --analy-multi-group 5-4-0.txt farthest.csv solution.csv" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --all <file_name>" << endl; |
|
|
|
cout << " Purpose: find all cases from klotski game with detail" << endl; |
|
|
|
cout << " exp: ./engine --all main.csv" << endl; |
|
|
|
cout << " --analy-multi-group-integral <input_file_name> <file_name_farthest> <file_name_farthest>" << endl; |
|
|
|
cout << " Purpose: The same function as --analy-multi-group, but all solution case will be output" << endl; |
|
|
|
cout << " exp: ./engine --analy-multi-group-integral 5-4-0.txt farthest.csv solution.csv" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --all" << endl; |
|
|
|
cout << " Purpose: Find all the cases of klotski with detail" << endl; |
|
|
|
cout << " exp: ./engine --all" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --all-code <file_name>" << endl; |
|
|
|
cout << " Purpose: find all cases from klotski game only with code" << endl; |
|
|
|
cout << " Purpose: Find all the code of klotski" << endl; |
|
|
|
cout << " exp: ./engine --all-code All_Case.txt" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << " --help" << endl; |
|
|
|
cout << " Purpose: show the usage" << endl; |
|
|
|
cout << " Purpose: Display instructions for use" << endl; |
|
|
|
cout << " exp: ./engine --help" << endl; |
|
|
|
cout << endl; |
|
|
|
cout << "More details: https://github.com/dnomd343/HRD_Database" << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
void parameter_err() { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char* argv[]) { |
|
|
|
cout << "Klotski engine by Dnomd343" << endl; |
|
|
|
if (argc <= 1) { |
|
|
|
cout << "no parameter" << endl; |
|
|
|
cout << "You can try to use \"--help\" for more information" << endl; |
|
|
|
cout << "You can try \"--help\" for more information" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
string parameter; |
|
|
|
parameter = argv[1]; |
|
|
|
if (parameter == "--cal") { |
|
|
|
if (parameter == "--show") { |
|
|
|
if (argc == 3) { |
|
|
|
show_case(argv[2]); |
|
|
|
} else if (argc == 4) { |
|
|
|
show_case(argv[2], argv[3]); |
|
|
|
} else { |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--cal") { |
|
|
|
if (argc == 3) { |
|
|
|
cal_case(argv[2]); |
|
|
|
} else if (argc == 4) { |
|
|
|
cal_case(argv[2], argv[3]); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--cal-target") { |
|
|
|
if (argc == 4) { |
|
|
@ -311,71 +426,71 @@ int main(int argc, char* argv[]) { |
|
|
|
} else if (argc == 5) { |
|
|
|
cal_target(argv[2], argv[3], argv[4]); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--group") { |
|
|
|
if (argc == 4) { |
|
|
|
if (argc == 3) { |
|
|
|
cal_group(argv[2]); |
|
|
|
} else if (argc == 4) { |
|
|
|
cal_group(argv[2], argv[3]); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy") { |
|
|
|
if (argc == 4) { |
|
|
|
if (argc == 3) { |
|
|
|
analy_case(argv[2], false); |
|
|
|
} else if (argc == 4) { |
|
|
|
analy_case(argv[2], argv[3], false); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy-quiet") { |
|
|
|
if (argc == 4) { |
|
|
|
analy_case(argv[2], argv[3], true); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy-group") { |
|
|
|
if (argc == 5) { |
|
|
|
analy_group(argv[2], argv[3], argv[4], false); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy-group-all") { |
|
|
|
} else if (parameter == "--analy-group-integral") { |
|
|
|
if (argc == 5) { |
|
|
|
analy_group(argv[2], argv[3], argv[4], true); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy-multi-group") { |
|
|
|
if (argc == 5) { |
|
|
|
analy_multi_group(argv[2], argv[3], argv[4], false); |
|
|
|
} else { |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--analy-multi-group-integral") { |
|
|
|
if (argc == 5) { |
|
|
|
analy_multi_group(argv[2], argv[3], argv[4], true); |
|
|
|
} else { |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--all") { |
|
|
|
if (argc == 3) { |
|
|
|
find_all(argv[2]); |
|
|
|
if (argc == 2) { |
|
|
|
find_all(); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--all-code") { |
|
|
|
if (argc == 3) { |
|
|
|
find_all_code(argv[2]); |
|
|
|
} else { |
|
|
|
cout << "parameter error" << endl; |
|
|
|
cout << endl; |
|
|
|
return 0; |
|
|
|
parameter_err(); |
|
|
|
} |
|
|
|
} else if (parameter == "--help") { |
|
|
|
show_help(); |
|
|
|
} else { |
|
|
|
cout << "unknow parameter" << endl; |
|
|
|
cout << "You can try to use \"--help\" for more information" << endl; |
|
|
|
cout << "You can try \"--help\" for more information" << endl; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
return 0; |
|
|
|