forked from hkociemba/CubeExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CordCube.pas
3790 lines (3440 loc) · 122 KB
/
CordCube.pas
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
unit CordCube;
interface
uses CubiCube, CubeDefs, graphics;
//+++++++++++++++++Extract pruning value from Pruning Tables++++++++++++++++++++
function GetPruningP(index:Integer):Integer;
{$IF not QTM}
function GetPruningPhase2P(index: Integer): Integer;
{$IFEND}
function GetPruningBigP(index: LongWord):Integer;
function GetPruningCentP(index: LongWord):Integer;
function GetPruningUBigP(index: LongWord;p:Pointer):Integer;
function GetPruningFullCorner(index: Integer):Integer;
{$IF FULLPHASE2}
function GetPruningFullPhase2(index:LongWord;slice:Integer):Integer;
{$IFEND}
//++++++++++++++++Find the Phase2 initial pruning value+++++++++++++++++++++++++
{$IF not QTM}
function GetPrunPhase2(cPos,e8Pos:Integer):Integer;
{$IFEND}
//+++++++++++Initial values for the incomplete Solver ++++++++++++++++++++++++
function GetPrunFullCorner(cPos,cOri:Integer):Integer;
//Create table used to extract phase 2 edge permutation coordinate from+++++++++
//RLSliceSorted and FBSliceSorted coordinates+++++++++++++++++++++++++++++++++++
procedure CreateGetEdge8PermTable;
//+++++++++++++++++++++Tables for the Huge Optimal Solver+++++++++++++++++++++++
procedure CreateBigPruningTable;
procedure CreateUltraBigPruningTable;
{$IF FULLPHASE2}
procedure CreateFullPhase2PruningTable;
{$IFEND}
procedure CreateFlipConjugateTable;
procedure CreateGetCorn8PermTable;//für den Coset-Explorer
procedure CreateFlipUDSliceCentPruningTable;
procedure CreateCenTwistUDSliceSortedPruningTable;
procedure CreateFullCornerPruningTable(useSlice:Boolean);
type
SymCoord= record n: Integer; s: Integer; end;//the parts of a sym-coordinate
//n is the class index, s the symmetry index
//++++++++++++++++Class for the cubes on the Coordinate Level+++++++++++++++++++
CoordCube = class
public
//+++++++++++++++First phase and Optimal Solver coordinates+++++++++++++++++
flipUDSlice,flipRLSlice,flipFBSlice: SymCoord;
UDTwist,RLTwist,FBTwist: Word;//corner orientation coordinates
UDTetra,RLTetra,FBTetra: Word;//Tetra coordinate, used in ultrabig solver
//++++++++++++++++++Second phase coordinates++++++++++++++++++++++++++++++++
UDSliceSorted,RLSliceSorted,FBSliceSorted,cornPos: Word;
edge8Pos: Word;
//+++++++++++++++++++Big Optimal Solver coordinates+++++++++++++++++++++++++
UDSliceSortedSym,RLSliceSortedSym,FBSliceSortedSym: SymCoord;
UDFlip,RLFlip,FBFlip: Word;
//+++++++++++++++++++Parity used only in QTM++++++++++++++++++++++++++++++++
parityEven: Boolean;
//+++++++++++++++++++Symmetries of this Cube++++++++++++++++++++++++++++++++
sym: Int64; //bit n = 1: has symmetry n (0<=n<=47)
//+++++++++++++++++++Twist of the centers+++++++++++++++++++++++++++++++++++
UDCenTwist,RLCenTwist,FBCenTwist: Word;
// UDSlice, RLSlice, FBSlice: Word;//also needed for oriented Cubes WIEDER ENTFERNEN !!!!!!!!!!!!!!!!!!!!!!!
UDCentRFLBMod2Twist,RLCentRFLBMod2Twist,FBCentRFLBMod2Twist:Word;
isOriented: Boolean;//Center orientation included?
//++++++++++++++Routines used only for debugging++++++++++++++++++++++++++++
procedure DoMove(m: Move);
procedure DoMovePhase2(m: Move);
procedure Print(c:TCanvas;x,y:Longint);
//+++++Find the Phase 1 and Big Optimals Solver initial pruning value+++++++
function GetPrun(direction:Integer):Integer;
function GetCentPrun(direction:Integer):Integer;
function GetPrunBig(direction: Integer):Integer;
function GetPrunUBig(direction: Integer):Integer;
//+++++++++++++++++++++++++++++++++constructors+++++++++++++++++++++++++++++
constructor Create; overload;
constructor Create(cc: CubieCube); overload;
end;
//++++++++++++End Class for the cubes on the Coordinate Level+++++++++++++++++++
//++++++++++++++Arrays for the Move Tables++++++++++++++++++++++++++++++++++++++
var TwistMove: array[0..2187-1,Ux1..Fsx3] of Word;//auf slice moves erweitert
FlipMove: array[0..2048-1,Ux1..Fsx3] of Word;
UDSliceMove: array[0..495-1,Ux1..Fsx3] of Word;
CentOriMove: array[0..4096-1,Ux1..Fsx3] of Word;//auf slice moves erweitert
CentOriRFLBMod2Move: array[0..16-1,Ux1..Fsx3] of Word;
TetraMove: array[0..70-1,Ux1..Fsx3] of Word;
CornPermMove: array[0..40320-1,Ux1..Fsx3] of Word;//auf slice moves erweitert
UDSliceSortedMove: array[0..11880-1,Ux1..Fsx3] of Word;
UDSliceSortedSymMove: array[0..788-1,Ux1..Fsx3] of Integer;
Edge8PermMove: array[0..40320-1,Ux1..Fsx3] of Word;
FlipSliceMove: array of array{[0..64430-1,Ux1..Fsx3]} of Integer;//dynamic creation
//++++++++++++++++Arrays for the Conjugation by symmetries++++++++++++++++++++++
TwistConjugate: array[0..2187-1,0..15] of Word;
TetraConjugate: array[0..70-1,0..15] of Word;
FlipConjugate: array of array of array {[0..2048-1,0..15,0..788-1]}of Word;
Edge8PosConjugate: array[0..40320-1,0..15] of Word;
CornPermConjugate: array[0..40320-1,0..15] of Word;
UDSliceSortedConjugate: array[0..24-1,0..15] of Word;//eingeschränkt auf phase2!
CentOriRFLBMod2Conjugate: array[0..16-1,0..15] of Word;
// UDSliceConjugate: array[0..495-1,0..15] of Word;
// ++++++Array for the computation of the phase 2 edge coordinate+++++++++++++++
GetEdge8Perm: array[0..11880-1,0..24-1] of Word;
//+++++++++++++++++++++++Pruning Table arrays+++++++++++++++++++++++++++++++++++
Pruning: array {*[0..64430*2187 div 16+1]*} of Integer;//phase 1/optimal unpacked
PruningP: array {*[0..64430*2187 div 5]*} of Byte;//phase 1/optimal packed
PruningCent: array {*[0..64430*2187*16 div 16]*} of Integer;//oriented phase 1/optimal unpacked
PruningCentP: array {*[0..64430*2187*16 div 5]*} of Byte;//oriented phase 1/optimal packed
PruningFullCorner: array {*[0..2768*2187 div 16+1]*} of Integer;//Die kompletten Ecken
{$IF not QTM}
PruningPhase2: array {*[0..2768*40320 div 16+1]*} of Integer;//phase 2
PruningPhase2P: array {*[0..2768*40320 div 5]*} of Byte;
{$ELSE}
PruningPhase2Q: array {*[0..2768*40320-1]*} of Byte;//phase 2 in QTM
depthmod2Remain: array(*[0..2768-1]*) of Byte;
{$IFEND}
PruningBig: array {*[0..788*2187*2048 div 16+1]*} of Integer;//big optima solver
PruningBigP: array {*[0..788*2187*2048 div 5+1]*} of Byte;
PruningCornPermPh2: array[0..40320-1] of Byte;//for pre-check in phase 2
PruningUBig: array[0..70-1] of array of Integer;
PruningUBigP: array[0..70-1] of array of Byte;
PruningCenTwistUDSliceSorted: array {[0..11880*4096-1]} of Byte;
{$IF FULLPHASE2}
PruningFullPhase2: array[0..24-1] of array of Byte;
{$IFEND}
//+++++++GetPacked[i,j] extracts value for entry j from byte value i++++++++++++
GetPacked: array [0..243-1,0..4] of Byte;
//++++++++++++++++++++++++++Für den Coset-Explorer++++++++++++++++++++++++++++++
BitVector: array {[0..24*40320*288/32-1]} of Integer;//für den Bitvektor 24*40320*288
BitVectorPS: array {[0..24*40320*288/32-1]} of Integer;//für den Bitvektor 24*40320*288
GetCorn8Perm: array[0..40320-1] of Word;//Eckenpermutationen in den Tetraedern
//++++++++++++++++++++++++++Für phase 2 bei orientierten Cubes++++++++++++++++++
UDSliceParity: array [0..24-1] of Byte;
RFLBCentOriParity: array [0..4096-1] of Byte;
//+++++++++++++++++++++++++++Table Generation Routines++++++++++++++++++++++++++
procedure CreateMoveTables;
procedure CreatePruningTables;
procedure CreateConjugateTables;
procedure CreateUDSliceSortedSymMoveTable;
procedure CreateGetPackedTable;
implementation
uses Symmetries, classes, SysUtils, RubikMain, Forms,Windows,OptOptions, FaceCube; /////////FaceCube wieder rausnehmen!!!!!!!!
//+++++++++++++++++++++++++++Default Constructor++++++++++++++++++++++++++++++++
constructor CoordCube.Create;
begin
flipUDSlice.n:=0;flipRLSlice.n:=0;flipFBSlice.n:=0;
flipUDSlice.s:=0;flipRLSlice.s:=0;flipFBSlice.s:=0;
UDTwist:=0;RLTwist:=0;FBTwist:=0;
UDTetra:=0;RLTetra:=0;FBTetra:=0;
UDSliceSorted:=0;RLSliceSorted:=0;FBSliceSorted:=0;cornPos:=0;
edge8Pos:= 0;
UDSliceSortedSym.n:=0;RLSliceSortedSym.n:=0;FBSliceSortedSym.n:=0;
UDSliceSortedSym.s:=0;RLSliceSortedSym.s:=0;FBSliceSortedSym.s:=0;
parityEven:=true;
sym:=1;//Identity :=0;
UDCenTwist:=0;RLCenTwist:=0;FBCenTwist:=0; //needed for oriented Cubes
UDCentRFLBMod2Twist:=0;RLCentRFLBMod2Twist:=0;FBCentRFLBMod2Twist:=0;
isOriented:= false;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++Create CoordCube from CubieCube++++++++++++++++++++++++++++
constructor CoordCube.Create(cc:CubieCube);
var prodC: CornerCubie; prodE: EdgeCubie; prodCn: CenterCubie;
s: Integer; hasSym:Boolean;
c1:Corner; e1:Edge; cn1: TurnAxis;
begin
//++++++++++++++++++++++++Initialize the symmetry+++++++++++++++++++++++++++++
sym:=0;
isOriented:= cc.isOriented;
for s:= 0 to 47 do
begin
hasSym:=true; //dies muss jetzt widerlegt werden!
CornMult(CornSym[s],cc.PCorn^,cc.PCornTemp^);
CornMult(cc.PCornTemp^,CornSym[InvIdx[s]],prodC);
EdgeMult(EdgeSym[s],cc.PEdge^,cc.PEdgeTemp^);
EdgeMult(cc.PEdgeTemp^,EdgeSym[InvIdx[s]],prodE);
if isOriented then
begin
CentMult(CentSym[s],cc.PCent^,cc.PCentTemp^);
CentMult(cc.PCentTemp^,CentSym[InvIdx[s]],prodCn);
end;
for c1:= URF to DRB do
if (prodC[c1].c<>cc.PCorn^[c1].c) or (ProdC[c1].o<>cc.PCorn^[c1].o) then
begin
hasSym:=false;
break;
end;
for e1:= UR to BR do
begin
if not hasSym then break;
if (prodE[e1].e<>cc.PEdge^[e1].e) or (prodE[e1].o<>cc.PEdge^[e1].o) then
begin
hasSym:=false;
break;
end;
end;
if isOriented then
for cn1:= U to B do//nur wenn
begin
if not hasSym then break;
if (prodCn[cn1].c<>cc.PCent^[cn1].c) or (prodCn[cn1].o<>cc.PCent^[cn1].o) then
begin
hasSym:=false;
break;
end;
end;
if hasSym then sym:= sym or ( Int64(1) shl s);
end;
//++++++++++++++++++++Initialize the coordinates++++++++++++++++++++++++++++++
cornPos:= cc.CornPermCoord;
UDTwist:= cc.CornOriCoord;
UDFlip:= cc.EdgeOriCoord;
UDTetra:= cc.TetraCoord;
UDSliceSorted:= cc.UDSliceSortedCoord;
UDCenTwist:= cc.CentOriCoord;
UDCentRFLBMod2Twist:=cc.CentOriRFLBMod2Coord;
flipUDSlice.n:= cc.FlipUDSliceCoord;
flipUDSlice.s:= flipUDSlice.n and 15;
flipUDSlice.n:=flipUDSlice.n shr 4;
UDSliceSortedSym.n:= cc.UDSliceSortedSymCoord;
UDSliceSortedSym.s:= UDSliceSortedSym.n and 15;
UDSliceSortedSym.n:=UDSliceSortedSym.n shr 4;
EdgeMult(EdgeSym[16],cc.PEdge^,prodE); //Apply S_URF3*X*S_URF3^-1 to edges
EdgeMult(prodE,EdgeSym[InvIdx[16]],cc.PEdge^);
CornMult(CornSym[16],cc.PCorn^,prodC); //Apply S_URF3*X*S_URF3^-1 to corners
CornMult(prodC,CornSym[InvIdx[16]],cc.PCorn^);
CentMult(CentSym[16],cc.PCent^,prodCn); //Apply S_URF3*X*S_URF3^-1 to centers
CentMult(prodCn,CentSym[InvIdx[16]],cc.PCent^);
RLTwist:= cc.CornOriCoord;
RLFlip:= cc.EdgeOriCoord;
RLTetra:= cc.TetraCoord;
RLSliceSorted:= cc.UDSliceSortedCoord;
RLCenTwist:= cc.CentOriCoord;
RLCentRFLBMod2Twist:=cc.CentOriRFLBMod2Coord;
flipRLSlice.n:= cc.FlipUDSliceCoord;
flipRLSlice.s:= flipRLSlice.n and 15;
flipRLSlice.n:= flipRLSlice.n shr 4;
RLSliceSortedSym.n:= cc.UDSliceSortedSymCoord;
RLSliceSortedSym.s:= RLSliceSortedSym.n and 15;
RLSliceSortedSym.n:=RLSliceSortedSym.n shr 4;
EdgeMult(EdgeSym[16],cc.PEdge^,prodE);
EdgeMult(prodE,EdgeSym[InvIdx[16]],cc.PEdge^);
CornMult(CornSym[16],cc.PCorn^,prodC);
CornMult(prodC,CornSym[InvIdx[16]],cc.PCorn^);
CentMult(CentSym[16],cc.PCent^,prodCn);
CentMult(prodCn,CentSym[InvIdx[16]],cc.PCent^);
FBTwist:= cc.CornOriCoord;
FBFlip:= cc.EdgeOriCoord;
FBTetra:= cc.TetraCoord;
FBSliceSorted:= cc.UDSliceSortedCoord;
FBCenTwist:= cc.CentOriCoord;
FBCentRFLBMod2Twist:=cc.CentOriRFLBMod2Coord;
edge8Pos:= GetEdge8Perm[RLSliceSorted,FBSliceSorted mod 24];
//correct only if cube is in phase2
flipFBSlice.n:= cc.FlipUDSliceCoord;
flipFBSlice.s:= flipFBSlice.n and 15;
flipFBSlice.n:= flipFBSlice.n shr 4;
FBSliceSortedSym.n:= cc.UDSliceSortedSymCoord;
FBSliceSortedSym.s:= FBSliceSortedSym.n and 15;
FBSliceSortedSym.n:= FBSliceSortedSym.n shr 4;
EdgeMult(EdgeSym[16],cc.PEdge^,prodE); //restore cc
EdgeMult(prodE,EdgeSym[InvIdx[16]],cc.PEdge^);
CornMult(CornSym[16],cc.PCorn^,prodC);
CornMult(prodC,CornSym[InvIdx[16]],cc.PCorn^);
CentMult(CentSym[16],cc.PCent^,prodCn);
CentMult(prodCn,CentSym[InvIdx[16]],cc.PCent^);
parityEven:= cc.CornParityEven;
end;
//++++++++++++++++End Create CoordCube from CubieCube+++++++++++++++++++++++++++
procedure CreateCentOriRFLBMod2MoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 16-1 do
begin
c.InvCentOriRFLBMod2Coord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then CentOriRFLBMod2Move[i,Move(3*Ord(j)+k)]:=c.CentOriRFLBMod2Coord;
end;
end;
end;
c.Free;
end;
procedure CreateRFLBCentOriParityTable;
var c: CubieCube; i: Integer;
begin
c:= CubieCube.Create;
for i:= 0 to 4096-1 do
begin
c.InvCentOriCoord(i);
if c.RFLBCentOriParityEven
then RFLBCentOriParity[i]:=0
else RFLBCentOriParity[i]:=1;
end;
c.Free;
end;
procedure CreateUDSliceParityTable;
var c: CubieCube; i: Integer;
begin
c:= CubieCube.Create;
for i:= 0 to 24-1 do
begin
c.InvUDSliceSortedCoord(i);
if c.UDSliceParityEven
then UDSliceParity[i]:=0
else UDSliceParity[i]:=1;
end;
c.Free;
end;
//++++++++++++++Create Move Table for the centers+++++++++++++++++++++++++++++++
procedure CreateCentOriMoveTable;
var c: CubieCube; i,k: Integer; j,j1: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 4096-1 do
begin
if i and $fff =0 then Application.ProcessMessages;
c.InvCentOriCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then CentOriMove[i,Move(3*Ord(j)+k)]:=c.CentOriCoord;
end;
end;
end;
c.Free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++Create Move Table for the UDSliceCoord+++++++++++++++++++++++++++++++
procedure CreateUDSliceMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 495-1 do
begin
c.InvUDSliceCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then UDSliceMove[i,Move(3*Ord(j)+k)]:=c.UDSliceCoord;
end;
end;
end;
c.Free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++Create Move Table for the corner orientations+++++++++++++++++++
procedure CreateTwistMoveTable;
var c: CubieCube; i,k: Integer; j,j1: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 2187-1 do
begin
if i and $fff =0 then Application.ProcessMessages;
c.InvCornOriCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then TwistMove[i,Move(3*Ord(j)+k)]:=c.CornOriCoord;
end;
end;
end;
c.Free;
Form1.ProgressBar.Position:=30;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++Create Move Table for the edge orientations+++++++++++++++++++++
procedure CreateFlipMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 2048-1 do
begin
c.InvEdgeOriCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then FlipMove[i,Move(3*Ord(j)+k)]:=c.EdgeOriCoord;
end;
end;
end;
c.Free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++Create Move Table for the tetraeder coordinate+++++++++++++++++++++
procedure CreateTetraMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 70-1 do
begin
c.InvTetraCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then TetraMove[i,Move(3*Ord(j)+k)]:=c.TetraCoord;
end;
end;
end;
c.Free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Create Move Table for the Corner Permutations+++++++++++++++++
procedure CreateCornPermMoveTable;
var c: CubieCube; i,k: Integer; j,j1: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 40320-1 do
begin
if i and $fff = 0 then Application.ProcessMessages;
c.InvCornPermCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then CornPermMove[i,Move(3*Ord(j)+k)]:=c.CornPermCoord;
end;
end;
end;
c.Free;
Form1.ProgressBar.Position:=60;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++Create Move Table for the FlipUDSlice sym-coordinate++++++++++++++
procedure CreateFlipUDSliceMoveTable;
var c: CubieCube; i,k,n: Integer; j: TurnAxis;
fstr: TFileStream;
const filename = 'flipUDslice.move';
begin
SetLength(FlipSliceMove,64430,27);//27 is number of different moves
if FileExists(filename) then
begin
fstr := TFileStream.Create(filename, fmOpenRead);
for k:= 0 to 64430-1 do
begin
fstr.ReadBuffer(FlipSliceMove[k][0],27*4);
if k and $fff =0 then Application.ProcessMessages;
end;
Form1.ProgressBar.Position:=40;
end
else
begin
c:= CubieCube.Create;
Form1.SetUpProgressBar(0,64430-1,'Creating '+filename+' (6.6 MB)');
for i:=0 to 64430-1 do
begin
Form1.ProgressBar.Position:=i;
if i and $fff =0 then Application.ProcessMessages;
n:= FlipUDSliceToRawFlipUDSlice[i];
c.InvUDSliceCoord(n div 2048);
c.InvEdgeOriCoord(n mod 2048);
for j:= U to Fs do
begin
for k:= 0 to 3 do //X1,X2,X3 (and X4=ID to restore Cube)
begin
c.Move(j);
if k<>3 then FlipSliceMove[i,3*Ord(j)+k]:= c.FlipUDSliceCoord;
end;
end;
end;
fstr := TFileStream.Create(filename, fmCreate);
for k:= 0 to 64430-1 do
fstr.WriteBuffer(FlipSliceMove[k][0],27*4);
c.Free;
Form1.SetUpProgressBar(0,100,'Loading...');
end;
fstr.Free;
end;
//++++++++++End Create Move Table for the FlipUDSlice sym-coordinate++++++++++++
//+++++++++++++Create Move Table for the UDSliceSorted raw-coordinate+++++++++++
procedure CreateUDSliceSortedMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 11879 do
begin
if i and $fff = 0 then Application.ProcessMessages;
c.InvUDSliceSortedCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then UDSliceSortedMove[i,Move(3*Ord(j)+k)]:=c.UDSliceSortedCoord;
end;
end;
end;
c.Free;
Form1.ProgressBar.Position:=50;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Create Move Table for the UDSliceSorted sym-coordinate+++++++++++
//+++++++++++++++++used only in Big Optimal Solver++++++++++++++++++++++++++++++
procedure CreateUDSliceSortedSymMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 788-1 do
begin
c.InvUDSliceSortedSymCoord(i shl 4);//use the representants!!
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
if k<>3 then UDSliceSortedSymMove[i,Move(3*Ord(j)+k)]:=c.UDSliceSortedSymCoord;
end;
end;
end;
c.Free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++Create Move Table for the phase 2 edge permutation coordinate+++++++
procedure CreateEdge8PermMoveTable;
var c: CubieCube; i,k: Integer; j: TurnAxis;
begin
c:= CubieCube.Create;
for i:=0 to 40320-1 do
begin
if i and $fff = 0 then Application.ProcessMessages;
c.InvPhase2EdgePermCoord(i);
for j:= U to Fs do
begin
for k:= 0 to 3 do
begin
c.Move(j);
case j of
U,D,Us:
if k<3 then Edge8PermMove[i,Move(3*Ord(j)+k)]:=c.Phase2EdgePermCoord;
R,L,F,B,Rs,Fs:
if k=1 then Edge8PermMove[i,Move(3*Ord(j)+k)]:=c.Phase2EdgePermCoord;
end;
end;
end;
end;
c.Free;
Form1.ProgressBar.Position:=70;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Create table used to extract phase 2 edge permutation coordinate from+++++++++
//RLSliceSorted and FBSliceSorted coordinates+++++++++++++++++++++++++++++++++++
procedure CreateGetEdge8PermTable;
var i,j,x,y:Word; c:CubieCube;prodE: EdgeCubie;
begin
c:= CubieCube.Create;
for i:=0 to 11880-1 do
for j:= 0 to 24-1 do
GetEdge8Perm[i,j]:=55555;//magic number used for empty entry
for i:=0 to 40320-1 do
begin
if i and $fff =0 then Application.ProcessMessages;
c.InvPhase2EdgePermCoord(i);
EdgeMult(EdgeSym[16],c.PEdge^,prodE); //Apply S_URF3*X*S_URF3^-1 to edges
EdgeMult(prodE,EdgeSym[InvIdx[16]],c.PEdge^);
x:= c.UDSliceSortedCoord;//the RLSliceSortedCoord
EdgeMult(EdgeSym[16],c.PEdge^,prodE);
EdgeMult(prodE,EdgeSym[InvIdx[16]],c.PEdge^);//the FBSliceSortedCoord
y:= c.UDSliceSortedCoord mod 24;//do not need the positional part
Assert(GetEdge8Perm[x,y]=55555);
GetEdge8Perm[x,y]:=i;
end;
c.free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
procedure CreateGetCorn8PermTable;//falls Slicekoordinate
Type Tetra1Corner = (URF1,UFL1,URB1,UBR1);
// Tetra2Corner = (DFR1,DLF1,DBL1,DRB1);
var c:CubieCube; k,x1,x2,s: Integer; i1,j1: Tetra1Corner;
test: array[URF..DRB] of Integer; cc: Corner;
const
Tetra1ToCorner: array [URF1..UBR1] of Corner =
(URF,UFL,ULB,UBR);
begin
c:= CubieCube.Create;
for k:=0 to 40320-1 do
begin
if k and $fff =0 then Application.ProcessMessages;
c.InvCornPermCoord(k);
//testen ob die ersten vier Koordinaten überhaupt im Tetraeder liegen
for cc:= URF to DRB do test[cc]:=0;
for i1:= URF1 to UBR1 do Inc(test[c.PCorn^[Tetra1ToCorner[i1]].c]);
if test[URF]*test[UFL]*test[ULB]*test[UBR]<>1 then x1:=-1
else
begin
x1:= 0;
for i1:= UBR1 downto Succ(URF1) do
begin
s:=0;
for j1:= Pred(i1) downto URF1 do
begin
if c.PCorn^[Tetra1ToCorner[j1]].c>c.PCorn^[Tetra1ToCorner[i1]].c then Inc(s);
end;
x1:= (x1+s)*Ord(i1);
end;
end;
//ich habe ein besseres Gefühl, das auf die Position von zwei Steinen zu beziehen.
if (c.PCorn^[DFR].c=DFR) and (c.PCorn^[DLF].c=DLF) then x2:=0
else if (c.PCorn^[DFR].c=DFR) and (c.PCorn^[DBL].c=DLF) then x2:=1
else if (c.PCorn^[DFR].c=DFR) and (c.PCorn^[DRB].c=DLF) then x2:=2
else if (c.PCorn^[DLF].c=DFR) and (c.PCorn^[DFR].c=DLF) then x2:=3
else if (c.PCorn^[DLF].c=DFR) and (c.PCorn^[DBL].c=DLF) then x2:=4
else if (c.PCorn^[DLF].c=DFR) and (c.PCorn^[DRB].c=DLF) then x2:=5
else if (c.PCorn^[DBL].c=DFR) and (c.PCorn^[DFR].c=DLF) then x2:=6
else if (c.PCorn^[DBL].c=DFR) and (c.PCorn^[DLF].c=DLF) then x2:=7
else if (c.PCorn^[DBL].c=DFR) and (c.PCorn^[DRB].c=DLF) then x2:=8
else if (c.PCorn^[DRB].c=DFR) and (c.PCorn^[DFR].c=DLF) then x2:=9
else if (c.PCorn^[DRB].c=DFR) and (c.PCorn^[DLF].c=DLF) then x2:=10
else if (c.PCorn^[DRB].c=DFR) and (c.PCorn^[DBL].c=DLF) then x2:=11
else x2:=-1;
if (x1=-1) or (x2=-1) then GetCorn8Perm[k]:=288 else GetCorn8Perm[k]:=12*x1+x2;
end;
c.free;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
procedure CreateMoveTables;
begin
CreateTwistMoveTable;
CreateFlipMoveTable;
CreateTetraMoveTable;
CreateFlipUDSliceMoveTable;
CreateUDSliceSortedMoveTable;
CreateCornPermMoveTable;
CreateGetCorn8PermTable;//für Coset-Explorer
// CreateCorn8PermMoveTable; //für den Coset Explorer (Prescan)
CreateEdge8PermMoveTable;
CreateUDSliceSortedSymMoveTable;
CreateCentOriMoveTable; //needed for oriented Cubes
CreateCentOriRFLBMod2MoveTable;
CreateRFLBCentOriParityTable;
CreateUDSliceParityTable;
CreateUDSliceMoveTable;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked phase 1 pruning table++++++++++++++++++++++
procedure SetPruning(index,value:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
Pruning[base]:= Pruning[base] and mask;//zero the important bits
Pruning[base]:= Pruning[base] or value;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked phase 2 pruning table++++++++++++++++++++++
{$IF not QTM}
procedure SetPruningPhase2(index,value:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
PruningPhase2[base]:= PruningPhase2[base] and mask;//zero the important bits
PruningPhase2[base]:= PruningPhase2[base] or value;
end;
{$IFEND}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked full Corner pruning table++++++++++++++++++++++
procedure SetPruningFullCorner(index,value:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
PruningFullCorner[base]:= PruningFullCorner[base] and mask;//zero the important bits
PruningFullCorner[base]:= PruningFullCorner[base] or value;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked cent pruning table++++++++++++++++++++++++++
procedure SetPruningCent(index:LongWord;value:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
PruningCent[base]:= PruningCent[base] and mask;//zero the important bits
PruningCent[base]:= PruningCent[base] or value;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked big pruning table++++++++++++++++++++++++++
procedure SetPruningBig(index:LongWord;value:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
PruningBig[base]:= PruningBig[base] and mask;//zero the important bits
PruningBig[base]:= PruningBig[base] or value;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++Set entry in unpacked ultrabig pruning tables++++++++++++++++++++
procedure SetPruningUBig(index:LongWord;value,tetra:Integer);
var mask,base,offset: Integer;
begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
value:= value shl (offset*2);
mask:= mask shl (offset*2);
mask:= not mask;
PruningUBig[tetra][base]:= PruningUBig[tetra][base] and mask;//zero the important bits
PruningUBig[tetra][base]:= PruningUBig[tetra][base] or value;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked phase 1 pruning table+++++++++++++++++++
function GetPruning(index: Integer):Integer;
//var mask,base,offset: Integer; //Delphi version of asseembler code
{*begin
mask:=3;//00000000 00000000 00000000 00000011
base:= index shr 4;
offset:= index and $f;
mask:= mask shl (offset*2);
mask:= mask and Pruning[base];
Result:= mask shr (offset*2)
end;*}
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}
mov edx,[Pruning]
mov eax,[edx+eax*4] {Pruning[base]}
mov edx,$3;
shl edx,cl {mask shl offset*2}
and eax,edx
shr eax,cl
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in packed phase 1 pruning table+++++++++++++++++++
function GetPruningP(index: Integer):Integer;
asm
cmp eax,(64430/5)*2187*4
jae @x5
mov edx,eax
and edx,3 //offset
shr eax,2 //base
mov ecx,[PruningP]
movzx eax, BYTE PTR[ecx+eax] {eax:=Pruning[base]}
lea eax,[eax+eax*4] {multiply by 5 to find offset in GetPacked}
add eax,OFFSET GetPacked {eax:=GetPacked[Pruning[base]]}
movzx eax,BYTE PTR[eax+edx] {eax:=GetPacked[Pruning[base],offset]}
ret
@x5:
sub eax,(64430/5)*2187*4 //base, offset is 4
mov ecx,[PruningP]
movzx eax, BYTE PTR[ecx+eax]
lea eax,[eax+eax*4]
add eax,OFFSET GetPacked
movzx eax,BYTE PTR[eax+4]
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked phase 2 pruning table+++++++++++++++++++
{$IF not QTM}
function GetPruningPhase2(index: Integer):Integer;
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}
mov edx,[PruningPhase2]
mov eax,[edx+eax*4] {Pruning[base]}
mov edx,$3;
shl edx,cl {mask shl offset*2}
and eax,edx
shr eax,cl
end;
{$IFEND}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in packed phase 2 pruning table+++++++++++++++++++++
{$IF not QTM}
function GetPruningPhase2P(index: Integer):Integer;
asm
cmp eax,(40320/5)*2768*4
jae @x5
mov edx,eax
and edx,3 //offset
shr eax,2 //base
mov ecx,[PruningPhase2P]
movzx eax, BYTE PTR[ecx+eax] {eax:=Pruning[base]}
lea eax,[eax+eax*4] {multiply by 5 to find offset in GetPacked}
add eax,OFFSET GetPacked {eax:=GetPacked[Pruning[base]]}
movzx eax,BYTE PTR[eax+edx] {eax:=GetPacked[Pruning[base],offset]}
ret
@x5:
sub eax,(40320/5)*2768*4 //base, offset is 4
mov ecx,[PruningPhase2P]
movzx eax, BYTE PTR[ecx+eax]
lea eax,[eax+eax*4]
add eax,OFFSET GetPacked
movzx eax,BYTE PTR[eax+4]
end;
{$IFEND}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked fullCorner table+++++++++++++++++++
function GetPruningFullCorner(index: Integer):Integer;
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}
mov edx,[PruningFullCorner]
mov eax,[edx+eax*4] {Pruning[base]}
mov edx,$3;
shl edx,cl {mask shl offset*2}
and eax,edx
shr eax,cl
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked cent pruning table+++++++++++++++++++++++
function GetPruningCent(index: LongWord):Integer;
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}
mov edx,[PruningCent]
mov eax,[edx+eax*4] {Pruning[base]}
mov edx,$3;
shl edx,cl {mask shl offset*2}
and eax,edx
shr eax,cl
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked big pruning table+++++++++++++++++++++++
function GetPruningBig(index: LongWord):Integer;
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}
mov edx,[PruningBig]
mov eax,[edx+eax*4] {Pruning[base]}
mov edx,$3;
shl edx,cl {mask shl offset*2}
and eax,edx
shr eax,cl
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++Get entry in unpacked big pruning table+++++++++++++++++++++++
function GetPruningUBig(index: LongWord; p: Pointer):Integer;
asm
mov ecx,eax
shr eax,$4 {base}
and ecx,$f
add ecx,ecx {offset*2}