Browse Source

update engine

master
Dnomd343 4 years ago
parent
commit
2e41222987
  1. 24
      src/engine/HRD_analy.cpp
  2. 2
      src/engine/HRD_cal.cpp
  3. 3
      src/engine/HRD_group.cpp
  4. 1
      src/engine/HRD_statistic.cpp
  5. 275
      src/engine/main.cpp

24
src/engine/HRD_analy.cpp

@ -185,12 +185,12 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
unsigned int i, j, k;
farthest_step = -1; // 初始化farthest
farthest_num = 0;
farthest_case.clear();
farthest_case.clear();
min_solution_step = -1; // 初始化min_solution
min_solution_num = 0;
min_solution_case.clear();
solution_num = 0; // 初始化solution
solution_case.clear();
solution_num = 0; // 初始化solution
solution_case.clear();
solution_step.clear();
if (Check_Code(code) == false) {return;} // 若编码错误则退出
Calculate(code); // 计算分层数据
@ -204,7 +204,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
farthest_case.push_back((*Layer[farthest_step][i]).code);
}
farthest_num = farthest_case.size();
sort(farthest_case.begin(), farthest_case.end()); //得到的结果进行排序
sort(farthest_case.begin(), farthest_case.end()); //得到的结果进行排序
// 获取最少步解
for (i = 0; i < Layer.size(); i++) {
for (j = 0; j < Layer[i].size(); j++) {
@ -223,7 +223,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
}
}
min_solution_num = min_solution_case.size();
sort(min_solution_case.begin(), min_solution_case.end()); // 得到的结果进行排序
sort(min_solution_case.begin(), min_solution_case.end()); // 得到的结果进行排序
// 获取全部解
vector <Case_cal *> case_list;
solution_case = min_solution_case; // 同步最少步解到所有解序列中
@ -239,20 +239,20 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
}
}
}
temp.clear();
temp.clear();
for (j = 0; j < Layer[i + 1].size(); j++) { // 遍历下一层内元素
if (solution_flag[i + 1][j] == false) { // 得到未被标识的元素
if (((*Layer[i + 1][j]).code >> 32) == 0xD) { // 若为解的布局
temp.push_back((*Layer[i + 1][j]).code); // 先加入到temp中方便排序
temp.push_back((*Layer[i + 1][j]).code); // 先加入到temp中方便排序
solution_step.push_back(i + 1);
solution_flag[i + 1][j] = true; // 标识
}
}
}
sort(temp.begin(), temp.end()); // 将得到的结果进行排序
for (k = 0; k < temp.size(); k++) { // 将temp内容加入solution_case中
solution_case.push_back(temp[k]);
}
sort(temp.begin(), temp.end()); // 将得到的结果进行排序
for (k = 0; k < temp.size(); k++) { // 将temp内容加入solution_case中
solution_case.push_back(temp[k]);
}
}
solution_num = solution_case.size();
if (quiet == true) {return;} // 若quiet为true则不输出
@ -692,6 +692,6 @@ unsigned long long HRD_analy::Change_int (char *str) { // 将文本编码转化
} else if (str[i] >= 97 && str[i] <= 102) { // a ~ f
dat |= str[i] - 87;
}
}
}
return dat;
}

2
src/engine/HRD_cal.cpp

@ -467,6 +467,6 @@ unsigned long long HRD_cal::Change_int (char *str) { // 将文本编码转化为
} else if (str[i] >= 97 && str[i] <= 102) { // a ~ f
dat |= str[i] - 87;
}
}
}
return dat;
}

3
src/engine/HRD_group.cpp

