aboutsummaryrefslogtreecommitdiff
path: root/src/steps.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/steps.c165
1 files changed, 41 insertions, 124 deletions
diff --git a/src/steps.c b/src/steps.c
index cfd9a23..98e26b5 100644
--- a/src/steps.c
+++ b/src/steps.c
@@ -5,30 +5,22 @@
5/* Checkers, estimators and validators ***************************************/ 5/* Checkers, estimators and validators ***************************************/
6 6
7static bool check_centers(Cube cube); 7static bool check_centers(Cube cube);
8static bool check_coany_HTM(Cube cube);
9static bool check_coud_HTM(Cube cube); 8static bool check_coud_HTM(Cube cube);
10static bool check_coany_URF(Cube cube);
11static bool check_coud_URF(Cube cube); 9static bool check_coud_URF(Cube cube);
12static bool check_corners_HTM(Cube cube); 10static bool check_corners_HTM(Cube cube);
13static bool check_corners_URF(Cube cube); 11static bool check_corners_URF(Cube cube);
14static bool check_cornershtr(Cube cube); 12static bool check_cornershtr(Cube cube);
15static bool check_eoany(Cube cube);
16static bool check_eofb(Cube cube); 13static bool check_eofb(Cube cube);
17static bool check_drany(Cube cube);
18static bool check_drud(Cube cube); 14static bool check_drud(Cube cube);
19static bool check_htr(Cube cube); 15static bool check_htr(Cube cube);
20 16
21static int estimate_eoany_HTM(DfsArg *arg);
22static int estimate_eofb_HTM(DfsArg *arg); 17static int estimate_eofb_HTM(DfsArg *arg);
23static int estimate_coany_HTM(DfsArg *arg);
24static int estimate_coud_HTM(DfsArg *arg); 18static int estimate_coud_HTM(DfsArg *arg);
25static int estimate_coany_URF(DfsArg *arg);
26static int estimate_coud_URF(DfsArg *arg); 19static int estimate_coud_URF(DfsArg *arg);
27static int estimate_corners_HTM(DfsArg *arg); 20static int estimate_corners_HTM(DfsArg *arg);
28static int estimate_cornershtr_HTM(DfsArg *arg); 21static int estimate_cornershtr_HTM(DfsArg *arg);
29static int estimate_corners_URF(DfsArg *arg); 22static int estimate_corners_URF(DfsArg *arg);
30static int estimate_cornershtr_URF(DfsArg *arg); 23static int estimate_cornershtr_URF(DfsArg *arg);
31static int estimate_drany_HTM(DfsArg *arg);
32static int estimate_drud_HTM(DfsArg *arg); 24static int estimate_drud_HTM(DfsArg *arg);
33static int estimate_drud_eofb(DfsArg *arg); 25static int estimate_drud_eofb(DfsArg *arg);
34static int estimate_dr_eofb(DfsArg *arg); 26static int estimate_dr_eofb(DfsArg *arg);
@@ -46,8 +38,9 @@ static bool validate_singlecw_ending(Alg *alg);
46 38
47/* Pre-transformation detectors **********************************************/ 39/* Pre-transformation detectors **********************************************/
48 40
49static Trans detect_pretrans_eofb(Cube cube); 41static int detect_pretrans_eofb(Cube cube, Trans *ret);
50static Trans detect_pretrans_drud(Cube cube); 42static int detect_pretrans_drud(Cube cube, Trans *ret);
43static int detect_pretrans_void_3axis(Cube cube, Trans *ret);
51 44
52/* Messages for when cube is not ready ***************************************/ 45/* Messages for when cube is not ready ***************************************/
53 46
@@ -206,14 +199,14 @@ eoany_HTM = {
206 .name = "EO on any axis", 199 .name = "EO on any axis",
207 200
208 .final = false, 201 .final = false,
209 .is_done = check_eoany, 202 .is_done = check_eofb,
210 .estimate = estimate_eoany_HTM, 203 .estimate = estimate_eofb_HTM,
211 .ready = check_centers, 204 .ready = check_centers,
212 .ready_msg = check_centers_msg, 205 .ready_msg = check_centers_msg,
213 .is_valid = validate_singlecw_ending, 206 .is_valid = validate_singlecw_ending,
214 .moveset = &moveset_HTM, 207 .moveset = &moveset_HTM,
215 208
216 .pre_trans = uf, 209 .detect = detect_pretrans_void_3axis,
217 210
218 .tables = {&pd_eofb_HTM}, 211 .tables = {&pd_eofb_HTM},
219 .ntables = 1, 212 .ntables = 1,
@@ -283,13 +276,13 @@ coany_HTM = {
283 .name = "CO on any axis", 276 .name = "CO on any axis",
284 277
285 .final = false, 278 .final = false,
286 .is_done = check_coany_HTM, 279 .is_done = check_coud_HTM,
287 .estimate = estimate_coany_HTM, 280 .estimate = estimate_coud_HTM,
288 .ready = NULL, 281 .ready = NULL,
289 .is_valid = validate_singlecw_ending, 282 .is_valid = validate_singlecw_ending,
290 .moveset = &moveset_HTM, 283 .moveset = &moveset_HTM,
291 284
292 .pre_trans = uf, 285 .detect = detect_pretrans_void_3axis,
293 286
294 .tables = {&pd_coud_HTM}, 287 .tables = {&pd_coud_HTM},
295 .ntables = 1, 288 .ntables = 1,
@@ -355,13 +348,13 @@ coany_URF = {
355 .name = "CO any axis (URF moveset)", 348 .name = "CO any axis (URF moveset)",
356 349
357 .final = false, 350 .final = false,
358 .is_done = check_coany_URF, 351 .is_done = check_coud_URF,
359 .estimate = estimate_coany_URF, 352 .estimate = estimate_coud_URF,
360 .ready = NULL, 353 .ready = NULL,
361 .is_valid = validate_singlecw_ending, 354 .is_valid = validate_singlecw_ending,
362 .moveset = &moveset_URF, 355 .moveset = &moveset_URF,
363 356
364 .pre_trans = uf, 357 .detect = detect_pretrans_void_3axis,
365 358
366 .tables = {&pd_coud_HTM}, 359 .tables = {&pd_coud_HTM},
367 .ntables = 1, 360 .ntables = 1,
@@ -501,14 +494,14 @@ drany_HTM = {
501 .name = "DR on any axis", 494 .name = "DR on any axis",
502 495
503 .final = false, 496 .final = false,
504 .is_done = check_drany, 497 .is_done = check_drud,
505 .estimate = estimate_drany_HTM, 498 .estimate = estimate_drud_HTM,
506 .ready = check_centers, 499 .ready = check_centers,
507 .ready_msg = check_centers_msg, 500 .ready_msg = check_centers_msg,
508 .is_valid = validate_singlecw_ending, 501 .is_valid = validate_singlecw_ending,
509 .moveset = &moveset_HTM, 502 .moveset = &moveset_HTM,
510 503
511 .pre_trans = uf, 504 .detect = detect_pretrans_void_3axis,
512 505
513 .tables = {&pd_drud_sym16_HTM}, 506 .tables = {&pd_drud_sym16_HTM},
514 .ntables = 1, 507 .ntables = 1,
@@ -1003,31 +996,12 @@ check_centers(Cube cube)
1003} 996}
1004 997
1005static bool 998static bool
1006check_coany_HTM(Cube cube)
1007{
1008 return cube.cofb == 0 || cube.corl == 0 || cube.coud == 0;
1009}
1010
1011static bool
1012check_coud_HTM(Cube cube) 999check_coud_HTM(Cube cube)
1013{ 1000{
1014 return cube.coud == 0; 1001 return cube.coud == 0;
1015} 1002}
1016 1003
1017static bool 1004static bool
1018check_coany_URF(Cube cube)
1019{
1020 Cube c2, c3;
1021
1022 c2 = apply_move(y, apply_move(z, cube));
1023 c3 = apply_move(y, apply_move(x, cube));
1024
1025 return check_coany_HTM(cube) ||
1026 check_coany_HTM(c2) ||
1027 check_coany_HTM(c3);
1028}
1029
1030static bool
1031check_coud_URF(Cube cube) 1005check_coud_URF(Cube cube)
1032{ 1006{
1033 Cube c2, c3; 1007 Cube c2, c3;
@@ -1066,26 +1040,12 @@ check_cornershtr(Cube cube)
1066} 1040}
1067 1041
1068static bool 1042static bool
1069check_eoany(Cube cube)
1070{
1071 return cube.eofb == 0 || cube.eorl == 0 || cube.eoud == 0;
1072}
1073
1074static bool
1075check_eofb(Cube cube) 1043check_eofb(Cube cube)
1076{ 1044{
1077 return cube.eofb == 0; 1045 return cube.eofb == 0;
1078} 1046}
1079 1047
1080static bool 1048static bool
1081check_drany(Cube cube)
1082{
1083 return (cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0) ||
1084 (cube.eorl == 0 && cube.eoud == 0 && cube.cofb == 0) ||
1085 (cube.eoud == 0 && cube.eofb == 0 && cube.corl == 0);
1086}
1087
1088static bool
1089check_drud(Cube cube) 1049check_drud(Cube cube)
1090{ 1050{
1091 return cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0; 1051 return cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0;
@@ -1098,61 +1058,18 @@ check_htr(Cube cube)
1098} 1058}
1099 1059
1100static int 1060static int
1101estimate_eoany_HTM(DfsArg *arg)
1102{
1103 int r1, r2, r3;
1104
1105 r1 = ptableval(&pd_eofb_HTM, arg->cube);
1106 r2 = ptableval(&pd_eofb_HTM, apply_trans(ur, arg->cube));
1107 r3 = ptableval(&pd_eofb_HTM, apply_trans(fd, arg->cube));
1108
1109 return MIN(r1, MIN(r2, r3));
1110}
1111
1112static int
1113estimate_eofb_HTM(DfsArg *arg) 1061estimate_eofb_HTM(DfsArg *arg)
1114{ 1062{
1115 return ptableval(&pd_eofb_HTM, arg->cube); 1063 return ptableval(&pd_eofb_HTM, arg->cube);
1116} 1064}
1117 1065
1118static int 1066static int
1119estimate_coany_HTM(DfsArg *arg)
1120{
1121 int r1, r2, r3;
1122
1123 r1 = ptableval(&pd_coud_HTM, arg->cube);
1124 r2 = ptableval(&pd_coud_HTM, apply_trans(rf, arg->cube));
1125 r3 = ptableval(&pd_coud_HTM, apply_trans(fd, arg->cube));
1126
1127 return MIN(r1, MIN(r2, r3));
1128}
1129
1130static int
1131estimate_coud_HTM(DfsArg *arg) 1067estimate_coud_HTM(DfsArg *arg)
1132{ 1068{
1133 return ptableval(&pd_coud_HTM, arg->cube); 1069 return ptableval(&pd_coud_HTM, arg->cube);
1134} 1070}
1135 1071
1136static int 1072static int
1137estimate_coany_URF(DfsArg *arg)
1138{
1139 int r1, r2, r3;
1140 Cube c;
1141
1142 c = arg->cube;
1143
1144 r1 = estimate_coud_URF(arg);
1145 arg->cube = apply_trans(rf, c);
1146 r2 = estimate_coud_URF(arg);
1147 arg->cube = apply_trans(fd, c);
1148 r3 = estimate_coud_URF(arg);
1149
1150 arg->cube = c;
1151
1152 return MIN(r1, MIN(r2, r3));
1153}
1154
1155static int
1156estimate_coud_URF(DfsArg *arg) 1073estimate_coud_URF(DfsArg *arg)
1157{ 1074{
1158 /* TODO: I can improve this by checking first the orientation of 1075 /* TODO: I can improve this by checking first the orientation of
@@ -1232,18 +1149,6 @@ estimate_corners_URF(DfsArg *arg)
1232} 1149}
1233 1150
1234static int 1151static int
1235estimate_drany_HTM(DfsArg *arg)
1236{
1237 int r1, r2, r3;
1238
1239 r1 = ptableval(&pd_drud_sym16_HTM, arg->cube);
1240 r2 = ptableval(&pd_drud_sym16_HTM, apply_trans(rf, arg->cube));
1241 r3 = ptableval(&pd_drud_sym16_HTM, apply_trans(fd, arg->cube));
1242
1243 return MIN(r1, MIN(r2, r3));
1244}
1245
1246static int
1247estimate_drud_HTM(DfsArg *arg) 1152estimate_drud_HTM(DfsArg *arg)
1248{ 1153{
1249 return ptableval(&pd_drud_sym16_HTM, arg->cube); 1154 return ptableval(&pd_drud_sym16_HTM, arg->cube);
@@ -1515,28 +1420,40 @@ validate_singlecw_ending(Alg *alg)
1515 1420
1516/* Pre-transformation detectors **********************************************/ 1421/* Pre-transformation detectors **********************************************/
1517 1422
1518static Trans 1423static int
1519detect_pretrans_eofb(Cube cube) 1424detect_pretrans_eofb(Cube cube, Trans *ret)
1520{ 1425{
1521 Trans i; 1426 int i, n;
1427 static Trans tt[3] = {uf, ur, fd};
1522 1428
1523 for (i = 0; i < NROTATIONS; i++) 1429 for (i = 0, n = 0; i < 3; i++)
1524 if (check_eofb(apply_trans(i, cube))) 1430 if (check_eofb(apply_trans(tt[i], cube)))
1525 return i; 1431 ret[n++] = tt[i];
1526 1432
1527 return 0; 1433 return n;
1528} 1434}
1529 1435
1530static Trans 1436static int
1531detect_pretrans_drud(Cube cube) 1437detect_pretrans_drud(Cube cube, Trans *ret)
1532{ 1438{
1533 Trans i; 1439 int i, n;
1440 static Trans tt[3] = {uf, ur, fd};
1441
1442 for (i = 0, n = 0; i < 3; i++)
1443 if (check_drud(apply_trans(tt[i], cube)))
1444 ret[n++] = tt[i];
1534 1445
1535 for (i = 0; i < NROTATIONS; i++) 1446 return n;
1536 if (check_drud(apply_trans(i, cube))) 1447}
1537 return i; 1448
1449static int
1450detect_pretrans_void_3axis(Cube cube, Trans *ret)
1451{
1452 ret[0] = uf;
1453 ret[1] = fr;
1454 ret[2] = rd;
1538 1455
1539 return 0; 1456 return 3;
1540} 1457}
1541 1458
1542/* Public functions **********************************************************/ 1459/* Public functions **********************************************************/

Generated with cgit - Back to sebastiano.tronto.net