-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsss2.cpp
2582 lines (2478 loc) · 89.9 KB
/
fsss2.cpp
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
/*
*
* Created on: May 13, 2014
* Author: Mladen Dobrichev
*/
//Fast Simple Sudoku Solver 2
#include <stdio.h>
#include <memory.h>
#include <random>
#include "fsss2.h"
//game mode flags
#define MODE_SOLVING 0 //unused, keep solving
#define MODE_STOP_PROCESSING 1 //solved or error
#define MODE_STOP_GUESSING 2 //necessary solutions found
#ifdef COUNT_TRIALS
int nTrials;
#endif
//int knownNoLockedCandidatesHits;
//int knownNoLockedCandidatesMisses;
//int knownNoHiddenHits;
//int knownNoHiddenMisses;
//only first 81 bits set
constexpr t_128 constraints::mask81 = {{0xFFFFFFFFFFFFFFFF, 0x0001FFFF}};
//only first 81 + 27 = 108 bits set
//template <class X> const t_128 fsss2<X>::mask108 = {0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFF};
//the first 81 bits for the cells and the 27 bits from position 96+
constexpr t_128 constraints::mask108 = {{0xFFFFFFFFFFFFFFFF,0x07FFFFFF0001FFFF}};
//the 27 bits from position 96+
//const t_128 constraints::mask27 = {{0x0,0x07FFFFFF00000000}};
constexpr t_128 constraints::visibleCells[81] = { //1 for all 20 visible cells, 1 for the cell itself, 1 for the three houses
{{0x80402010081C0FFF,0x0004020100000100}},
{{0x00804020101C0FFF,0x0004040100000201}},
{{0x01008040201C0FFF,0x0004080100000402}},
{{0x0201008040E071FF,0x0008100100000804}},
{{0x0402010080E071FF,0x0008200100001008}},
{{0x0804020100E071FF,0x0008400100002010}},
{{0x10080402070381FF,0x0010800100004020}},
{{0x20100804070381FF,0x0011000100008040}},
{{0x40201008070381FF,0x0012000100010080}},
{{0x80402010081FFE07,0x0004020200000100}},
{{0x00804020101FFE07,0x0004040200000201}},
{{0x01008040201FFE07,0x0004080200000402}},
{{0x0201008040E3FE38,0x0008100200000804}},
{{0x0402010080E3FE38,0x0008200200001008}},
{{0x0804020100E3FE38,0x0008400200002010}},
{{0x100804020703FFC0,0x0010800200004020}},
{{0x201008040703FFC0,0x0011000200008040}},
{{0x402010080703FFC0,0x0012000200010080}},
{{0x804020100FFC0E07,0x0004020400000100}},
{{0x0080402017FC0E07,0x0004040400000201}},
{{0x0100804027FC0E07,0x0004080400000402}},
{{0x0201008047FC7038,0x0008100400000804}},
{{0x0402010087FC7038,0x0008200400001008}},
{{0x0804020107FC7038,0x0008400400002010}},
{{0x1008040207FF81C0,0x0010800400004020}},
{{0x2010080407FF81C0,0x0011000400008040}},
{{0x4020100807FF81C0,0x0012000400010080}},
{{0x8040E07FF8040201,0x0020020800000100}},
{{0x0080E07FF8080402,0x0020040800000201}},
{{0x0100E07FF8100804,0x0020080800000402}},
{{0x0207038FF8201008,0x0040100800000804}},
{{0x0407038FF8402010,0x0040200800001008}},
{{0x0807038FF8804020,0x0040400800002010}},
{{0x10381C0FF9008040,0x0080800800004020}},
{{0x20381C0FFA010080,0x0081000800008040}},
{{0x40381C0FFC020100,0x0082000800010080}},
{{0x8040FFF038040201,0x0020021000000100}},
{{0x0080FFF038080402,0x0020041000000201}},
{{0x0100FFF038100804,0x0020081000000402}},
{{0x02071FF1C0201008,0x0040101000000804}},
{{0x04071FF1C0402010,0x0040201000001008}},
{{0x08071FF1C0804020,0x0040401000002010}},
{{0x10381FFE01008040,0x0080801000004020}},
{{0x20381FFE02010080,0x0081001000008040}},
{{0x40381FFE04020100,0x0082001000010080}},
{{0x807FE07038040201,0x0020022000000100}},
{{0x00BFE07038080402,0x0020042000000201}},
{{0x013FE07038100804,0x0020082000000402}},
{{0x023FE381C0201008,0x0040102000000804}},
{{0x043FE381C0402010,0x0040202000001008}},
{{0x083FE381C0804020,0x0040402000002010}},
{{0x103FFC0E01008040,0x0080802000004020}},
{{0x203FFC0E02010080,0x0081002000008040}},
{{0x403FFC0E04020100,0x0082002000010080}},
{{0xFFC0201008040201,0x0100024000000703}},
{{0xFFC0402010080402,0x0100044000000703}},
{{0xFFC0804020100804,0x0100084000000703}},
{{0x7FC1008040201008,0x020010400000381C}},
{{0x7FC2010080402010,0x020020400000381C}},
{{0x7FC4020100804020,0x020040400000381C}},
{{0x7FC8040201008040,0x040080400001C0E0}},
{{0x7FD0080402010080,0x040100400001C0E0}},
{{0x7FE0100804020100,0x040200400001C0E0}},
{{0x81C0201008040201,0x01000280000007FF}},
{{0x81C0402010080402,0x01000480000007FF}},
{{0x81C0804020100804,0x01000880000007FF}},
{{0x8E01008040201008,0x02001080000038FF}},
{{0x8E02010080402010,0x02002080000038FF}},
{{0x8E04020100804020,0x02004080000038FF}},
{{0xF008040201008040,0x040080800001C0FF}},
{{0xF010080402010080,0x040100800001C0FF}},
{{0xF020100804020100,0x040200800001C0FF}},
{{0x81C0201008040201,0x010003000001FF03}},
{{0x81C0402010080402,0x010005000001FF03}},
{{0x81C0804020100804,0x010009000001FF03}},
{{0x0E01008040201008,0x020011000001FF1C}},
{{0x0E02010080402010,0x020021000001FF1C}},
{{0x0E04020100804020,0x020041000001FF1C}},
{{0x7008040201008040,0x040081000001FFE0}},
{{0x7010080402010080,0x040101000001FFE0}},
{{0x7020100804020100,0x040201000001FFE0}}
}; //bm128 visibleCells[81]
constexpr t_128 constraints::bitsForHouse[27] = { //1 for the 9 cells in the house
{{0x00000000000001FF,0x0000000000000000}},
{{0x000000000003FE00,0x0000000000000000}},
{{0x0000000007FC0000,0x0000000000000000}},
{{0x0000000FF8000000,0x0000000000000000}},
{{0x00001FF000000000,0x0000000000000000}},
{{0x003FE00000000000,0x0000000000000000}},
{{0x7FC0000000000000,0x0000000000000000}},
{{0x8000000000000000,0x00000000000000FF}},
{{0x0000000000000000,0x000000000001FF00}},
{{0x8040201008040201,0x0000000000000100}},
{{0x0080402010080402,0x0000000000000201}},
{{0x0100804020100804,0x0000000000000402}},
{{0x0201008040201008,0x0000000000000804}},
{{0x0402010080402010,0x0000000000001008}},
{{0x0804020100804020,0x0000000000002010}},
{{0x1008040201008040,0x0000000000004020}},
{{0x2010080402010080,0x0000000000008040}},
{{0x4020100804020100,0x0000000000010080}},
{{0x00000000001C0E07,0x0000000000000000}},
{{0x0000000000E07038,0x0000000000000000}},
{{0x00000000070381C0,0x0000000000000000}},
{{0x0000E07038000000,0x0000000000000000}},
{{0x00070381C0000000,0x0000000000000000}},
{{0x00381C0E00000000,0x0000000000000000}},
{{0x81C0000000000000,0x0000000000000703}},
{{0x0E00000000000000,0x000000000000381C}},
{{0x7000000000000000,0x000000000001C0E0}},
}; //bitsForHouse[27]
//const uint32 constraints::topCellsHouses = 0x00FC007F; //000111111000000000001111111
#ifdef USE_LOCKED_CANDIDATES
constexpr tripletMask constraints::tripletMasks[54] = {
{{{0x0000000000000007,0x0000000000000000}}, {{0x00000000000001F8,0x0000000000000000}}, {{0x00000000001C0E00,0x0000000000000000}}, },
{{{0x0000000000000038,0x0000000000000000}}, {{0x00000000000001C7,0x0000000000000000}}, {{0x0000000000E07000,0x0000000000000000}}, },
{{{0x00000000000001C0,0x0000000000000000}}, {{0x000000000000003F,0x0000000000000000}}, {{0x0000000007038000,0x0000000000000000}}, },
{{{0x0000000000000E00,0x0000000000000000}}, {{0x000000000003F000,0x0000000000000000}}, {{0x00000000001C0007,0x0000000000000000}}, },
{{{0x0000000000007000,0x0000000000000000}}, {{0x0000000000038E00,0x0000000000000000}}, {{0x0000000000E00038,0x0000000000000000}}, },
{{{0x0000000000038000,0x0000000000000000}}, {{0x0000000000007E00,0x0000000000000000}}, {{0x00000000070001C0,0x0000000000000000}}, },
{{{0x00000000001C0000,0x0000000000000000}}, {{0x0000000007E00000,0x0000000000000000}}, {{0x0000000000000E07,0x0000000000000000}}, },
{{{0x0000000000E00000,0x0000000000000000}}, {{0x00000000071C0000,0x0000000000000000}}, {{0x0000000000007038,0x0000000000000000}}, },
{{{0x0000000007000000,0x0000000000000000}}, {{0x0000000000FC0000,0x0000000000000000}}, {{0x00000000000381C0,0x0000000000000000}}, },
{{{0x0000000038000000,0x0000000000000000}}, {{0x0000000FC0000000,0x0000000000000000}}, {{0x0000E07000000000,0x0000000000000000}}, },
{{{0x00000001C0000000,0x0000000000000000}}, {{0x0000000E38000000,0x0000000000000000}}, {{0x0007038000000000,0x0000000000000000}}, },
{{{0x0000000E00000000,0x0000000000000000}}, {{0x00000001F8000000,0x0000000000000000}}, {{0x00381C0000000000,0x0000000000000000}}, },
{{{0x0000007000000000,0x0000000000000000}}, {{0x00001F8000000000,0x0000000000000000}}, {{0x0000E00038000000,0x0000000000000000}}, },
{{{0x0000038000000000,0x0000000000000000}}, {{0x00001C7000000000,0x0000000000000000}}, {{0x00070001C0000000,0x0000000000000000}}, },
{{{0x00001C0000000000,0x0000000000000000}}, {{0x000003F000000000,0x0000000000000000}}, {{0x0038000E00000000,0x0000000000000000}}, },
{{{0x0000E00000000000,0x0000000000000000}}, {{0x003F000000000000,0x0000000000000000}}, {{0x0000007038000000,0x0000000000000000}}, },
{{{0x0007000000000000,0x0000000000000000}}, {{0x0038E00000000000,0x0000000000000000}}, {{0x00000381C0000000,0x0000000000000000}}, },
{{{0x0038000000000000,0x0000000000000000}}, {{0x0007E00000000000,0x0000000000000000}}, {{0x00001C0E00000000,0x0000000000000000}}, },
{{{0x01C0000000000000,0x0000000000000000}}, {{0x7E00000000000000,0x0000000000000000}}, {{0x8000000000000000,0x0000000000000703}}, },
{{{0x0E00000000000000,0x0000000000000000}}, {{0x71C0000000000000,0x0000000000000000}}, {{0x0000000000000000,0x000000000000381C}}, },
{{{0x7000000000000000,0x0000000000000000}}, {{0x0FC0000000000000,0x0000000000000000}}, {{0x0000000000000000,0x000000000001C0E0}}, },
{{{0x8000000000000000,0x0000000000000003}}, {{0x0000000000000000,0x00000000000000FC}}, {{0x01C0000000000000,0x0000000000000700}}, },
{{{0x0000000000000000,0x000000000000001C}}, {{0x8000000000000000,0x00000000000000E3}}, {{0x0E00000000000000,0x0000000000003800}}, },
{{{0x0000000000000000,0x00000000000000E0}}, {{0x8000000000000000,0x000000000000001F}}, {{0x7000000000000000,0x000000000001C000}}, },
{{{0x0000000000000000,0x0000000000000700}}, {{0x0000000000000000,0x000000000001F800}}, {{0x81C0000000000000,0x0000000000000003}}, },
{{{0x0000000000000000,0x0000000000003800}}, {{0x0000000000000000,0x000000000001C700}}, {{0x0E00000000000000,0x000000000000001C}}, },
{{{0x0000000000000000,0x000000000001C000}}, {{0x0000000000000000,0x0000000000003F00}}, {{0x7000000000000000,0x00000000000000E0}}, },
{{{0x0000000000040201,0x0000000000000000}}, {{0x8040201008000000,0x0000000000000100}}, {{0x0000000000180C06,0x0000000000000000}}, },
{{{0x0000201008000000,0x0000000000000000}}, {{0x8040000000040201,0x0000000000000100}}, {{0x0000C06030000000,0x0000000000000000}}, },
{{{0x8040000000000000,0x0000000000000100}}, {{0x0000201008040201,0x0000000000000000}}, {{0x0180000000000000,0x0000000000000603}}, },
{{{0x0000000000080402,0x0000000000000000}}, {{0x0080402010000000,0x0000000000000201}}, {{0x0000000000140A05,0x0000000000000000}}, },
{{{0x0000402010000000,0x0000000000000000}}, {{0x0080000000080402,0x0000000000000201}}, {{0x0000A05028000000,0x0000000000000000}}, },
{{{0x0080000000000000,0x0000000000000201}}, {{0x0000402010080402,0x0000000000000000}}, {{0x8140000000000000,0x0000000000000502}}, },
{{{0x0000000000100804,0x0000000000000000}}, {{0x0100804020000000,0x0000000000000402}}, {{0x00000000000C0603,0x0000000000000000}}, },
{{{0x0000804020000000,0x0000000000000000}}, {{0x0100000000100804,0x0000000000000402}}, {{0x0000603018000000,0x0000000000000000}}, },
{{{0x0100000000000000,0x0000000000000402}}, {{0x0000804020100804,0x0000000000000000}}, {{0x80C0000000000000,0x0000000000000301}}, },
{{{0x0000000000201008,0x0000000000000000}}, {{0x0201008040000000,0x0000000000000804}}, {{0x0000000000C06030,0x0000000000000000}}, },
{{{0x0001008040000000,0x0000000000000000}}, {{0x0200000000201008,0x0000000000000804}}, {{0x0006030180000000,0x0000000000000000}}, },
{{{0x0200000000000000,0x0000000000000804}}, {{0x0001008040201008,0x0000000000000000}}, {{0x0C00000000000000,0x0000000000003018}}, },
{{{0x0000000000402010,0x0000000000000000}}, {{0x0402010080000000,0x0000000000001008}}, {{0x0000000000A05028,0x0000000000000000}}, },
{{{0x0002010080000000,0x0000000000000000}}, {{0x0400000000402010,0x0000000000001008}}, {{0x0005028140000000,0x0000000000000000}}, },
{{{0x0400000000000000,0x0000000000001008}}, {{0x0002010080402010,0x0000000000000000}}, {{0x0A00000000000000,0x0000000000002814}}, },
{{{0x0000000000804020,0x0000000000000000}}, {{0x0804020100000000,0x0000000000002010}}, {{0x0000000000603018,0x0000000000000000}}, },
{{{0x0004020100000000,0x0000000000000000}}, {{0x0800000000804020,0x0000000000002010}}, {{0x00030180C0000000,0x0000000000000000}}, },
{{{0x0800000000000000,0x0000000000002010}}, {{0x0004020100804020,0x0000000000000000}}, {{0x0600000000000000,0x000000000000180C}}, },
{{{0x0000000001008040,0x0000000000000000}}, {{0x1008040200000000,0x0000000000004020}}, {{0x0000000006030180,0x0000000000000000}}, },
{{{0x0008040200000000,0x0000000000000000}}, {{0x1000000001008040,0x0000000000004020}}, {{0x0030180C00000000,0x0000000000000000}}, },
{{{0x1000000000000000,0x0000000000004020}}, {{0x0008040201008040,0x0000000000000000}}, {{0x6000000000000000,0x00000000000180C0}}, },
{{{0x0000000002010080,0x0000000000000000}}, {{0x2010080400000000,0x0000000000008040}}, {{0x0000000005028140,0x0000000000000000}}, },
{{{0x0010080400000000,0x0000000000000000}}, {{0x2000000002010080,0x0000000000008040}}, {{0x0028140A00000000,0x0000000000000000}}, },
{{{0x2000000000000000,0x0000000000008040}}, {{0x0010080402010080,0x0000000000000000}}, {{0x5000000000000000,0x00000000000140A0}}, },
{{{0x0000000004020100,0x0000000000000000}}, {{0x4020100800000000,0x0000000000010080}}, {{0x00000000030180C0,0x0000000000000000}}, },
{{{0x0020100800000000,0x0000000000000000}}, {{0x4000000004020100,0x0000000000010080}}, {{0x00180C0600000000,0x0000000000000000}}, },
{{{0x4000000000000000,0x0000000000010080}}, {{0x0020100804020100,0x0000000000000000}}, {{0x3000000000000000,0x000000000000C060}}, },
}; //tripletMasks
#endif
namespace fsss2 {
int rand729() {
static std::mt19937 generator;
static std::uniform_int_distribution<int> distribution(0, 728);
return distribution(generator);
}
template <class X> fsss2<X>::fsss2(X &theCollector) : mode(0), guessDepth(0)
#ifdef USE_LOCKED_CANDIDATES
#ifndef LOCKED_CANDIDATES_ALWAYS
, lockedDone(0)
#endif
#endif
#ifdef USE_SUBSETS
//, subsetsDone(0)
#endif
, collector(theCollector)
{}
template <class X> constexpr void fsss2<X>::initEmpty() {
//set all cells and houses as "unsolved"
grid[0] = constraints::mask108;
grid[1] = constraints::mask108;
grid[2] = constraints::mask108;
grid[3] = constraints::mask108;
grid[4] = constraints::mask108;
grid[5] = constraints::mask108;
grid[6] = constraints::mask108;
grid[7] = constraints::mask108;
grid[8] = constraints::mask108;
//no processed digits for hidden singles yet
knownNoHiddenSingles[0] = constraints::mask108;
knownNoHiddenSingles[1] = constraints::mask108;
knownNoHiddenSingles[2] = constraints::mask108;
knownNoHiddenSingles[3] = constraints::mask108;
knownNoHiddenSingles[4] = constraints::mask108;
knownNoHiddenSingles[5] = constraints::mask108;
knownNoHiddenSingles[6] = constraints::mask108;
knownNoHiddenSingles[7] = constraints::mask108;
knownNoHiddenSingles[8] = constraints::mask108;
#ifdef USE_LOCKED_CANDIDATES
#ifdef LOCKED_CANDIDATES_USE_CACHE
knownNoLockedCandidates[0] = constraints::mask108;
knownNoLockedCandidates[1] = constraints::mask108;
knownNoLockedCandidates[2] = constraints::mask108;
knownNoLockedCandidates[3] = constraints::mask108;
knownNoLockedCandidates[4] = constraints::mask108;
knownNoLockedCandidates[5] = constraints::mask108;
knownNoLockedCandidates[6] = constraints::mask108;
knownNoLockedCandidates[7] = constraints::mask108;
knownNoLockedCandidates[8] = constraints::mask108;
#endif
#ifndef LOCKED_CANDIDATES_ALWAYS
lockedDone = 0;
#endif
#endif
#ifdef USE_SUBSETS
//subsetsDone = 0;
// for(int i = 0; i < 36; i++) knownNoSubsets[i] = constraints::mask108;
#endif //USE_SUBSETS
solved.clear(); //no solved cells yet
trialCandidates.clear(); //unknown cell candidates for T&E
mode = 0; //should solve
guessDepth = 0; //no guessed cells yet
numTrialsLocal = 0;
//maxGuessDepth = 0;
//hardMode = 0;
}
template <class X> void fsss2<X>::setCellValue(int pos, int value) {
collector.setCellValue(pos, value);
solved.setBit(pos); //mark cell as "solved"
grid[value - 1].clearBits(constraints::visibleCells[pos]); //mark visible cells as forbidden for the same digit, mark the 3 houses as solved
}
template <class X> void fsss2<X>::eliminateCellValue(int pos, int value) {
grid[value - 1].clearBit(pos);
}
#ifdef USE_LOCKED_CANDIDATES
//template <class X> bool fsss2<X>::doLockedCandidatesForDigit(bm128& tmp) {
// bool found = false;
// for(uint32_t lines = 0x03FFFF & (tmp.toInt32_3()); lines; lines &= (lines - 1)) {
// unsigned int line = 3U * bm128::FindLSBIndex32(lines); //unsolved row or column
// //process the 3 triplets in the line (row or column)
// for(unsigned int t = 0; t < 3; t++) {
// //if(tmp.isDisjoint(constraints::tripletMasks[line + t].self)) continue; //no candidates, possibly resolved box
// bool dl = tmp.isDisjoint(constraints::tripletMasks[line + t].adjacentLine);
// bool db = tmp.isDisjoint(constraints::tripletMasks[line + t].adjacentBox);
// if(dl) {
// //unsolved line with candidates located only within this triplet
// if(!db) {
// tmp.clearBits(constraints::tripletMasks[line + t].adjacentBox);
// found = true;
// //goto next_line;
// return true;
// }
// }
// if(db) {
// //the other two triplets within this box have no candidates
// if(!dl) {
// //other two triplets for this line have candidates, but the box is possibly solved
// if(!tmp.isDisjoint(constraints::tripletMasks[line + t].self)) { //unsolved box
// tmp.clearBits(constraints::tripletMasks[line + t].adjacentLine);
// found = true;
// //goto next_line;
// return true;
// }
// }
// }
// } //triplets in a line
////next_line:
// ;
// } //lines
// return found;
// //return false;
//}
template <class X> bool fsss2<X>::doLockedCandidatesForDigit(bm128& tmp) {
static constexpr int boxNum[18][3] = {
{0,1,2},{0,1,2},{0,1,2},{3,4,5},{3,4,5},{3,4,5},{6,7,8},{6,7,8},{6,7,8},
{0,3,6},{0,3,6},{0,3,6},{1,4,7},{1,4,7},{1,4,7},{2,5,8},{2,5,8},{2,5,8}
};
bool found = false;
uint32_t unsolvedHouses = tmp.toInt32_3();
if(unsolvedHouses == 0) return false;
uint32_t unsolvedBoxes = unsolvedHouses >> 18;
//if(unsolvedBoxes == 0) return false; //never happens
for(uint32_t lines = 0x03FFFF & unsolvedHouses; lines; lines &= (lines - 1)) {
unsigned int line = bm128::FindLSBIndex32(lines); //unsolved row or column
unsigned int lineBase = 3U * line;
//process the 3 triplets in the line (row or column)
for(unsigned int t = 0; t < 3; t++) {
if(0 == (unsolvedBoxes & ((uint32_t) 1) << (boxNum[line][t]))) continue; //resolved box
//if(tmp.isDisjoint(constraints::tripletMasks[lineBase + t].self)) continue; //resolved box
// fprintf(stderr, "?");
// continue; //no candidates, possibly resolved box
// }
bool dl = tmp.isDisjoint(constraints::tripletMasks[lineBase + t].adjacentLine); //all line candidates are within this triplet
bool db = tmp.isDisjoint(constraints::tripletMasks[lineBase + t].adjacentBox); //all box candidates are within this triplet
if(dl) {
//unsolved line with candidates located only within this triplet
if(!db) {
tmp.clearBits(constraints::tripletMasks[lineBase + t].adjacentBox);
//fprintf(stderr, "B%2.2d %d\n", lineBase, t);
found = true;
//goto next_line;
return true;
}
}
if(db) {
//the other two triplets within this box have no candidates
if(!dl) {
//other two triplets for this line have candidates, but the box is possibly solved
//if(!tmp.isDisjoint(constraints::tripletMasks[lineBase + t].self)) { //unsolved box
//if(1 || 0 != (unsolvedBoxes & (((uint32_t) 1) << (boxNum[line][t])))) {
tmp.clearBits(constraints::tripletMasks[lineBase + t].adjacentLine);
//fprintf(stderr, "L%2.2d %d\n", lineBase, t);
found = true;
//goto next_line;
return true;
//}
}
}
} //triplets in a line
//next_line:
;
} //lines
return found;
//return false;
}
#endif
#ifdef USE_SUBSETS
template <class X> int fsss2<X>::doPairs() {
int eliminationFound = 0;
//int subsetIndex = 0; //01,02,03,04,05,06,07,08,12,13,14,15,16,17,18,23,24,25,26,27,28,34,35,36,37,38,45,46,47,48,56,57,58,67,68,78
for(int d1 = 0, subsetIndex = 0; d1 < 8; d1++) {
for(int d2 = d1 + 1; d2 < 9; d2++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
if(any == knownNoPairs[subsetIndex]) {
//fprintf(stderr, "-"); // debug
continue;
}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 2) return -1;
if(numCandidates == 2) {
//only 2 digits in 2 cells in the same house
ss |= tmp;
//ss = tmp;
subsetFound = true;
//fprintf(stderr, "p"); // debug
//trialCandidates |= ss;
//break;
}
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
//if(eliminationHere) {
// eliminationFound = true;
//}
//else {
// knownNoSubsets[subsetIndex] = any;
//}
}
else {
knownNoPairs[subsetIndex] = any;
}
}
}
return eliminationFound;
}
template <class X> int fsss2<X>::doTriples() {
int eliminationFound = 0;
//int subsetIndex = 0; //012,013,...,678
for(int d1 = 0, subsetIndex = 0; d1 < 7; d1++) {
for(int d2 = d1 + 1; d2 < 8; d2++) {
for(int d3 = d2 + 1; d3 < 9; d3++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
any |= grid[d3];
if(any == knownNoTriples[subsetIndex]) {
//fprintf(stderr, "-"); // debug
continue;
}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
both &= grid[d3];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 3) return -1;
if(numCandidates == 3) {
//only 3 digits in 3 cells in the same house
ss |= tmp;
subsetFound = true;
//fprintf(stderr, "t"); // debug
//trialCandidates |= ss;
//break;
}
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2) && (d != d3)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
}
else {
knownNoTriples[subsetIndex] = any;
}
}
}
}
return eliminationFound;
}
template <class X> int fsss2<X>::doQuadruples() {
int eliminationFound = 0;
//int subsetIndex = 0; //0123,0124,...,5678
for(int d1 = 0, subsetIndex = 0; d1 < 6; d1++) {
for(int d2 = d1 + 1; d2 < 7; d2++) {
for(int d3 = d2 + 1; d3 < 8; d3++) {
for(int d4 = d3 + 1; d4 < 9; d4++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
any |= grid[d3];
any |= grid[d4];
if(any == knownNoQuadruples[subsetIndex]) {
//fprintf(stderr, "-"); // debug
continue;
}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
both &= grid[d3];
both &= grid[d4];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 4) return -1;
if(numCandidates == 4) {
//only 4 digits in 4 cells in the same house
ss |= tmp;
subsetFound = true;
//fprintf(stderr, "q"); // debug
//trialCandidates |= ss;
//break;
}
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2) && (d != d3) && (d != d4)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
}
else {
knownNoQuadruples[subsetIndex] = any;
}
}
}
}
}
return eliminationFound;
}
template <class X> int fsss2<X>::doQuintuples() {
int eliminationFound = 0;
//int subsetIndex = 0; //01234,01235,...,45678
for(int d1 = 0, subsetIndex = 0; d1 < 5; d1++) {
for(int d2 = d1 + 1; d2 < 6; d2++) {
for(int d3 = d2 + 1; d3 < 7; d3++) {
for(int d4 = d3 + 1; d4 < 8; d4++) {
for(int d5 = d4 + 1; d5 < 9; d5++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
any |= grid[d3];
any |= grid[d4];
any |= grid[d5];
//if(any == knownNoQuintuples[subsetIndex]) {
// fprintf(stderr, "-"); // debug
// continue;
//}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
both &= grid[d3];
both &= grid[d4];
both &= grid[d5];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 5) return -1;
if(numCandidates == 5) {
//only 5 digits in 5 cells in the same house
ss |= tmp;
subsetFound = true;
//fprintf(stderr, "Q"); // debug
//trialCandidates |= ss;
//break;
}
//if(5 > tmp.popcount_128()) fprintf(stderr, "C5"); // debug
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2) && (d != d3) && (d != d4) && (d != d5)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
}
else {
//knownNoQuadruples[subsetIndex] = any;
//fprintf(stderr, "."); // debug
}
}
}
}
}
}
return eliminationFound;
}
template <class X> int fsss2<X>::doSextuples() {
int eliminationFound = 0;
//int subsetIndex = 0; //012345,012346,...,345678
for(int d1 = 0, subsetIndex = 0; d1 < 4; d1++) {
for(int d2 = d1 + 1; d2 < 5; d2++) {
for(int d3 = d2 + 1; d3 < 6; d3++) {
for(int d4 = d3 + 1; d4 < 7; d4++) {
for(int d5 = d4 + 1; d5 < 8; d5++) {
for(int d6 = d5 + 1; d6 < 9; d6++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
any |= grid[d3];
any |= grid[d4];
any |= grid[d5];
any |= grid[d6];
//if(any == knownNoQuintuples[subsetIndex]) {
// fprintf(stderr, "-"); // debug
// continue;
//}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
both &= grid[d3];
both &= grid[d4];
both &= grid[d5];
both &= grid[d6];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 6) return -1;
if(numCandidates == 6) {
//only 6 digits in 6 cells in the same house
ss |= tmp;
subsetFound = true;
//fprintf(stderr, "s"); // debug
//trialCandidates |= ss;
//break;
}
//if(6 > tmp.popcount_128()) fprintf(stderr, "C6"); // debug
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2) && (d != d3) && (d != d4) && (d != d5) && (d != d6)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
}
else {
//knownNoQuadruples[subsetIndex] = any;
//fprintf(stderr, "."); // debug
}
}
}
}
}
}
}
return eliminationFound;
}
template <class X> int fsss2<X>::doSeptuples() {
int eliminationFound = 0;
//int subsetIndex = 0; //0123456,0123457,...,2345678
for(int d1 = 0, subsetIndex = 0; d1 < 3; d1++) {
for(int d2 = d1 + 1; d2 < 4; d2++) {
for(int d3 = d2 + 1; d3 < 5; d3++) {
for(int d4 = d3 + 1; d4 < 6; d4++) {
for(int d5 = d4 + 1; d5 < 7; d5++) {
for(int d6 = d5 + 1; d6 < 8; d6++) {
for(int d7 = d6 + 1; d7 < 9; d7++, subsetIndex++) {
bm128 any = grid[d1];
any |= grid[d2];
any |= grid[d3];
any |= grid[d4];
any |= grid[d5];
any |= grid[d6];
any |= grid[d7];
//if(any == knownNoQuintuples[subsetIndex]) {
// fprintf(stderr, "-"); // debug
// continue;
//}
bool subsetFound = false;
bm128 ss;
ss.clear();
bm128 both = grid[d1];
both &= grid[d2];
both &= grid[d3];
both &= grid[d4];
both &= grid[d5];
both &= grid[d6];
both &= grid[d7];
//for each unsolved for both digits house
for(uint32_t houses = both.toInt32_3(); houses; houses &= (houses - 1)) {
bm128 tmp = any;
tmp &= constraints::bitsForHouse[bm128::FindLSBIndex32(houses)]; //mask other candidates and leave only these from the current house
int numCandidates = tmp.popcount_128();
if(numCandidates < 6) return -1;
if(numCandidates == 6) {
//only 6 digits in 6 cells in the same house
ss |= tmp;
subsetFound = true;
//fprintf(stderr, "s"); // debug
//trialCandidates |= ss;
//break;
}
//if(6 > tmp.popcount_128()) fprintf(stderr, "C6"); // debug
}
//eliminate the candidates from other digits
if(subsetFound) {
//bool eliminationHere = false;
for(int d = 0; d < 9; d++) {
if((d != d1) && (d != d2) && (d != d3) && (d != d4) && (d != d5) && (d != d6) && (d != d7)) {
if(!grid[d].isDisjoint(ss)) {
grid[d].clearBits(ss);
eliminationFound = 1;
//eliminationHere = true;
//goto nakedAgain;
}
}
}
}
else {
//knownNoQuadruples[subsetIndex] = any;
//fprintf(stderr, "."); // debug
}
}
}
}
}
}
}
}
return eliminationFound;
}
#endif
#ifdef USE_FISHES
template <class X> int fsss2<X>::doFish2() {
int eliminationFound = 0;
for(int d = 0; d < 9; d++) {
bm128 all = grid[d];
int numCandidates = all.popcount_96();
if(numCandidates > 65) continue; // small success chance
if(numCandidates < 5) continue; // zero success chance
uint32_t masks = all.toInt32_3();
//rows then columns
for(int r1 = 0; r1 < 8; r1++) {
if((masks & (1 << r1)) == 0) continue; // resolved row
bm128 r1pm = all;
r1pm &= (bm128)constraints::bitsForHouse[r1];
if(r1pm.popcount_128() != 2) continue;
int c1 = r1pm.getFirstBit1Index96();
r1pm.clearBit(c1);
int c2 = r1pm.getFirstBit1Index96();
c1 -= 9 * r1;
c2 -= 9 * r1;
for(int r2 = r1 + 1; r2 < 9; r2++) {
if((masks & (1 << r2)) == 0) continue; // resolved row
bm128 r2pm = all;
r2pm &= (bm128)constraints::bitsForHouse[r2];
if(r2pm.popcount_128() != 2) continue;
if(! r2pm.isBitSet(r2 * 9 + c1)) continue;
if(! r2pm.isBitSet(r2 * 9 + c2)) continue;
bm128 colMask = (bm128)constraints::bitsForHouse[9 + c1];
colMask |= (bm128)constraints::bitsForHouse[9 + c2];
bm128 elim = all;
elim &= colMask;
int elimCount = elim.popcount_128() - 4;
if(elimCount <= 0) continue; // no eliminations
eliminationFound = 1;
elim.clearBits(constraints::bitsForHouse[r1]); // don't remove intersecions with row 1
elim.clearBits(constraints::bitsForHouse[r2]); // don't remove intersecions with row 2
grid[d].clearBits(elim);
fprintf(stderr, "f"); // debug
//return 1;
}
}
//columns then rows
masks >>= 9; // place columns on the first 9 bits
for(int c1 = 0; c1 < 8; c1++) {
if((masks & (1 << c1)) == 0) continue; // resolved column
bm128 c1pm = all;
c1pm &= (bm128)constraints::bitsForHouse[c1 + 9];
if(c1pm.popcount_128() != 2) continue;
int r1 = c1pm.getFirstBit1Index96();
c1pm.clearBit(r1);
int r2 = c1pm.getFirstBit1Index96();
r1 /= 9;
r2 /= 9;
for(int c2 = c1 + 1; c2 < 9; c2++) {
if((masks & (1 << c2)) == 0) continue; // resolved column
bm128 c2pm = all;
c2pm &= (bm128)constraints::bitsForHouse[c2 + 9];
if(c2pm.popcount_128() != 2) continue;
if(! c2pm.isBitSet(r1 * 9 + c2)) continue;
if(! c2pm.isBitSet(r2 * 9 + c2)) continue;
bm128 rowMask = (bm128)constraints::bitsForHouse[r1];
rowMask |= (bm128)constraints::bitsForHouse[r2];
bm128 elim = all;
elim &= rowMask;
int elimCount = elim.popcount_128() - 4;
if(elimCount <= 0) continue; // no eliminations
eliminationFound = 1;
elim.clearBits(constraints::bitsForHouse[9 + c1]); // don't remove intersecions with column 1
elim.clearBits(constraints::bitsForHouse[9 + c2]); // don't remove intersecions with column 2
grid[d].clearBits(elim);
fprintf(stderr, "f"); // debug
//return 1;
}
}
//fprintf(stderr, "%c", eliminationFound ? 'f' : '.'); // debug
}
return eliminationFound;
}
template <class X> int fsss2<X>::doFish3() {
int eliminationFound = 0;
for(int d = 0; d < 9; d++) {
bm128 all = grid[d];
int numCandidates = all.popcount_96();
if(numCandidates > 65) continue; // small success chance
if(numCandidates < 10) continue; // zero success chance
uint32_t masks = all.toInt32_3();
//rows then columns
for(int r1 = 0; r1 < 7; r1++) {
if((masks & (1 << r1)) == 0) continue; // resolved row
bm128 r1pm = all;
r1pm &= (bm128)constraints::bitsForHouse[r1];
if(r1pm.popcount_128() != 3) continue;
int c1 = r1pm.getFirstBit1Index96();
r1pm.clearBit(c1);
int c2 = r1pm.getFirstBit1Index96();
r1pm.clearBit(c2);
int c3 = r1pm.getFirstBit1Index96();
c1 -= 9 * r1;
c2 -= 9 * r1;
c3 -= 9 * r1;
for(int r2 = r1 + 1; r2 < 8; r2++) {
if((masks & (1 << r2)) == 0) continue; // resolved row
bm128 r2pm = all;
r2pm &= (bm128)constraints::bitsForHouse[r2];
if(r2pm.popcount_128() != 3) continue;
if(! r2pm.isBitSet(r2 * 9 + c1)) continue;
if(! r2pm.isBitSet(r2 * 9 + c2)) continue;
if(! r2pm.isBitSet(r2 * 9 + c3)) continue;
for(int r3 = r2 + 1; r3 < 9; r3++) {
if((masks & (1 << r3)) == 0) continue; // resolved row
bm128 r3pm = all;
r3pm &= (bm128)constraints::bitsForHouse[r3];
if(r3pm.popcount_128() != 3) continue;
if(! r3pm.isBitSet(r3 * 9 + c1)) continue;
if(! r3pm.isBitSet(r3 * 9 + c2)) continue;
if(! r3pm.isBitSet(r3 * 9 + c3)) continue;
bm128 colMask = (bm128)constraints::bitsForHouse[9 + c1];
colMask |= (bm128)constraints::bitsForHouse[9 + c2];
colMask |= (bm128)constraints::bitsForHouse[9 + c3];
bm128 elim = all;
elim &= colMask;
int elimCount = elim.popcount_128() - 9;
if(elimCount <= 0) continue; // no eliminations
eliminationFound = 1;
elim.clearBits(constraints::bitsForHouse[r1]); // don't remove intersecions with row 1
elim.clearBits(constraints::bitsForHouse[r2]); // don't remove intersecions with row 2
elim.clearBits(constraints::bitsForHouse[r3]); // don't remove intersecions with row 2
grid[d].clearBits(elim);
fprintf(stderr, "F"); // debug
//return 1;
}
}
}
//columns then rows
masks >>= 9; // place columns on the first 9 bits
for(int c1 = 0; c1 < 7; c1++) {
if((masks & (1 << c1)) == 0) continue; // resolved column
bm128 c1pm = all;
c1pm &= (bm128)constraints::bitsForHouse[c1 + 9];
if(c1pm.popcount_128() != 3) continue;
int r1 = c1pm.getFirstBit1Index96();
c1pm.clearBit(r1);
int r2 = c1pm.getFirstBit1Index96();
c1pm.clearBit(r2);
int r3 = c1pm.getFirstBit1Index96();
r1 /= 9;
r2 /= 9;
r3 /= 9;
for(int c2 = c1 + 1; c2 < 8; c2++) {
if((masks & (1 << c2)) == 0) continue; // resolved row
bm128 c2pm = all;
c2pm &= (bm128)constraints::bitsForHouse[c2 + 9];
if(c2pm.popcount_128() != 3) continue;
if(! c2pm.isBitSet(r1 * 9 + c2)) continue;
if(! c2pm.isBitSet(r2 * 9 + c2)) continue;
if(! c2pm.isBitSet(r3 * 9 + c2)) continue;
for(int c3 = c2 + 1; c3 < 8; c3++) {
if((masks & (1 << c3)) == 0) continue; // resolved row
bm128 c3pm = all;
c3pm &= (bm128)constraints::bitsForHouse[c3 + 9];
if(c3pm.popcount_128() != 3) continue;
if(! c3pm.isBitSet(r1 * 9 + c3)) continue;
if(! c3pm.isBitSet(r2 * 9 + c3)) continue;
if(! c3pm.isBitSet(r3 * 9 + c3)) continue;
bm128 rowMask = (bm128)constraints::bitsForHouse[r1];
rowMask |= (bm128)constraints::bitsForHouse[r2];
rowMask |= (bm128)constraints::bitsForHouse[r3];
bm128 elim = all;
elim &= rowMask;
int elimCount = elim.popcount_128() - 9;
if(elimCount <= 0) continue; // no eliminations
eliminationFound = 1;
elim.clearBits(constraints::bitsForHouse[9 + c1]); // don't remove intersecions with column 1
elim.clearBits(constraints::bitsForHouse[9 + c2]); // don't remove intersecions with column 2
elim.clearBits(constraints::bitsForHouse[9 + c3]); // don't remove intersecions with column 3
grid[d].clearBits(elim);
fprintf(stderr, "F"); // debug
//return 1;
}
}
}
//fprintf(stderr, "%c", eliminationFound ? 'F' : '.'); // debug
}
return eliminationFound;
}
#endif
//void fsss2::findBiValueCells(bm128& all) const { //cells with 2 remaining candidates
// //bm128 all;
// all = solved;
// bm128 duplicates = solved;
// bm128 triplicates = solved;
// for(int d = 0; d < 9; d++) {
// bm128 tmp = grid[d];
// tmp &= all;
// bm128 tmp2 = tmp;
// tmp2 &= duplicates;
// triplicates |= tmp2;
// duplicates |= tmp;
// all |= grid[d];
// }
// all &= constraints::mask81; //clear other bits
// all.clearBits(triplicates);
//}
template <class X> int fsss2<X>::findLeastPopulatedCells(bm128& all) const {
//the following code is written by a member of http://forum.enjoysudoku.com known by pseudonym Blue
//it returns the cells with less number of candidates and works for 0 to 9 candidates (4-bit sum)
bm128 sum0 = grid[0];
bm128 sum1 = grid[1];
bm128 tmp = sum0;
sum0 ^= sum1;
sum1 &= tmp;
bm128 carry = grid[2];