@ -469,7 +469,6 @@ bool HRD_group::Parse_Code(Case_cal &dat, unsigned long long Code) { // 解析
x = Code % 4;
y = Code / 4;
dat.status[x][y] = dat.status[x + 1][y] = dat.status[x][y + 1] = dat.status[x + 1][y + 1] = 0;
num = x = y = 0;
for (i = 0; i < 16; i++) {
while (dat.status[x][y] != 0xFF) { // 找到下一个未填入的位置
@ -538,6 +537,6 @@ unsigned long long HRD_group::Change_int(char *str) { // 将文本编码转化
} else if (str[i] >= 97 && str[i] <= 102) { // a ~ f
dat |= str[i] - 87;
}
}
}
return dat;
}

1
src/engine/HRD_statistic.cpp

@ -232,4 +232,3 @@ void HRD_statistic::Find_All_Case() { // 找到所有编码
}
cout << "Total: " << num << endl;
}

275
src/engine/main.cpp

@ -10,18 +10,17 @@
using namespace std;
ofstream File_Output;
unsigned long long checked_code;
bool code_check(string str) {
HRD_cal cal;
char code_str[10];
if (str.length() != 9) {
return false;
}
for (unsigned int i = 0; i < str.length(); i++) {
HRD_cal cal;
char code_str[10];
if (str.length() != 9) {
return false;
}
for (unsigned int i = 0; i < str.length(); i++) {
code_str[i] = str[i];
}
}
code_str[9] = '\0';
checked_code = cal.Change_int(code_str);
return cal.Check_Code(checked_code);
@ -29,12 +28,12 @@ bool code_check(string str) {
void show_case(string str) {
unsigned long long code;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_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;
@ -45,16 +44,16 @@ void show_case(string str) {
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;
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
istringstream is(width); // 借用字符串流对象将string转为int
is >> square_width;
cout << endl;
cout << "Code: " << analy.Change_str(code) << endl;
@ -65,11 +64,11 @@ void show_case(string str, string width) {
void cal_case(string str) {
unsigned long long code;
vector <unsigned long long> dat;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
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;
@ -88,11 +87,11 @@ void cal_case(string str) {
void cal_case(string str, string File_name) {
unsigned long long code;
vector <unsigned long long> dat;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
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;
@ -122,18 +121,18 @@ void cal_case(string str, string File_name) {
void cal_target(string str_1, string str_2) {
unsigned long long code, target;
vector <unsigned long long> dat;
if (code_check(str_1) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
if (code_check(str_2) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
target = checked_code;
if (code_check(str_1) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
if (code_check(str_2) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
target = checked_code;
HRD_cal cal;
cout << "Start code: " << cal.Change_str(code) << endl;
cout << "Target code: " << cal.Change_str(target) << endl;
@ -152,18 +151,18 @@ void cal_target(string str_1, string str_2) {
void cal_target(string str_1, string str_2, string File_name) {
unsigned long long code, target;
vector <unsigned long long> dat;
if (code_check(str_1) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
if (code_check(str_2) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
target = checked_code;
if (code_check(str_1) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
if (code_check(str_2) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
target = checked_code;
HRD_cal cal;
cout << "Start code: " << cal.Change_str(code) << endl;
cout << "Target code: " << cal.Change_str(target) << endl;
@ -193,11 +192,11 @@ void cal_target(string str_1, string str_2, string File_name) {
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;
}
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;
@ -209,11 +208,11 @@ void cal_group(string str) {
void cal_group(string str, string File_name) {
unsigned long long code;
vector <unsigned long long> dat;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
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;
@ -235,11 +234,11 @@ void cal_group(string str, string File_name) {
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;
}
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;
@ -252,11 +251,11 @@ void analy_case(string str, bool quiet) {
void analy_case(string str, string File_name, bool quiet) {
unsigned long long code;
vector <unsigned long long> dat;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
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;
@ -276,11 +275,11 @@ void analy_case(string str, string File_name, bool quiet) {
void analy_group(string str, string File_name_1, string File_name_2, bool is_all) {
unsigned long long code;
vector <unsigned long long> dat;
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
if (code_check(str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
HRD_group group;
code = checked_code;
cout << "Start code: " << group.Change_str(code) << endl;
@ -395,103 +394,103 @@ void parameter_err() {
}
int main(int argc, char* argv[]) {
cout << endl << "Klotski engine by Dnomd343" << endl;
if (argc <= 1) {
cout << endl << "Klotski engine by Dnomd343" << endl;
if (argc <= 1) {
cout << "no parameter" << endl;
cout << "You can try \"--help\" for more information" << endl;
cout << endl;
return 0;
}
string parameter;
parameter = argv[1];
if (parameter == "--show") {
}
string parameter;
parameter = argv[1];
if (parameter == "--show") {
if (argc == 3) {
show_case(argv[2]);
} else if (argc == 4) {
} else if (argc == 4) {
show_case(argv[2], argv[3]);
} else {
} else {
parameter_err();
}
} else if (parameter == "--cal") {
if (argc == 3) {
}
} else if (parameter == "--cal") {
if (argc == 3) {
cal_case(argv[2]);
} else if (argc == 4) {
} else if (argc == 4) {
cal_case(argv[2], argv[3]);
} else {
} else {
parameter_err();
}
} else if (parameter == "--cal-target") {
if (argc == 4) {
}
} else if (parameter == "--cal-target") {
if (argc == 4) {
cal_target(argv[2], argv[3]);
} else if (argc == 5) {
} else if (argc == 5) {
cal_target(argv[2], argv[3], argv[4]);
} else {
} else {
parameter_err();
}
} else if (parameter == "--group") {
if (argc == 3) {
cal_group(argv[2]);
}
} else if (parameter == "--group") {
if (argc == 3) {
cal_group(argv[2]);
} else if (argc == 4) {
cal_group(argv[2], argv[3]);
} else {
} else {
parameter_err();
}
} else if (parameter == "--analy") {
if (argc == 3) {
}
} else if (parameter == "--analy") {
if (argc == 3) {
analy_case(argv[2], false);
} else if (argc == 4) {
analy_case(argv[2], argv[3], false);
} else {
} else {
parameter_err();
}
} else if (parameter == "--analy-quiet") {
if (argc == 4) {
}
} else if (parameter == "--analy-quiet") {
if (argc == 4) {
analy_case(argv[2], argv[3], true);
} else {
} else {
parameter_err();
}
} else if (parameter == "--analy-group") {
if (argc == 5) {
}
} else if (parameter == "--analy-group") {
if (argc == 5) {
analy_group(argv[2], argv[3], argv[4], false);
} else {
} else {
parameter_err();
}
}
} else if (parameter == "--analy-group-integral") {
if (argc == 5) {
if (argc == 5) {
analy_group(argv[2], argv[3], argv[4], true);
} else {
} else {
parameter_err();
}
}
} else if (parameter == "--analy-multi-group") {
if (argc == 5) {
if (argc == 5) {
analy_multi_group(argv[2], argv[3], argv[4], false);
} else {
} else {
parameter_err();
}
}
} else if (parameter == "--analy-multi-group-integral") {
if (argc == 5) {
if (argc == 5) {
analy_multi_group(argv[2], argv[3], argv[4], true);
} else {
} else {
parameter_err();
}
} else if (parameter == "--all") {
if (argc == 2) {
}
} else if (parameter == "--all") {
if (argc == 2) {
find_all();
} else {
} else {
parameter_err();
}
} else if (parameter == "--all-code") {
if (argc == 3) {
}
} else if (parameter == "--all-code") {
if (argc == 3) {
find_all_code(argv[2]);
} else {
} else {
parameter_err();
}
} else if (parameter == "--help") {
show_help();
} else {
cout << "unknow parameter" << endl;
}
} else if (parameter == "--help") {
show_help();
} else {
cout << "unknow parameter" << endl;
cout << "You can try \"--help\" for more information" << endl;
cout << endl;
}
return 0;
return 0;
}

Loading…
Cancel
Save