-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnautilus.cpp
More file actions
1334 lines (1055 loc) · 44 KB
/
nautilus.cpp
File metadata and controls
1334 lines (1055 loc) · 44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file is part of "GR Cube"
Copyright (C) 2022 German Ramos Rodriguez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
German Ramos Rodriguez
Vigo, Spain
grvigo@hotmail.com
*/
#include "nautilus.h"
#include "collection.h"
namespace grcube3
{
// Reset the search results
void Nautilus::Reset()
{
for (int i = 0; i < 24; i++)
{
Inspections[i].clear();
AlgFB[i].clear();
AlgSB[i].clear();
AlgdFR[i].clear();
AlgNCLL[i].clear();
AlgL5E[i].clear();
AlgNCOLL[i].clear();
AlgEODF[i].clear();
AlgF2L[i].clear();
AlgZBLL[i].clear();
AlgOCLL[i].clear();
AlgPLL[i].clear();
AlgCOLL[i].clear();
AlgEPLL[i].clear();
CasesNCLL[i].clear();
CasesL5E[i].clear();
CasesNCOLL[i].clear();
CasesEODF[i].clear();
CasesZBLL[i].clear();
CasesOCLL[i].clear();
CasesPLL[i].clear();
CasesCOLL[i].clear();
CasesEPLL[i].clear();
}
MaxDepthFB = MaxDepthSB = MaxDepthdFR = MaxDepthF2L = 0u;
TimeFB = TimeSB = TimedFR = TimeNCLL = TimeNCOLL = TimeL5E = TimeEODF = TimeF2L = TimeZBLL = TimeOCLL = TimePLL = TimeCOLL = TimeEPLL = 0.0;
Metric = Metrics::Movements; // Default metric
}
// Search the best first blocks solve algorithm with the given search depth
// Return false if no first blocks found
bool Nautilus::SearchFB(const uint MaxDepth, const uint MaxSolves)
{
const auto time_fb_start = std::chrono::system_clock::now();
MaxDepthFB = (MaxDepth <= 4u ? 4u : MaxDepth);
// Deep search for first block
DS.Clear();
DS.SetScramble(Scramble);
DS.AddToOptionalPieces(Pgr::UF_B1);
DS.AddToOptionalPieces(Pgr::UB_B1);
DS.AddToOptionalPieces(Pgr::UR_B1);
DS.AddToOptionalPieces(Pgr::UL_B1);
DS.AddToOptionalPieces(Pgr::DF_B1);
DS.AddToOptionalPieces(Pgr::DB_B1);
DS.AddToOptionalPieces(Pgr::DR_B1);
DS.AddToOptionalPieces(Pgr::DL_B1);
DS.AddToOptionalPieces(Pgr::FU_B1);
DS.AddToOptionalPieces(Pgr::FD_B1);
DS.AddToOptionalPieces(Pgr::FR_B1);
DS.AddToOptionalPieces(Pgr::FL_B1);
DS.AddToOptionalPieces(Pgr::BU_B1);
DS.AddToOptionalPieces(Pgr::BD_B1);
DS.AddToOptionalPieces(Pgr::BR_B1);
DS.AddToOptionalPieces(Pgr::BL_B1);
DS.AddToOptionalPieces(Pgr::RU_B1);
DS.AddToOptionalPieces(Pgr::RD_B1);
DS.AddToOptionalPieces(Pgr::RF_B1);
DS.AddToOptionalPieces(Pgr::RB_B1);
DS.AddToOptionalPieces(Pgr::LU_B1);
DS.AddToOptionalPieces(Pgr::LD_B1);
DS.AddToOptionalPieces(Pgr::LF_B1);
DS.AddToOptionalPieces(Pgr::LB_B1);
// First level is extended in the search to improve the multithreading - first level will not be checked
// (it's supose that the first block not will be solved in a single movement)
const SearchUnit URoot(SequenceTypes::DOUBLE);
const SearchUnit U(SequenceTypes::SINGLE);
SearchLevel L_Root(SearchCheck::NO_CHECK);
L_Root.Add(URoot);
SearchLevel L_Check(SearchCheck::CHECK);
L_Check.Add(U);
SearchLevel L_NoCheck(SearchCheck::NO_CHECK);
L_NoCheck.Add(U);
DS.AddSearchLevel(L_Root); // Level 1 (two steps -DOUBLE- root algorithms)
DS.AddSearchLevel(L_NoCheck); // Level 2
DS.AddSearchLevel(L_Check); // Level 3
for (uint l = 4u; l < MaxDepthFB; l++) DS.AddSearchLevel(L_Check); // Levels 4 to MaxDepth
DS.UpdateRootData();
// DS.SetMinDepth(DS.GetMaxDepth() - 2u);
DS.Run(Cores);
Cores = DS.GetUsedCores(); // Update to the real number of cores used
EvaluateFB(DS.GetSolves(), MaxSolves);
const std::chrono::duration<double> fb_elapsed_seconds = std::chrono::system_clock::now() - time_fb_start;
TimeFB = fb_elapsed_seconds.count();
return !DS.GetSolves().empty();
}
// Search the best first block solve algorithms from an algorithms vector
void Nautilus::EvaluateFB(const std::vector<Algorithm>& Solves, const uint MaxSolves)
{
// Best first block solve algorithms adapted to spin
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
Stp T1, T2;
Algorithm Insp;
EvaluateNautilusFBResult(AlgFB[sp], MaxSolves, Solves, CubeBase, spin, Plc::BEST);
Inspections[sp].clear();
if (!AlgFB[sp].empty())
{
Insp.Clear();
Cube::GetSpinsSteps(CubeBase.GetSpin(), spin, T1, T2);
if (T1 != Stp::NONE) Insp.Append(T1);
if (T2 != Stp::NONE) Insp.Append(T2);
for (auto& fb : AlgFB[sp])
{
if (T1 != Stp::NONE) fb.TransformTurn(T1);
if (T2 != Stp::NONE) fb.TransformTurn(T2);
Inspections[sp].push_back(Insp);
}
}
}
}
// Search the best second block solve algorithm with the given search depth
void Nautilus::SearchSB(const uint MaxDepth)
{
const auto time_sb_start = std::chrono::system_clock::now();
bool Skip = false; // Skip the search (for multi threading)
MaxDepthSB = (MaxDepth <= 4u ? 4u : MaxDepth);
const SearchUnit U_SB(SequenceTypes::SINGLE, Sst::NAUTILUS_rRUM);
const SearchUnit U_SB_Seq(SequenceTypes::CONJUGATE_SINGLE, Sst::SINGLE_R, Sst::LATERAL_SINGLE_FBp);
SearchLevel L_Check(SearchCheck::CHECK);
L_Check.Add(U_SB);
L_Check.Add(U_SB_Seq);
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgSB[sp].clear();
Pgr B1, B2S;
switch (spin)
{
case Spn::UF: B1 = Pgr::UF_B1; B2S = Pgr::UF_B2S2; break;
case Spn::UB: B1 = Pgr::UB_B1; B2S = Pgr::UB_B2S2; break;
case Spn::UR: B1 = Pgr::UR_B1; B2S = Pgr::UR_B2S2; break;
case Spn::UL: B1 = Pgr::UL_B1; B2S = Pgr::UL_B2S2; break;
case Spn::DF: B1 = Pgr::DF_B1; B2S = Pgr::DF_B2S2; break;
case Spn::DB: B1 = Pgr::DB_B1; B2S = Pgr::DB_B2S2; break;
case Spn::DR: B1 = Pgr::DR_B1; B2S = Pgr::DR_B2S2; break;
case Spn::DL: B1 = Pgr::DL_B1; B2S = Pgr::DL_B2S2; break;
case Spn::FU: B1 = Pgr::FU_B1; B2S = Pgr::FU_B2S2; break;
case Spn::FD: B1 = Pgr::FD_B1; B2S = Pgr::FD_B2S2; break;
case Spn::FR: B1 = Pgr::FR_B1; B2S = Pgr::FR_B2S2; break;
case Spn::FL: B1 = Pgr::FL_B1; B2S = Pgr::FL_B2S2; break;
case Spn::BU: B1 = Pgr::BU_B1; B2S = Pgr::BU_B2S2; break;
case Spn::BD: B1 = Pgr::BD_B1; B2S = Pgr::BD_B2S2; break;
case Spn::BR: B1 = Pgr::BR_B1; B2S = Pgr::BR_B2S2; break;
case Spn::BL: B1 = Pgr::BL_B1; B2S = Pgr::BL_B2S2; break;
case Spn::RU: B1 = Pgr::RU_B1; B2S = Pgr::RU_B2S2; break;
case Spn::RD: B1 = Pgr::RD_B1; B2S = Pgr::RD_B2S2; break;
case Spn::RF: B1 = Pgr::RF_B1; B2S = Pgr::RF_B2S2; break;
case Spn::RB: B1 = Pgr::RB_B1; B2S = Pgr::RB_B2S2; break;
case Spn::LU: B1 = Pgr::LU_B1; B2S = Pgr::LU_B2S2; break;
case Spn::LD: B1 = Pgr::LD_B1; B2S = Pgr::LD_B2S2; break;
case Spn::LF: B1 = Pgr::LF_B1; B2S = Pgr::LF_B2S2; break;
case Spn::LB: B1 = Pgr::LB_B1; B2S = Pgr::LB_B2S2; break;
default: return; // Should not happend
}
uint n = 0u;
for (const auto& FB : AlgFB[sp])
{
AlgSB[sp].push_back(Algorithm(""));
if (Skip) continue;
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(FB);
// Deep search for second block
DS.Clear();
DS.SetScramble(AlgStart);
DS.AddToMandatoryPieces(B1);
DS.AddToMandatoryPieces(B2S);
for (uint l = 1u; l < MaxDepthSB; l++) DS.AddSearchLevel(L_Check); // Add needed search levels
DS.UpdateRootData();
DS.Run(Cores);
Skip = DS.CheckSkipSearch();
Cube CubeNautilus(AlgStart);
Method::EvaluateNautilusSBResult(AlgSB[sp][n], DS.GetSolves(), CubeNautilus, spin, Plc::BEST);
n++;
}
}
const std::chrono::duration<double> sb_elapsed_seconds = std::chrono::system_clock::now() - time_sb_start;
TimeSB = sb_elapsed_seconds.count();
}
// Add the pair containing the DFR corner and FR edge
void Nautilus::SearchPairdFR(bool NoCornerOriented)
{
const auto time_dFR_start = std::chrono::system_clock::now();
bool Skip = false; // Skip the search (for multi threading)
const SearchUnit U_Root(SequenceTypes::DOUBLE, Sst::NAUTILUS_rRUM);
const SearchUnit U_UR(SequenceTypes::SINGLE, Sst::NAUTILUS_rRUM);
SearchLevel L_Root(SearchCheck::NO_CHECK);
L_Root.Add(U_Root);
SearchLevel L_Check(SearchCheck::CHECK);
L_Check.Add(U_UR);
MaxDepthdFR = 8u;
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
Pgr B1, B2, PAIR;
Pcp dFR_Edge, dFR_Corner;
switch (spin)
{
case Spn::UF: B1 = Pgr::UF_B1; B2 = Pgr::PETRUS_DBR; PAIR = Pgr::F2L_D_DFR; break;
case Spn::UB: B1 = Pgr::UB_B1; B2 = Pgr::PETRUS_DFL; PAIR = Pgr::F2L_D_DBL; break;
case Spn::UR: B1 = Pgr::UR_B1; B2 = Pgr::PETRUS_DBL; PAIR = Pgr::F2L_D_DBR; break;
case Spn::UL: B1 = Pgr::UL_B1; B2 = Pgr::PETRUS_DFR; PAIR = Pgr::F2L_D_DFL; break;
case Spn::DF: B1 = Pgr::DF_B1; B2 = Pgr::PETRUS_UBL; PAIR = Pgr::F2L_U_UFL; break;
case Spn::DB: B1 = Pgr::DB_B1; B2 = Pgr::PETRUS_UFR; PAIR = Pgr::F2L_U_UBR; break;
case Spn::DR: B1 = Pgr::DR_B1; B2 = Pgr::PETRUS_UFL; PAIR = Pgr::F2L_U_UFR; break;
case Spn::DL: B1 = Pgr::DL_B1; B2 = Pgr::PETRUS_UBR; PAIR = Pgr::F2L_U_UBL; break;
case Spn::FU: B1 = Pgr::FU_B1; B2 = Pgr::PETRUS_DBL; PAIR = Pgr::F2L_B_UBL; break;
case Spn::FD: B1 = Pgr::FD_B1; B2 = Pgr::PETRUS_UBR; PAIR = Pgr::F2L_B_DBR; break;
case Spn::FR: B1 = Pgr::FR_B1; B2 = Pgr::PETRUS_UBL; PAIR = Pgr::F2L_B_UBR; break;
case Spn::FL: B1 = Pgr::FL_B1; B2 = Pgr::PETRUS_DBR; PAIR = Pgr::F2L_B_DBL; break;
case Spn::BU: B1 = Pgr::BU_B1; B2 = Pgr::PETRUS_DFR; PAIR = Pgr::F2L_F_UFR; break;
case Spn::BD: B1 = Pgr::BD_B1; B2 = Pgr::PETRUS_UFL; PAIR = Pgr::F2L_F_DFL; break;
case Spn::BR: B1 = Pgr::BR_B1; B2 = Pgr::PETRUS_DFL; PAIR = Pgr::F2L_F_DFR; break;
case Spn::BL: B1 = Pgr::BL_B1; B2 = Pgr::PETRUS_UFR; PAIR = Pgr::F2L_F_UFL; break;
case Spn::RU: B1 = Pgr::RU_B1; B2 = Pgr::PETRUS_DFL; PAIR = Pgr::F2L_L_UFL; break;
case Spn::RD: B1 = Pgr::RD_B1; B2 = Pgr::PETRUS_UBL; PAIR = Pgr::F2L_L_DBL; break;
case Spn::RF: B1 = Pgr::RF_B1; B2 = Pgr::PETRUS_DBL; PAIR = Pgr::F2L_L_DFL; break;
case Spn::RB: B1 = Pgr::RB_B1; B2 = Pgr::PETRUS_UFL; PAIR = Pgr::F2L_L_UBL; break;
case Spn::LU: B1 = Pgr::LU_B1; B2 = Pgr::PETRUS_DBR; PAIR = Pgr::F2L_R_UBR; break;
case Spn::LD: B1 = Pgr::LD_B1; B2 = Pgr::PETRUS_UFR; PAIR = Pgr::F2L_R_DFR; break;
case Spn::LF: B1 = Pgr::LF_B1; B2 = Pgr::PETRUS_UBR; PAIR = Pgr::F2L_R_UFR; break;
case Spn::LB: B1 = Pgr::LB_B1; B2 = Pgr::PETRUS_DFR; PAIR = Pgr::F2L_R_DBR; break;
default: return; // Should not happend
}
dFR_Edge = Cube::FromAbsPosition(App::FR, spin);
dFR_Corner = Cube::FromAbsPosition(App::DFR, spin);
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgdFR[sp].push_back(Algorithm(""));
if (Skip) continue;
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(AlgFB[sp][n]);
AlgStart.Append(AlgSB[sp][n]);
const Cube C(AlgStart);
if (!C.IsSolved(B1) || !C.IsSolved(B2) || C.IsSolved(PAIR)) continue; // dFR pair already solved or not blocks solved
// Deep search for dFR pair
DS.Clear();
DS.SetScramble(AlgStart);
DS.SetShortPolicy();
DS.AddToMandatoryPieces(B1);
DS.AddToMandatoryPieces(B2);
if (NoCornerOriented)
{
DS.AddToMandatoryPieces(dFR_Edge);
DS.AddToMandatoryPositions(dFR_Corner);
}
else DS.AddToMandatoryPieces(PAIR);
DS.AddSearchLevel(L_Root);
for (uint l = 2; l < MaxDepthdFR; l++) DS.AddSearchLevel(L_Check); // Add needed search levels
DS.UpdateRootData();
DS.Run(Cores);
Skip = DS.CheckSkipSearch();
if (NoCornerOriented) DS.EvaluateShortestResult(AlgdFR[sp][n], true);
else EvaluateNautilusSBResult(AlgdFR[sp][n], DS.GetSolves(), C, spin, Plc::BEST);
}
}
const std::chrono::duration<double> dFR_elapsed_seconds = std::chrono::system_clock::now() - time_dFR_start;
TimedFR = dFR_elapsed_seconds.count();
}
// NCLL search
void Nautilus::SearchNCLL(const Plc Pol, const bool AddLastUMovement)
{
const auto time_NCLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgNCLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgNCLL[sp].push_back(Algorithm(""));
CasesNCLL[sp].push_back("");
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(AlgFB[sp][n]);
AlgStart.Append(AlgSB[sp][n]);
AlgStart.Append(AlgdFR[sp][n]);
const Cube CubeNautilus(AlgStart);
if (!IsNautilusSBBuilt(CubeNautilus) || !IsF2LPairsBuilt(CubeNautilus)) continue;
Stp LastUStep;
CornersLL(AlgNCLL[sp][n], CasesNCLL[sp][n], LastUStep, Algset_NCLL, Pol, Metric, CubeNautilus);
if (AddLastUMovement) AlgNCLL[sp][n].Append(LastUStep);
}
}
const std::chrono::duration<double> NCLL_elapsed_seconds = std::chrono::system_clock::now() - time_NCLL_start;
TimeNCLL = NCLL_elapsed_seconds.count();
}
// NCOLL search
void Nautilus::SearchNCOLL(const Plc Pol, const bool AddLastUMovement)
{
const auto time_NCOLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgNCOLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgNCOLL[sp].push_back(Algorithm(""));
CasesNCOLL[sp].push_back("");
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(AlgFB[sp][n]);
AlgStart.Append(AlgSB[sp][n]);
AlgStart.Append(AlgdFR[sp][n]);
const Cube CubeNautilus(AlgStart);
if (!IsNautilusSBBuilt(CubeNautilus) || !IsF2LPairsBuilt(CubeNautilus)) continue;
Stp LastUStep;
CornersLL(AlgNCOLL[sp][n], CasesNCOLL[sp][n], LastUStep, Algset_NCOLL, Pol, Metric, CubeNautilus);
if (AddLastUMovement) AlgNCOLL[sp][n].Append(LastUStep);
}
}
const std::chrono::duration<double> NCOLL_elapsed_seconds = std::chrono::system_clock::now() - time_NCOLL_start;
TimeNCOLL = NCOLL_elapsed_seconds.count();
}
// TNCLL search
void Nautilus::SearchTNCLL(const Plc Pol, const bool AddLastUMovement)
{
const auto time_TNCLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgTNCLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgTNCLL[sp].push_back(Algorithm(""));
CasesTNCLL[sp].push_back("");
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(AlgFB[sp][n]);
AlgStart.Append(AlgSB[sp][n]);
AlgStart.Append(AlgdFR[sp][n]);
const Cube CubeNautilus(AlgStart);
if (!IsNautilusSBBuilt(CubeNautilus)) continue;
Stp LastUStep;
if (IsF2LPairsBuilt(CubeNautilus)) // If last pair is built, use NCLL algorithms
CornersLL(AlgTNCLL[sp][n], CasesTNCLL[sp][n], LastUStep, Algset_NCLL, Pol, Metric, CubeNautilus);
else
CornersLL(AlgTNCLL[sp][n], CasesTNCLL[sp][n], LastUStep, Algset_TNCLL, Pol, Metric, CubeNautilus);
if (AddLastUMovement) AlgTNCLL[sp][n].Append(LastUStep);
}
}
const std::chrono::duration<double> TNCLL_elapsed_seconds = std::chrono::system_clock::now() - time_TNCLL_start;
TimeTNCLL = TNCLL_elapsed_seconds.count();
}
// Solve the cube by solving the last 5 edges
void Nautilus::SearchL5E(const Plc Pol)
{
const auto time_l5e_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgL5E[sp].clear();
CasesL5E[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgL5E[sp].push_back(Algorithm(""));
CasesL5E[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgdFR[sp][n];
if (!AlgNCLL[sp].empty()) Alg += AlgNCLL[sp][n];
else if (!AlgNCOLL[sp].empty()) Alg += AlgNCOLL[sp][n];
else if (!AlgTNCLL[sp].empty()) Alg += AlgTNCLL[sp][n];
Cube CubeL5E = CubeBase;
CubeL5E.ApplyAlgorithm(Alg);
if (!IsNautilusNCLLBuilt(CubeL5E, spin)) continue;
bool Found = false;
for (uint Index = 0u; Index < Algset_L5E.GetCasesNumber(); Index++)
{
const Algorithm A = Algset_L5E.GetAlgorithm(Index, Pol, Metric);
for (const auto U1Mov : Algorithm::UMovs) // U movement before algorithm
{
for (const auto U2Mov : Algorithm::UMovs) // U movement after algorithm
{
Cube CubeNautilus = CubeL5E;
if (U1Mov != Stp::NONE) CubeNautilus.ApplyStep(U1Mov);
CubeNautilus.ApplyAlgorithm(A);
if (U2Mov != Stp::NONE) CubeNautilus.ApplyStep(U2Mov);
if (CubeNautilus.IsSolved())
{
Found = true;
CasesL5E[sp][n] = Algset_L5E.GetCaseName(Index);
if (U1Mov != Stp::NONE)
{
AlgL5E[sp][n].Append(Stp::PARENTHESIS_OPEN);
AlgL5E[sp][n].Append(U1Mov);
AlgL5E[sp][n].Append(Stp::PARENTHESIS_CLOSE_1_REP);
}
AlgL5E[sp][n].Append(A);
if (U2Mov != Stp::NONE)
{
AlgL5E[sp][n].Append(Stp::PARENTHESIS_OPEN);
AlgL5E[sp][n].Append(U2Mov);
AlgL5E[sp][n].Append(Stp::PARENTHESIS_CLOSE_1_REP);
}
break;
}
}
if (Found) break; // Release for loop
}
if (Found) break; // Release for loop
}
}
}
const std::chrono::duration<double> l5e_elapsed_seconds = std::chrono::system_clock::now() - time_l5e_start;
TimeL5E = l5e_elapsed_seconds.count();
}
// Orient the remaining six edges while placing the DF edge
void Nautilus::SearchEODF(const Plc Pol)
{
const auto time_eodf_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgEODF[sp].clear();
CasesEODF[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgEODF[sp].push_back(Algorithm(""));
CasesEODF[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Cube CubeEODF = CubeBase;
CubeEODF.ApplyAlgorithm(Alg);
if (!IsNautilusSBBuilt(CubeEODF, spin)) continue;
bool Found = false;
for (uint Index = 0u; Index < Algset_EODF.GetCasesNumber(); Index++)
{
const Algorithm A = Algset_EODF.GetAlgorithm(Index, Pol, Metric);
for (const auto UMov : Algorithm::UMovs) // U movement before algorithm
{
Cube CubeNautilus = CubeEODF;
if (UMov != Stp::NONE) CubeNautilus.ApplyStep(UMov);
CubeNautilus.ApplyAlgorithm(A);
if (IsNautilusEODFBuilt(CubeNautilus, spin))
{
Found = true;
CasesEODF[sp][n] = Algset_EODF.GetCaseName(Index);
if (UMov != Stp::NONE)
{
AlgEODF[sp][n].Append(Stp::PARENTHESIS_OPEN);
AlgEODF[sp][n].Append(UMov);
AlgEODF[sp][n].Append(Stp::PARENTHESIS_CLOSE_1_REP);
}
AlgEODF[sp][n].Append(A);
break;
}
}
if (Found) break; // Release for loop
}
}
}
const std::chrono::duration<double> eodf_elapsed_seconds = std::chrono::system_clock::now() - time_eodf_start;
TimeEODF = eodf_elapsed_seconds.count();
}
// Solve the last F2L pair (complete the two first layers)
void Nautilus::SearchF2L()
{
const auto time_F2L_start = std::chrono::system_clock::now();
bool Skip = false; // Skip the search (for multi threading)
MaxDepthF2L = 12u;
const SearchUnit U_Root(SequenceTypes::DOUBLE, Sst::SINGLE_UR);
const SearchUnit U_UR(SequenceTypes::SINGLE, Sst::SINGLE_UR);
SearchLevel L_Root(SearchCheck::NO_CHECK);
L_Root.Add(U_Root);
SearchLevel L_Check(SearchCheck::CHECK);
L_Check.Add(U_UR);
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
const Lyr DownLayer = Cube::GetDownSliceLayer(spin);
const Lyr MiddleLayer = Cube::AdjacentLayer(DownLayer);
Pgr LDOWN, LMID, CUP;
switch (DownLayer)
{
case Lyr::U: LDOWN = Pgr::LAYER_U; LMID = Pgr::LAYER_E; CUP = Pgr::CROSS_D; break;
case Lyr::D: LDOWN = Pgr::LAYER_D; LMID = Pgr::LAYER_E; CUP = Pgr::CROSS_U; break;
case Lyr::F: LDOWN = Pgr::LAYER_F; LMID = Pgr::LAYER_S; CUP = Pgr::CROSS_B; break;
case Lyr::B: LDOWN = Pgr::LAYER_B; LMID = Pgr::LAYER_S; CUP = Pgr::CROSS_F; break;
case Lyr::R: LDOWN = Pgr::LAYER_R; LMID = Pgr::LAYER_M; CUP = Pgr::CROSS_L; break;
case Lyr::L: LDOWN = Pgr::LAYER_L; LMID = Pgr::LAYER_M; CUP = Pgr::CROSS_R; break;
default: continue; // Should not happend
}
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgF2L[sp].push_back(Algorithm(""));
if (Skip) continue;
Algorithm AlgStart = Scramble;
AlgStart.Append(Inspections[sp][n]);
AlgStart.Append(AlgFB[sp][n]);
AlgStart.Append(AlgSB[sp][n]);
AlgStart.Append(AlgEODF[sp][n]);
const Cube C(AlgStart);
if (C.CheckOrientation(Pgr::ALL_EDGES) && C.IsSolved(DownLayer) && C.IsSolved(MiddleLayer)) continue; // F2L already solved
// Deep search for F2L
DS.Clear();
DS.SetScramble(AlgStart);
DS.SetShortPolicy();
DS.AddToMandatoryPieces(LDOWN);
DS.AddToMandatoryPieces(LMID);
DS.AddToMandatoryOrientations(CUP);
DS.AddSearchLevel(L_Root);
for (uint l = 2u; l < MaxDepthF2L; l++) DS.AddSearchLevel(L_Check); // Add needed search levels
DS.UpdateRootData();
DS.Run(Cores);
Skip = DS.CheckSkipSearch();
DS.EvaluateShortestResult(AlgF2L[sp][n], true);
}
}
const std::chrono::duration<double> F2L_elapsed_seconds = std::chrono::system_clock::now() - time_F2L_start;
TimeF2L = F2L_elapsed_seconds.count();
}
// ZBLL search to complete the last layer
void Nautilus::SearchZBLL(const Plc Pol)
{
const auto time_ZBLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgZBLL[sp].clear();
CasesZBLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgZBLL[sp].push_back(Algorithm(""));
CasesZBLL[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgEODF[sp][n];
Alg += AlgF2L[sp][n];
Cube CubeZBLL = CubeBase;
CubeZBLL.ApplyAlgorithm(Alg);
Stp AUFStep;
SolveLL(AlgZBLL[sp][n], CasesZBLL[sp][n], AUFStep, Algset_ZBLL, Pol, Metric, CubeZBLL);
AlgZBLL[sp][n].Append(AUFStep);
}
}
const std::chrono::duration<double> ZBLL_elapsed_seconds = std::chrono::system_clock::now() - time_ZBLL_start;
TimeZBLL = ZBLL_elapsed_seconds.count();
}
// OCLL search
void Nautilus::SearchOCLL(const Plc Pol)
{
const auto time_OCLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgOCLL[sp].clear();
CasesOCLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgOCLL[sp].push_back(Algorithm(""));
CasesOCLL[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgEODF[sp][n];
Alg += AlgF2L[sp][n];
Cube CubeOCLL = CubeBase;
CubeOCLL.ApplyAlgorithm(Alg);
OrientateLL(AlgOCLL[sp][n], CasesOCLL[sp][n], Algset_OCLL, Pol, Metric, CubeOCLL);
}
}
const std::chrono::duration<double> OCLL_elapsed_seconds = std::chrono::system_clock::now() - time_OCLL_start;
TimeOCLL = OCLL_elapsed_seconds.count();
}
// PLL search
void Nautilus::SearchPLL(const Plc Pol)
{
const auto time_PLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgPLL[sp].clear();
CasesPLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgPLL[sp].push_back(Algorithm(""));
CasesPLL[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgEODF[sp][n];
Alg += AlgF2L[sp][n];
Alg += AlgOCLL[sp][n];
Cube CubeOCLL = CubeBase;
CubeOCLL.ApplyAlgorithm(Alg);
Stp AUFStep;
SolveLL(AlgPLL[sp][n], CasesPLL[sp][n], AUFStep, Algset_PLL, Pol, Metric, CubeOCLL);
AlgPLL[sp][n].Append(AUFStep);
}
}
const std::chrono::duration<double> PLL_elapsed_seconds = std::chrono::system_clock::now() - time_PLL_start;
TimePLL = PLL_elapsed_seconds.count();
}
// COLL search
void Nautilus::SearchCOLL(const Plc Pol)
{
const auto time_COLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgCOLL[sp].clear();
CasesCOLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgCOLL[sp].push_back(Algorithm(""));
CasesCOLL[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgEODF[sp][n];
Alg += AlgF2L[sp][n];
Cube CubeCOLL = CubeBase;
CubeCOLL.ApplyAlgorithm(Alg);
Stp LastStep;
CornersLL(AlgCOLL[sp][n], CasesCOLL[sp][n], LastStep, Algset_COLL, Pol, Metric, CubeCOLL);
AlgCOLL[sp][n].Append(LastStep);
}
}
const std::chrono::duration<double> COLL_elapsed_seconds = std::chrono::system_clock::now() - time_COLL_start;
TimeCOLL = COLL_elapsed_seconds.count();
}
// EPLL search
void Nautilus::SearchEPLL(const Plc Pol)
{
const auto time_EPLL_start = std::chrono::system_clock::now();
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
AlgEPLL[sp].clear();
CasesEPLL[sp].clear();
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
AlgEPLL[sp].push_back(Algorithm(""));
CasesEPLL[sp].push_back("");
Algorithm Alg = Inspections[sp][n];
Alg += AlgFB[sp][n];
Alg += AlgSB[sp][n];
Alg += AlgEODF[sp][n];
Alg += AlgF2L[sp][n];
Alg += AlgCOLL[sp][n];
Cube CubeCOLL = CubeBase;
CubeCOLL.ApplyAlgorithm(Alg);
Stp AUFStep;
SolveLL(AlgEPLL[sp][n], CasesEPLL[sp][n], AUFStep, Algset_EPLL, Pol, Metric, CubeCOLL);
AlgEPLL[sp][n].Append(AUFStep);
}
}
const std::chrono::duration<double> EPLL_elapsed_seconds = std::chrono::system_clock::now() - time_EPLL_start;
TimeEPLL = EPLL_elapsed_seconds.count();
}
// Set regrips
void Nautilus::SetRegrips()
{
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
if (!CheckSolveConsistency(spin)) continue;
for (uint n = 0u; n < AlgFB[sp].size(); n++)
{
AlgFB[sp][n] = AlgFB[sp][n].GetRegrip();
if (Algorithm::IsTurn(AlgFB[sp][n].First()))
{
Inspections[sp][n].AppendShrink(AlgFB[sp][n].First());
if (Inspections[sp][n].GetSize() == 3u) Inspections[sp][n] = Inspections[sp][n].GetCancellations();
AlgFB[sp][n].EraseFirst();
}
}
}
}
// Get a solve report
std::string Nautilus::GetReport(const bool cancellations, bool debug) const
{
std::string Report, ReportLine;
// Report = "Nautilus: Scramble [" + std::to_string(Scramble.GetNumSteps()) + "] " + GetTextScramble();
// Report += "\n--------------------------------------------------------------------------------\n";
for (const auto spin : SearchSpins)
{
int sp = static_cast<int>(spin);
if (!CheckSolveConsistency(spin)) continue;
for (uint n = 0u; n < Inspections[sp].size(); n++)
{
ReportLine.clear();
Cube C = CubeBase;
C.ApplyAlgorithm(Inspections[sp][n]);
C.ApplyAlgorithm(AlgFB[sp][n]);
if (IsRouxFBBuilt(C))
{
ReportLine += "[" + Cube::GetSpinText(spin) + "|" + Algorithm::GetMetricValue(GetMetricSolve(spin, n));
if (cancellations) ReportLine += "(" + Algorithm::GetMetricValue(GetMetricCancellations(spin, n)) + ")";
ReportLine += " " + Algorithm::GetMetricString(Metric) + "]: ";
if (!Inspections[sp][n].Empty()) ReportLine += "(" + Inspections[sp][n].ToString() + ") ";
ReportLine += "(" + AlgFB[sp][n].ToString() + ")";
}
else
{
if (debug)
{
ReportLine += "[" + Cube::GetSpinText(spin) + "]: ";
if (!Inspections[sp][n].Empty()) ReportLine += "(" + Inspections[sp][n].ToString() + ") ";
ReportLine += " First block not built in " + std::to_string(MaxDepthFB) + " steps";
if (!AlgFB[sp][n].Empty()) ReportLine += ": (" + AlgFB[sp][n].ToString() + ")\n";
else ReportLine.push_back('\n');
}
if (debug) Report += ReportLine;
continue;
}
C.ApplyAlgorithm(AlgSB[sp][n]);
if (IsNautilusSBBuilt(C))
{
ReportLine += " (" + AlgSB[sp][n].ToString() + ")";
}
else
{
ReportLine += " Second block not built in " + std::to_string(MaxDepthSB) + " steps";
if (!AlgSB[sp][n].Empty()) ReportLine += ": (" + AlgSB[sp][n].ToString() + ")\n";
else ReportLine.push_back('\n');
if (debug) Report += ReportLine;
continue;
}
if (!AlgL5E[sp].empty()) // L5E variant
{
C.ApplyAlgorithm(AlgdFR[sp][n]);
if (IsNautilusSBBuilt(C) && (IsF2LPairsBuilt(C) || !AlgTNCLL[sp].empty()))
{
ReportLine += " (" + AlgdFR[sp][n].ToString() + ")";
}
else
{
ReportLine += " dFR pair not built in " + std::to_string(MaxDepthdFR) + " steps";
if (!AlgdFR[sp][n].Empty()) ReportLine += ": (" + AlgdFR[sp][n].ToString() + ")\n";