-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo_5xx_cpp.h
3007 lines (2891 loc) · 97.6 KB
/
go_5xx_cpp.h
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
#define GTEST17_ON 1
#define UALIMSIZE 20
#define GUALIMSIZE 18
#define UA32_10 0xffc00000
#define UA64_54 0x3fffffffffffff
#define TUA64_12SIZE 2000
//==============================================
#define MAXN5 51520
#define MAXN6 237770
#define G17MORESIZE 32
#include "go_17sol_tables.h"
#include "Zh1b2b.h" // brute force 2 bands
extern ZH2B_GLOBAL zh2b_g;
extern ZH2B5_GLOBAL zh2b5_g; // 2_5 digits 2 bands
extern ZH2B_1D_GLOBAL zh2b1d_g; // one digit 2 bands
extern ZH2B zh2b[40], zh2b_i, zh2b_i1;
extern ZH2B5 zh2b5[10]; // solved digit per digit
extern ZH2B_1D zh2b1d[6]; // maxi 6 guesses, one per row
extern ZHONE_GLOBAL zh1b_g;
extern ZHONE zhone[20];
extern ZHONE zhone_i;
const char * libs_c17_00_cpt2g[40] = {
"0 bands1+2 processed entries M10",//0
"1 total bands 3",//1
"2 no more ua b2 ",//2
"3 valid brute force b2 ",//3
"4 max band3 ",//4
"5 7 clues b2",//5
"6 8 clues b2 ",//6
"7 expand 7",//7
"8 final check",//8
"9 valid after final check",//9
"10 critical band3",//10
"11 not critical 1",//11
"12 not critical 234",//12
"13 not critical >4",//13
"14 using socket 3",//14
"15 entry band3 handler excluding critical+ua outfield",//15
"16 entry critical ",//16
"17 add 1 from active",//17
"18 n uas at start",//18
"19 n gua2s at start ",//19
"20 n gua3s at start ",//20
"21 n sockets2",//21
"22 n sockets1",//22
"23 max bands 3",//23
"24/4 min", "25/5 min", "26/6 min","27/7 min","28/8 min","29/9 min","30/10 min",
};
// standard first band (or unique band)
struct STD_B416 {
char band[28];
int band0[27], i416, gangster[9], map[27], dband;
uint32_t tua[100], nua;// maximum 81
uint32_t fd_sols[2][9];//start puzzle/ solution
void Initstd();
void GetBandTable(int i);
void SetGangster();
inline void GetUAs() {
nua = t16_nua[i416];
memcpy(tua, &t16_UAs[t16_indua[i416]], 4 * nua);
}
void MorphUas();
void InitC10(int i);
void InitG12(int i);
void InitBand2_3(int i16, char * ze, BANDMINLEX::PERM & p
, int iband = 1);
void PrintStatus();
};
struct STD_B1_2 :STD_B416 {
// 12 115 maximum see band 28
int index1[30][3], index2[135][3], index3[2000][2],
n5, n6, nind[3];// bitfiedl,current index 5 current index 6
//XY_EXPAND xye6[MAXN6], xye5[MAXN5];
// row solution pattern in digit
int mini_digs[9], mini_pairs[27],
revised_g[9];// after false forced in 1/2 minirows
int tv_pairs[27], nvpairs; //9 or 27 bits
void FillMiniDigsMiniPairs(STD_B1_2 & bb);
inline void InitRevisedg() {
memcpy(revised_g, gangster, sizeof gangster);
}
int ReviseG_triplet(int imini, int ip, STD_B1_2 * bb);
uint32_t GetMiniData(int index, uint32_t & bcells, STD_B1_2 *bb);
void DoExpandBand(int dband);// dband 0/27
void DebugIndex2();
void Debug_2_3();
void PrintShortStatus();
} myband1, myband2;
struct STD_B3 :STD_B416 {// data specific to bands 3
struct GUAs {
BF128 isguasocket2, isguasocket3, isguasocket4;// active i81
int triplet[9];//same gua3s
int triplet_imini[81];
int ua_pair[81], ua_triplet[81]; // storing ua bitfields
int ua2_imini[81], ua3_imini[81];
int ua2_i27[81];
}guas;
int minirows_bf[9];
int triplet_perms[9][2][3];
//BF128 tbands_UA4_6s, tbands_pairs, tbands_triplets;
//int tuas46[81];
//_______________________
void InitBand3(int i16, char * ze, BANDMINLEX::PERM & p);
int IsGua(int i81);
int IsGua3(int i81);
int GetI81_2(int bf){
for (int i = 0; i < 81; i++) if (guas.ua_pair[i] == bf) return i;
return -1;
}
int GetI81_3(int bf) {
for (int i = 0; i < 81; i++) if (guas.ua_triplet[i] == bf) return i;
return -1;
}
void PrintB3Status();
};
//================== UA collector 2 bands
struct GENUAS_B12 {// for uas collection in bands 1+2 using brute force
int dig_cells[9][9],
gangbf[9],// columns for band 3 in bit field
revised_gangbf[9],// same revised UA2s UA3s ***
mini_digs[9], mini_pairs[27], // UA2s UA3 ***
//valid_pairs, // 27 bits valid sockets UA2s ***
nfloors, limstep, map[9], cptdebug, modemore;
BF128 valid_sockets;
//=============== uas collector
int limsize, floors;
uint64_t tuaold[1000],// previous non hit uas infinal table of uas for bands 1+2
tua[TUA64_12SIZE],//
tuab1b2[200];// collecting bands uas in 2x mode
uint32_t nuaold, nua, nuab1b2,
tuamore[500];
//_______________uamore control
STD_B1_2 *ba, *bb;
int ib, digp;
uint64_t w0, ua;
//_____________________ functions collect UAs bands 1+2
int Initgen();
void BuildFloorsAndCollectOlds(int fl);
//int AddUA64(uint64_t * t, uint32_t & nt);
inline void AddUA(uint64_t v) {
ua = v; AddUA64(tua, nua, ua);
}
inline void AddUACheck(uint64_t v) {
if (nua >= TUA64_12SIZE) nua = TUA64_12SIZE - 1;
ua = v; AddUA64(tua, nua, ua);
}
void BuilOldUAs(uint32_t r0);
int CheckOld();
int CheckMain(uint64_t wua);
void CollectMore();
void CollectMoreTry6_7();
void EndCollectMoreStep();
void CollectTriplets();
void CollectMore2minirows();
//_____________________ functions collect UA2s UAs3 socket
void ProcessSocket2(int i81);
int DebugUas();
}genuasb12;
#define SIZETGUA 150
#define GUAREDSIZE 100
struct GEN_BANDES_12 {// encapsulating global data
STD_B3 bands3[290];
int modeb12, go_back, diagmore,
it16, it16_2, imin16_1, imin16_2, imin16_3;
int i1t16, i2t16, i3t16, maxnb3; // index 416 ordered in increasing size of valid clues 6
char zsol[82], rband2[28];
int grid0[82], tc[6], ntc;
int gcheck[82], ib2check, ib3check;
int skip, last;// restart point; last entry in the batch
uint64_t nb12;
BANDMINLEX::PERM t_auto_b1[108], // maxi is 107excluding start position
t_auto_b1b2[108], t_auto_b2b1[108],
pband2, pband3, pcheck2, pcheck3;
int n_auto_b1, n_auto_b1b2, n_auto_b2b1;
int cold[9], rowd[6], boxd[6], rowdb3[3], boxdb3[3]; //free digits
//_________________ gangster
int gangcols[9];// 9 bits fields band3 for each colum (see valid band2)
int gang[9][3]; // gangcols expanded (buildgang ) 3 digits
int gangb12[9]; // digit bf bands 12 per column
int *gang27; // redefines gang[9][3] as 27 integer
int gang_digits_cols[9][3];// actice cols for a given digit
//____________structs hosting the 81 GUA entries
struct SGUA2 {// 81 possible UA2 sockets
// permanent data
uint64_t tua[SIZETGUA];
int col1, col2;// columns of the socket
int i_81; // index 0_80 for this
int i9;// complementary column in minirow
int id1, id2; // index of digits in gang 27
// Current band1+2 data
int digs, dig1, dig2;// depending on gang27 status
int valid, // valid if guas
validuas,// gua2s found
used;// if needed in bands3
int gangcols[9];// revised gangster
uint32_t nua;// nua_start, nua_end;
void Debug(const char * lib);
}tsgua2[81];
struct SGUA3 {// 81 possible UA3 sockets
// permanent data
uint64_t tua[SIZETGUA];
int col1;// first columns 0-9
int i_81, imini; // index 0_80 for this
int id1, id2, id3; // index of digits in gang 27
// Current band1+2 data
int dig1, dig2, dig3;// depending on gang27 status
int valid, // valid if guas
validuas,// gua2s found
used;// if needed in bands3
uint32_t nua;// nua_start, nua_end, nua;
void Debug(const char * lib);
}tsgua3[81];
// __________________________ primary UAs tables and creation of such tables
uint64_t // tua3x[3000],// dynamic sub tables
*ptua2;// pointer to current table cycle search 2/3
uint32_t tuasb2[500], nuasb2;
uint32_t ntua2, ntua3, nua2; // nua2 for cycle search 2/3
//================== bands 3 and gangster band 3 analysis
int nband3;
int tactive2[81], nactive2, tactive3[81], nactive3;
int tcolok[2], ncolok;
int ngua6_7, c1, c2, band, floors, digp, i81;
uint64_t wua0, ua;// partial gua ua to check
uint64_t tuacheck[100], tua_for_check[500];
uint32_t uadigs_for_check[500], nua_for_check, nua_check;
//__________________________ secondary guas table
uint32_t tuar2[81][GUAREDSIZE], tuar3[81][GUAREDSIZE],
ntuar2[81], ntuar3[81];
uint32_t guar2i81[80],guar3i81[80], nguared_2, nguared_3;
BF128 forced81_2, forced81_3,final81_2,final81_3;
//============= loops control for UAs 5;6;7 digits collection (collect more=
int iband, ibox, iminirow, ibox2, iminirow2, pat1, pat2, ncells;
int tcells[6], tcols[6];
int bcols[2][9], mycols[9], myfloors;
uint64_t mybf;
//=== expand band 2 and process
int cptclues[16];
uint64_t ispot ;
//_____________ one b12 set to check
uint32_t tcluesb12[12], ncluesb3;
int ncluesb12,ntb3,nmiss;
uint32_t mini_bf1 , mini_bf2 , mini_bf3 ,pairsbf , pairs27 , mini_triplet ;
uint32_t all_used_minis, mincount;
uint32_t uasb3_1[2000], uasb3_2[500], nuasb3_1, nuasb3_2;
//================ A creating a catalogue for the 17 search
//sorted increasing number of valid bands 6 clues
GEN_BANDES_12() {
gang27 = gang[0];
InitialSockets2Setup();
InitialSockets3Setup();
}
void InitialSockets2Setup();// batch level
void InitialSockets3Setup();// batch level
void BuildGang9x3();
void Build_CheckUAs_Subsets_Table();
void Build_tuacheck(int fl);
int Have_tuacheck_subset();
void SecondSockets2Setup();// band1+2 level
void SecondSockets2MoreUAs();// band1+2 level
void GuaCollectMore();
void SecondSockets3Setup();// band1+2 level
void GuaCollect(int fl, int diag = 0);
//=================================
void GetStartB2(int i); // one of the 20 starts
void NewBand1();
int Band2Check();
int Band3Check();
void Find_band2B();
void Go_Sol_Band1();
void ExpandBand2();
void ExpandBand3();
void FinalBand2(uint32_t filter);// final for band2
void ValidInitGang();
void Find_band3B();
//====================== debugging
int DebugFreshUA(uint64_t ua);
void GUAs2_Status(int all=0) {// print reduction status
char ws[82];
cout << forced81_2.String3X(ws) << " forced 2; n81=" << nguared_2 << endl;
/*
cout << "reduction GUAs status nguas reduit=" << ntguab22 << endl;
if(all)
for (uint32_t i = 0; i < nguared_2; i++) {
cout << w.i81 << "\tnua=\t" << w.nua << endl;
//for (uint32_t j = 0; j < w.nua; j++)
// cout << Char27out(w.tua[j]) << endl;
}
if(all)
for (uint32_t i = 0; i < nguared_3; i++) {
GUA_RED & w = guared_3[i];
cout << w.i81 << "\tnua=\t" << w.nua << endl;
//for (uint32_t j = 0; j < w.nua; j++)
// cout << Char27out(w.tua[j]) << endl;
}
*/
}
void Go511();
}genb12;
void GEN_BANDES_12::InitialSockets2Setup() {//load permanent data
for (int i = 0; i < 81; i++) {// initial socket 2
SGUA2 & w = tsgua2[i];
w.i_81 = i;
register int i9 = i / 9;
int tpcol[3][2] = { {1,2},{0,2},{0,1} };
int rdcol = i9 % 3, dcol = 3 * (i9 / 3), *p = tpcol[rdcol];
w.i9 = i9;
w.col1 = dcol + p[0];
w.col2 = dcol + p[1];
int rd1 = i - 9 * w.i9;//relative d1;d2
w.id1 = rd1 / 3 + 3 * w.col1;
w.id2 = rd1 % 3 + 3 * w.col2;
if (0) {
cout << "sua2=" << w.i_81 << " i9=" << w.i9 + 1
<< " cols12 " << w.col1 + 1 << w.col2 + 1
<< " id1;id2 " << w.id1 << ";" << w.id2 << endl;
}
}
}
void GEN_BANDES_12::InitialSockets3Setup() {//load permanent data
for (int i = 0; i < 81; i++) {// initial socket 3
SGUA3 & w = tsgua3[i];
int minir(i / 27);
w.i_81 = i;
w.imini = minir;
w.col1 = 3 * minir;// minirow first column in gangster
int dp = i - 27 * minir,// the 9 perms of the gangster minirow
dg = 9 * minir;// gangster 27 start
// pointers to gangster digits
w.id1 = dp / 9;
dp -= 9 * w.id1;
w.id1 += dg;
dg += 3;// next gangster column inthe minirow
w.id2 = dp / 3;
dp -= 3 * w.id2;
w.id2 += dg;
dg += 3;// last gangster column in the minirow
w.id3 = dp + dg;
if (0) {
cout << "sua2=" << w.i_81 << " col1=" << w.col1 + 1
<< " id1;id2,id3 " << w.id1
<< ";" << w.id2 << ";" << w.id3 << endl;
}
}
}
void GEN_BANDES_12::SecondSockets2Setup() {
ntua2 = 0; nactive2 = 0;
Build_CheckUAs_Subsets_Table();
for (i81 = 0; i81 < 81; i81++) {// initial socket 2
SGUA2 & w = tsgua2[i81];
w.dig1 = gang27[w.id1];
w.dig2 = gang27[w.id2];
w.digs = (1 << w.dig1) | (1 << w.dig2);
w.valid = 0;
//skip if no band3 uses it gua2 gua4 gua6 / build guas
for (int iband3 = 0; iband3 < nband3; iband3++) {
if(bands3[iband3].IsGua(i81))// setup guas in band
w.valid=1;
}
if (!w.valid)continue;
// build revised gangster
memcpy(w.gangcols, gangb12, sizeof gangb12);
w.gangcols[w.col1] ^= w.digs;
w.gangcols[w.col2] ^= w.digs;
// find guas of the socket
zh2b_g.InitGangster(gangb12, w.gangcols);
zh2b5_g.sizef5 = GUALIMSIZE;
zh2b5_g.modevalid = 0;
w.nua = 0;
//w.nua_start = ntua2;
ptua2 = w.tua;
nua2 = 0;
//================== GUA collector 2 bands
GuaCollect(w.digs );
for (int i = 0; i < 84; i++) {// find UAs 3 digits
int fl = floors_3d[i];
if ((fl & w.digs) == w.digs) GuaCollect(fl);
}
for (int i = 0; i < 126; i++) {// find UAs 4 digits
int fl = floors_4d[i];
if ((fl & w.digs) == w.digs) GuaCollect(fl);
}
for (int i = 0; i < 126; i++) {// find UAs 5digits
int fl = 0x1ff ^ floors_4d[i];
if ((fl & w.digs) == w.digs) GuaCollect(fl);
}
SecondSockets2MoreUAs();
if (nua2) {
tactive2[nactive2++]=i81;
ntua2 += nua2;
}
w.nua = nua2;
}
}
void GEN_BANDES_12::SecondSockets3Setup() {
ntua3 = 0; nactive3 = 0;
for (int i81 = 0; i81 < 81; i81++) {// initial socket 2
SGUA3 &w = tsgua3[i81];
w.dig1 = gang27[w.id1];
w.dig2 = gang27[w.id2];
w.dig3 = gang27[w.id3];
w.valid = 0;
//skip if no band3 uses it
for (int iband3 = 0; iband3 < nband3; iband3++) {
if (bands3[iband3].IsGua3(i81))// setup guas in band
w.valid = 1;
}
if (!w.valid)continue;
// Setup the perms for gangsters in minirow
int bita = 1 << w.dig1, bitb = 1 << w.dig2, bitc = 1 << w.dig3,
digs = bita | bitb | bitc;
int triplet_perms[2][3];
int * p = triplet_perms[0];// for per abc -> bca
p[0] = bita | bitb; p[1] = bitb | bitc; p[2] = bitc | bita;
p = triplet_perms[1];// for per abc -> cab
p[0] = bita | bitc; p[1] = bitb | bita; p[2] = bitc | bitb;
ptua2 = w.tua;
nua2 = 0;
// build revised gangster
//w.gangcols[w.col2] ^= w.digs;
int tp3f[2][3] = { {1,2,0},{2,0,1} };// perms no valid digit
for (int ip = 0; ip < 2; ip++) {
// build revised gangster
int rgangcols[9];// revised gangster
memcpy(rgangcols, gangb12, sizeof gangcols);
p = triplet_perms[ip];
int c1 = w.col1, c2 = c1 + 1, c3 = c1 + 2;
rgangcols[c1] ^= p[0];
rgangcols[c2] ^= p[1];
rgangcols[c3] ^= p[2];
// find guas of the socket
zh2b_g.InitGangster(gangb12, rgangcols);
zh2b5_g.sizef5 = UALIMSIZE - 1;//; - 3;
zh2b5_g.modevalid = 0;
//w.nua_start = ntua3;
//================== GUA collector 2 bands
GuaCollect(digs);// find UAs 3 digits
for (int i = 0; i < 126; i++) {// find UAs 4 digits
int fl = floors_4d[i];
if ((fl& digs) == digs) GuaCollect(fl);
}
for (int i = 0; i < 126; i++) {// find UAs 5digits
int fl = 0x1ff ^ floors_4d[i];
if ((fl & digs) == digs) GuaCollect(fl);
}
}
if (nua2) {
tactive3[nactive3++] = i81;
ntua3 += nua2;
}
//w.nua_end = ntua3;// store the final count
w.nua = nua2;// store the final count
}
}
void GEN_BANDES_12::Build_CheckUAs_Subsets_Table() {
nua_for_check = 0;
for (uint32_t i = 0; i < genuasb12.nuab1b2; i++) {// uAs bands
register uint64_t R = genuasb12.tuab1b2[i]& BIT_SET_2X;
uint64_t cc = _popcnt64(R);
if (cc > 10) continue;// nearly no chance to be subset
tua_for_check[nua_for_check++] = R| (cc<<59);
}
for (uint32_t i = 0; i < genuasb12.nua; i++){
register uint64_t R = genuasb12.tua[i];
if ((R >> 59) > 10) continue;// nearly no chance to be subset
tua_for_check[nua_for_check++] = R;
}
// and build the digit pattern of the uas in tua_for_check
for (uint32_t i = 0; i < nua_for_check; i++) {
uint32_t digs = 0,res;
register uint64_t R = tua_for_check[i]&BIT_SET_2X;
while (bitscanforward64(res, R)) {
R ^= (uint64_t)1 << res;
int cell = From_128_To_81[res],digit=grid0[cell];
digs |= 1 << digit;
}
uadigs_for_check[i] = digs;
if (0) {
cout << Char2Xout(tua_for_check[i]) << " ua for check digs 0"
<< oct << digs << dec <<" ndigs "<<_popcnt32(digs)<< endl;
}
}
}
void GEN_BANDES_12::Build_tuacheck(int fl) {
nua_check=0;
int ndigs = 0x1ff ^ fl;
for (uint32_t i = 0; i < nua_for_check; i++) {
uint32_t digs = uadigs_for_check[i];
if (digs & ndigs) continue;
tuacheck[nua_check++]= tua_for_check[i];
}
}
int GEN_BANDES_12::Have_tuacheck_subset( ) {// ua 2x27 + 5 bit length
uint64_t * t = tuacheck;
register uint64_t ua2x = ua & BIT_SET_2X;
for (uint32_t iua = 0; iua < nua_check; iua++) {
register uint64_t R = t[iua];
R &= BIT_SET_2X;
if ((R&ua2x) == R) return 1;// we have a subset
}
return 0;
}
void GEN_BANDES_12::SecondSockets2MoreUAs() {
diagmore = 0;
SGUA2 s = tsgua2[i81];
int rx0[2], bx0[2], dx3[2];
rx0[0] = zh2b_g.fd_sols[0][s.dig1].SolRow(s.col2);
dx3[0] = genb12.grid0[9 * rx0[0] + s.col1];
rx0[1] = zh2b_g.fd_sols[0][s.dig2].SolRow(s.col1);
dx3[1] = genb12.grid0[9 * rx0[1] + s.col2];
bx0[0] = rx0[0] / 3;
bx0[1] = rx0[1] / 3;
if (bx0[0] == bx0[1]) return; // want digitsin 2 bands
if (dx3[0] == dx3[1]) return; // ua 6 cells
for (int idig = 0; idig < 2; idig++) {
int dx[2], cx[2],row,dig3;
if (idig) {
dx[0] = s.dig1; dx[1] = s.dig2;
cx[0] = s.col1; cx[1] = s.col2;
row = rx0[0]; dig3 = dx3[0];
}
else {
dx[0] = s.dig2; dx[1] = s.dig1;
cx[0] = s.col2; cx[1] = s.col1;
row = rx0[1]; dig3 = dx3[1];
}
band=row/3;
// dig3 must be possible in
if (!((1 << dig3) & s.gangcols[cx[1]])) {
//cout << " not a valid pattern dig3 col" << endl;
continue;
}
// now fill band bx[0] except the 2 cells
zh2b[0].Init_gang();
BF64 cells_to_fill;
cells_to_fill.bf.u64=BIT_SET_2X;// all cells
cells_to_fill.bf.u32[1-band] = 0;// nothing in the other band
c1 = row * 9 + s.col1;
c2 = row * 9 + s.col2;
if (row >= 3) { c1 += 5; c2 += 5; }// must be 2X mode
cells_to_fill.bf.u64 ^= (uint64_t)1 << c1;
cells_to_fill.bf.u64 ^= (uint64_t)1 << c2;
zh2b[0].Init_2digits_banda(cells_to_fill);
zh2b[0].FullUpdate();
if(diagmore)zh2b[0].ImageCandidats();
// at this point,we have only one band with a gangster
//not equal to the start and a partial GUA 2cells in the other band
//we prepare ZHONE to find partial uas in one band
uint32_t tua[300]; // supply a tua to ZHONE
zh1b_g.tua = tua;
for (int i = 0; i < 9; i++) {// load the gangster pm
zh1b_g.fd_sols[1][i] = zh2b[0].FD[i].bf.u32[1 - band];
}
STD_B416 * myb = &myband1;
if(!band) myb= &myband2; // to catch the solution
memcpy(zh1b_g.fd_sols[0], myb->fd_sols[0], sizeof zh1b_g.fd_sols[0]);
zh1b_g.band0 = myb->band0;
digp = s.digs | (1 << dig3);// must be in the floor
//============== now find more uas 6/7 digits
ngua6_7 = 6;
wua0 = ((uint64_t)1 << c1) | ((uint64_t)1 << c2);
for (int i6 = 0; i6 < 84; i6++) {
int fl3 = floors_3d[i6];// , fl6 = 0x1ff ^ fl3;
if (fl3&digp) continue;// digits must be in the multi floors
floors = 0x1ff ^ fl3;
if (diagmore)cout << "try 6 floors 0" << oct << floors << dec << endl;
GuaCollectMore();
}
ngua6_7 = 7;
for (int i7 = 0; i7 < 36; i7++) {
int fl2 = floors_2d[i7];// , fl7 = 0x1ff ^ fl2;
if (fl2&digp) continue;// digits must be in the multi floors
floors = 0x1ff ^ fl2;
if (diagmore)cout << "try 7 floors 0" << oct << floors << dec << endl;
GuaCollectMore();
}
}
}
void GEN_BANDES_12::GuaCollectMore() {
zh1b_g.nua = 0;
zhone[0].Start_nFloors(floors);
zhone[0].InitGuess();
if (diagmore > 1) zhone[0].ImageCandidats();
else zh1b_g.diag = 0;
if (ngua6_7 == 6)zhone[0].Guess6();
else zhone[0].Guess7();
if (zh1b_g.nua) {
Build_tuacheck(floors);
SGUA2 s = tsgua2[i81];
for (uint32_t i = 0; i < zh1b_g.nua; i++) {
uint32_t w = zh1b_g.tua[i]&BIT_SET_27, cc=_popcnt32(w),cell;
//cout << Char27out(w) << endl;;
if (cc < 8) continue;
if (cc < 12 && ngua6_7 == 7) continue;
if (cc > GUALIMSIZE - 2) continue;
int digpw = digp;// assigned outside the band
register uint32_t R = w;
while (bitscanforward(cell, R)) {
R ^= 1 << cell;
int dig = zh1b_g.band0[cell]; // digit changed
digpw |= 1 << dig;
}
if (_popcnt32(digpw) != ngua6_7) continue;
//cout << "valid ua to add to the table" << endl;
ua = wua0;
ua |= (uint64_t)w << 32 * (1 - band);
if (Have_tuacheck_subset()) {
//cout << Char2Xout(ua) << " ua has subset" << endl;
continue;
}
ua |= (uint64_t)(cc + 2) << 59;
if (nua2 >= SIZETGUA)nua2 = SIZETGUA - 1; // guess it will be a smaller
int ir = AddUA64(ptua2, nua2, ua);
if(ir && diagmore) cout << Char2Xout(ua) << " wua added cc=" << cc + 2 <<" nua2="<<nua2<< endl;
}
}
// try to add the ua to the file
}
void GEN_BANDES_12::GuaCollect(int fl,int diag) {//use revised gangster
uint64_t solved_cells = zh2b5_g.FindUAsInit(fl, 1);
if (!solved_cells) return;// one digit solved true
if (diag) cout << "return from zh2b5_g.FindUAsInit(fl, 1);" << endl;
zh2b5_g.CollectUas5();// collect uas for this set of floors
if (diag) cout << "zh2b5_g.CollectUas5();" << endl;
if (!zh2b5_g.nuaf5) return;
Build_tuacheck( fl);
// check subsets and add to main table
for (uint32_t i = 0; i < zh2b5_g.nuaf5; i++) {
ua = zh2b5_g.tuaf5[i].bf.u64;
//genuasb12.ua = ua;
if (diag)cout << Char2Xout(ua) << " to add if new2 nua=" << nua2 << endl;
if (Have_tuacheck_subset()) continue;// superset of a previous ua
// if (genuasb12.CheckOld()) continue;// superset of a previous ua
uint64_t cc = _popcnt64(ua&BIT_SET_2X);
ua |= cc << 59;
if (nua2 >= SIZETGUA)nua2 = SIZETGUA - 1; // guess it will be a smaller
int ir = AddUA64(ptua2, nua2,ua);
if (ir) {
if (diag)cout << Char2Xout(genuasb12.ua) <<" ir="<<ir << " added nua2="<<nua2 << endl;
}
}
}
void GEN_BANDES_12::GetStartB2(int ip) {//set rows 3_9 column 1
char const *tp[20] = {// 3 out of 6 ordered
"012345", "345012", "013245", "245013", "014235", "235014", "015234", "234015",
"023145", "145023", "024135", "135024", "025134", "134025",
"034125", "125034", "035124", "124035", "045123", "123045"
};
char tpw[7]; strcpy( tpw , tp[ip]);
for (int i = 0; i < 6; i++)boxd[i] = 0x1ff;
for (int j = 0, jc = 27; j < 6; j++, jc += 9) {
int ic = tpw[j] - '0', c0 = tc[ic], bit = 1 << c0;
grid0[jc] = c0;
zsol[jc] = c0+'1';
rowd[j] = 0x1ff ^ bit;
if (j < 3)boxd[0] ^= bit; else boxd[3] ^= bit;
}
}
uint32_t t2clues_band1[9] = {
0400000001,0200000004,02000020,
04000040,010000100,01000010,
020000200,040000400,0100000002,
};
void GEN_BANDES_12::NewBand1() {
go_back = 0;
modeb12 = 0;
myband1.Initstd();
zsol[81] = 0;
nb12 = 0;
i1t16 = 415; it16 = 28;
myband1.InitG12(28);
memcpy(grid0, myband1.band0, sizeof myband1.band0);
memcpy(gcheck, myband1.band0, sizeof myband1.band0);
strcpy(zsol, myband1.band);
n_auto_b1 = bandminlex.GetAutoMorphs(it16, t_auto_b1);
for (int i = 0; i < 9; i++) // init columns status
cold[i] = 0x1ff ^ myband1.gangster[i];
zsol[27] = 0;
cout << "i1t16=" << i1t16 << " it16=" << it16
<< " n auto morphs=" << n_auto_b1 << endl;
/*
uint32_t *tua=myband1.tua, nua=myband1.nua;// maximum 81
//myband1.PrintStatus();
int tua1[20], ntua1 = 0;
BitsInTable32(tua1, ntua1, tua[0]);// first ua
cout << " ua1 size " << ntua1 << endl;
for (int ic = 0; ic < ntua1; ic++) {
uint32_t cell = tua1[ic], bit = 1 << cell,and=BIT_SET_27;
for (uint32_t iu = 1; iu < nua; iu++) {
register uint32_t R = tua[iu];
if (R&bit) continue;
and &= R;
}
cout << Char27out(bit) << endl;
cout << Char27out(and)<< "and" << endl << endl;
if (and) cout << oct << (bit | and) << dec << endl;
}
*/
ntc = 0;
BitsInTable32(tc, ntc, cold[0]);// first col 6 digits in table
for (int ip = 0; ip < 20; ip++) {//0;ip<20 setup initial values for rows columns
GetStartB2(ip);
Find_band2B();
if (go_back)return;
}
}
void Go_c500() {// find 18 clues puzzles one band 2 clues
cout << "entry 500 18 with band 2 clues" << endl;
zh_g2.grid0=genb12.grid0;
genb12.NewBand1();
cout << "print final stats" << endl;
for (int i = 0; i < 40; i++) {
if (!p_cpt2g[i])continue;
cout << p_cpt2g[i] << "\t\t" << libs_c17_00_cpt2g[i] << endl;
}
cout << "compte clues bande 2" << endl;
for (int i = 0; i < 15; i++) if (p_cpt1g[i]) {
cout << i << "\t" << p_cpt1g[i] << endl;
}
cout << "exit" << endl;
cerr << "exit" << endl;
}
void GEN_BANDES_12::Find_band2B() {
int * zs0 = &grid0[27];
register int *crcb, bit;
int *rd = rowd, *cd = cold, *bd = boxd; // to updates rows cols boxes
char * zs = zsol;
// now loop over the 24 cells not yet assigned in the band to fill the band (use relative cell)
int ii = -1, free[24];
uint32_t d;
nextii:
ii++;
{ crcb = tgen_band_cat[ii];//cell_r_c_b 24 cells to fill
register int fr0 = cd[crcb[2]] & bd[crcb[3]], fr = rd[crcb[1]] & fr0;
if (crcb[4])if (_popcnt32(fr0) < 3) goto back; // 3 clues needed here
if (!fr)goto back;
free[ii] = fr;
}
goto next_first;
next:// erase previous fill and look for next
crcb = tgen_band_cat[ii];
d = zs0[crcb[0]];
bit = 1 << d;
rd[crcb[1]] ^= bit; cd[crcb[2]] ^= bit; bd[crcb[3]] ^= bit;
if (!free[ii])goto back;
{
next_first:
crcb = tgen_band_cat[ii];// be sure to have the good one
bitscanforward(d, free[ii]);
bit = 1 << d;
free[ii] ^= bit;
zs[crcb[0] + 27] = (char)(d + '1');
zs0[crcb[0]] = d;
rd[crcb[1]] ^= bit; cd[crcb[2]] ^= bit; bd[crcb[3]] ^= bit;
if (ii < 23) goto nextii;
// this is a valid band, check if lexically minimale
int ir = bandminlex.Getmin(zs0, &pband2, 0);
if (ir < 0) {//would be bug did not come in enumeration
cerr << "Find B2 invalid return Getmin" << endl;
return;
}
pcheck2 = pband2;
it16_2 = pband2.i416;
ib2check = i2t16 = t416_to_n6[it16_2];
{
memcpy(&gcheck[27], zs0, 27 * sizeof gcheck[0]);
if (Band2Check())goto next;// do nothing if p2b
}
nb12++;
p_cpt2g[0] ++;// compte band2
if (p_cpt2g[0] < sgo.vx[0]) goto next;
myband2.InitBand2_3(it16_2, &zsol[27], pband2);
//myband2.PrintStatus();
//__________________________ bands 3
Find_band3B();
if (!nband3) goto next;
for (int i = 0; i < nband3; i++) {
STD_B3 wb3= bands3[i];
int min= t16_min_clues[wb3.i416];
//cout << wb3.band << "\t" << wb3.i416 << "\t" << min << endl;
}
p_cpt2g[1] += nband3;// compte ba32
if (nband3 > p_cpt2g[4]) p_cpt2g[4] = nband3;
//if (1) goto next;
// setup gangster
for (int i = 0; i < 9; i++) {// init columns status
cold[i] = 0x1ff;
for (int j = 0; j < 6; j++) cold[i] ^= 1 << grid0[i + 9 * j];
gangb12[i] = 0x1ff ^ cold[i];
}
memcpy(gangcols, cold, sizeof gangcols);
//=========================== collect UAs GUAs
zh1b_g.modegua = 0;//must be to activate filter in UAs b12 more
if (genuasb12.Initgen()) return;
if (1) {
BuildGang9x3();
zh1b_g.modegua = 1;//must be to kill filter in GUAs 6_7 more
genb12.SecondSockets2Setup();// collect GUA2s
genb12.SecondSockets3Setup();// collect GUA3s
cout << "==========" << p_cpt2g[0] << " b2id="<<myband2.i416 << endl;
if (p_cpt2g[0] == sgo.vx[3]) {
cout << "n bands3 \t" << genb12.nband3 << endl;
cout << "ua bands1+2 \t" << genuasb12.nua << endl;
cout << "guas socket2 \t" << genb12.ntua2 << endl;
cout << "guas socket3 \t" << genb12.ntua3 << endl;
cout << "active socket2\t" << genb12.nactive2 << endl;
cout << "active socket3\t" << genb12.nactive3 << endl;
}
}
//if (1) return;
//________________loop on the 9 band1
Go_Sol_Band1();
if (p_cpt2g[0]>sgo.vx[2]) return;
goto next;
}
/*
//_______________________ std process
if ((nb12 >> 6) < skip) return 0;// here restart value, kept untouched if no band 3 found
Find_band3B();
{// print a restart point every 64 bands 1+2 seen
uint64_t w = genb12.nb12, w1 = w >> 6;
w &= 63;
if (w == 0) {
long tfin = GetTimeMillis();
cout << "next skip value to use=\t" << w1 <<"\t"<<(tfin-sgo.tdeb)/1000<<"\t"<< p_cpt2g[0]<< endl;
}
}
if ((nb12 >> 6) >= last)return 1;
return 0;
*/
back:
if (--ii >= 0) goto next;
}
void GEN_BANDES_12::Find_band3B() {
register int *crcb, bit;
nband3 = 0;
int *rd = rowdb3, *cd = cold, *bd = boxdb3; // to updates rows cols boxes
char * zs = zsol;
int * zs0 = &grid0[54];
memcpy(boxdb3, &boxd[3], sizeof boxdb3);
memcpy(rowdb3, &rowd[3], sizeof rowdb3);
// now loop over the 24 cells not yet assigned in the band to fill the band use relative cell
int ii = -1, free[24];
uint32_t d;
nextii:
ii++;
{
crcb = tgen_band_cat[ii];//cell_row_col_box one of the 24 cells to fill
register int fr = cd[crcb[2]] & bd[crcb[3]] & rd[crcb[1]];
if (!fr)goto back;
free[ii] = fr;
}
goto next_first;
next:// erase previous fill and look for next
crcb = tgen_band_cat[ii];
d = zs0[crcb[0]];
bit = 1 << d;
rd[crcb[1]] ^= bit; cd[crcb[2]] ^= bit; bd[crcb[3]] ^= bit;
if (!free[ii])goto back;
{
next_first:
crcb = tgen_band_cat[ii];// be sure to have the good one
bitscanforward(d, free[ii]);
bit = 1 << d;
free[ii] ^= bit;
zs[crcb[0] + 54] = (char)(d + '1');
zs0[crcb[0]] = d;
rd[crcb[1]] ^= bit; cd[crcb[2]] ^= bit; bd[crcb[3]] ^= bit;
if (ii < 23) goto nextii;
// this is a valid band, check if canonical
int ir = bandminlex.Getmin(zs0, &pband3, 0);
if (ir < 0) {//would be bug did not come in enumeration
cerr << "gen band 3 invalid return Getmin" << endl;
return;
}
int it16_3 = pband3.i416;
ib3check = i3t16 = t416_to_n6[it16_3];
if (Band3Check())goto next;
//if(ib3check==ib2check)//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
bands3[nband3++].InitBand3(it16_3, &zs[54], pband3);
goto next;
}
back:
if (--ii >= 0) goto next;
//cout << "nb3=" << nband3 << endl;
}
void GEN_BANDES_12::Go_Sol_Band1() {
uint32_t nua = genuasb12.nua;
uint64_t *tua = genuasb12.tua;
for (int i = 0; i < 9; i++) {
register uint32_t b1 = t2clues_band1[i];
ncluesb12 = 0;
BitsInTable32((int *)tcluesb12, ncluesb12, b1);
nuasb2 = 0;
for (uint32_t iua = 0; iua < nua; iua++) {
register uint64_t ua = tua[iua];
if (ua&b1) continue; // hit by the 2 clues in b1
ua >>= 32; // keep only b2
register uint32_t b2 = (uint32_t)ua & BIT_SET_27;
b2 |= (_popcnt32(b2) << 27);
if (nuasb2 == 500)nuasb2--;
AddUA32(tuasb2, nuasb2, b2);
}
// add uas specific to band2
{
uint32_t *tua = myband2.tua, nua = myband2.nua;
for (uint32_t iua = 0; iua < nua; iua++) {
register uint32_t b2 = tua[iua] & BIT_SET_27;
b2 |= (_popcnt32(b2) << 27);
AddUA32(tuasb2, nuasb2, b2);
}
}
for (uint32_t j = 0; j < nuasb2; j++) tuasb2[j] &= BIT_SET_27;// kill count
// find a minimum number of clues through disjoint uas
// assuming most are minirow uas
uint32_t disj_uas = tuasb2[0], ndisj = 1;
for (uint32_t iua = 1; iua < nuasb2; iua++) {
if (tuasb2[iua] & disj_uas) continue;
disj_uas |= tuasb2[iua];
ndisj++;
}
if (p_cpt2g[0]==sgo.vx[3]) {
cout << Char27out(b1) << " b1 2 clues" << endl;
cout << "minband2 = " << ndisj << endl;
cout << "reduced table nuas= " << nuasb2 << endl;
for (uint32_t j = 0; j < nuasb2; j++)
cout << Char27out(tuasb2[j]) << " s=" << (tuasb2[j] >> 27) << " i=" << j << endl;
}
if (ndisj > 8) continue; // nothing to do for a 18 clues
p_cpt2g[20 + ndisj]++;
if (0) {
ExpandBand2();
continue;
}
//_______________ guas filter => already killed/forced plus sub table
// build new subtables still active not fixed
nguared_2 = 0;
memset(ntuar2, 0, sizeof ntuar2);
forced81_2.SetAll_0(); forced81_3.SetAll_0();
for (int i = 0; i < genb12.nactive2; i++) {
int i81 = genb12.tactive2[i];
GEN_BANDES_12::SGUA2 & w = genb12.tsgua2[i81];
uint32_t * tuasw = tuar2[i81], nt = 0;
for (uint32_t iua = 0; iua < w.nua; iua++) {
register uint64_t Ru = w.tua[iua];
if (Ru&b1) continue; // hit by the 2 clues in b1
Ru >>= 32; // keep only b2
register uint32_t b2 = (uint32_t)Ru & BIT_SET_27;
if (!b2) {// empty in band 2 stop and force
forced81_2.Set_c(i81);
nt = 0;
goto nexti81_2;
}