forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdmoves.cpp
More file actions
7803 lines (6565 loc) · 328 KB
/
Copy pathsdmoves.cpp
File metadata and controls
7803 lines (6565 loc) · 328 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:3; fill-column:88 -*-
// SD -- square dance caller's helper.
//
// Copyright (C) 1990-2013 William B. Ackerman.
//
// This file is part of "Sd".
//
// ===================================================================
//
// If you received this file with express permission from the licensor
// to modify and redistribute it it under the terms of the Creative
// Commons CC BY-NC-SA 3.0 license, then that license applies. See
// http://creativecommons.org/licenses/by-nc-sa/3.0/
//
// ===================================================================
//
// Otherwise, the GNU General Public License applies.
//
// Sd is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Sd is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License,
// in the file COPYING.txt, along with Sd. See
// http://www.gnu.org/licenses/
//
// ===================================================================
//
// This is for version 38.
/* This defines the following functions:
canonicalize_rotation
reinstate_rotation
remove_mxn_spreading
do_1x3_type_expansion
divide_for_magic
do_simple_split
do_call_in_series
initialize_matrix_position_tables
drag_someone_and_move
anchor_someone_and_move
process_number_insertion
get_real_subcall
gcd
process_fractions
fraction_info::get_fraction_info
fraction_info::get_fracs_for_this_part
fraction_info::query_instant_stop
try_to_get_parts_from_parse_pointer
fill_active_phantoms_and_move
move_perhaps_with_active_phantoms
impose_assumption_and_move
really_inner_move
move
*/
#include <stdio.h>
#include <string.h>
#include "sd.h"
extern void canonicalize_rotation(setup *result) THROW_DECL
{
result->rotation &= 3;
if (result->kind == s1x1) {
result->rotate_person(0, (result->rotation) * 011);
result->rotation = 0;
}
else if (result->kind == s_normal_concentric) {
int i;
if (result->inner.skind == s_normal_concentric ||
result->outer.skind == s_normal_concentric ||
result->inner.skind == s_dead_concentric ||
result->outer.skind == s_dead_concentric)
fail("Recursive concentric?????.");
int save_rotation = result->rotation;
result->kind = result->inner.skind;
result->rotation += result->inner.srotation;
canonicalize_rotation(result); // Sorry!
result->inner.srotation = result->rotation;
result->kind = result->outer.skind;
result->rotation = save_rotation + result->outer.srotation;
for (i=0 ; i<12 ; i++) result->swap_people(i, i+12);
canonicalize_rotation(result); // Sorrier!
for (i=0 ; i<12 ; i++) result->swap_people(i, i+12);
result->outer.srotation = result->rotation;
result->kind = s_normal_concentric;
result->rotation = 0;
}
else if (result->kind == s_dead_concentric) {
if (result->inner.skind == s_normal_concentric || result->inner.skind == s_dead_concentric)
fail("Recursive concentric?????.");
result->kind = result->inner.skind;
result->rotation += result->inner.srotation;
canonicalize_rotation(result); // Sorry!
result->inner.srotation = result->rotation;
result->kind = s_dead_concentric;
result->rotation = 0;
}
else if (setup_attrs[result->kind].four_way_symmetry) {
// The setup has 4-way symmetry. We can canonicalize it so the
// result rotation is zero.
int i, rot, rot11, delta, bigd, i0, i1, i2, i3, j0, j1, j2, j3;
personrec x0, x1, x2, x3;
rot = result->rotation;
if (rot == 0) return;
rot11 = rot * 011;
bigd = attr::slimit(result) + 1;
if (result->kind == s3x3) bigd = 8;
delta = bigd >> 2;
i0 = 1;
i1 = i0 + delta;
i2 = i1 + delta;
i3 = i2 + delta;
j0 = (rot-4)*delta+1;
j1 = j0 + delta;
j2 = j1 + delta;
j3 = j2 + delta;
for (i=0; i<delta; i++) {
if ((--i0) < 0) i0 += bigd;
if ((--i1) < 0) i1 += bigd;
if ((--i2) < 0) i2 += bigd;
if ((--i3) < 0) i3 += bigd;
if ((--j0) < 0) j0 += bigd;
if ((--j1) < 0) j1 += bigd;
if ((--j2) < 0) j2 += bigd;
if ((--j3) < 0) j3 += bigd;
x0 = result->people[i0];
x1 = result->people[i1];
x2 = result->people[i2];
x3 = result->people[i3];
result->people[j0].id1 = rotperson(x0.id1, rot11);
result->people[j0].id2 = x0.id2;
result->people[j0].id3 = x0.id3;
result->people[j1].id1 = rotperson(x1.id1, rot11);
result->people[j1].id2 = x1.id2;
result->people[j1].id3 = x1.id3;
result->people[j2].id1 = rotperson(x2.id1, rot11);
result->people[j2].id2 = x2.id2;
result->people[j2].id3 = x2.id3;
result->people[j3].id1 = rotperson(x3.id1, rot11);
result->people[j3].id2 = x3.id2;
result->people[j3].id3 = x3.id3;
}
if (result->kind == s3x3) result->people[8].id1 = rotperson(result->people[8].id1, rot11);
result->rotation = 0;
}
else if (setup_attrs[result->kind].no_symmetry) {
}
else if (result->kind == s1x3) {
if (result->rotation & 2) {
// Must turn this setup upside-down.
result->swap_people(0, 2);
for (int i=0; i<3; i++)
result->rotate_person(i, 022);
}
result->rotation &= 1;
}
else if (result->kind == s1x5) {
if (result->rotation & 2) {
// Must turn this setup upside-down.
result->swap_people(0, 3);
result->swap_people(1, 4);
for (int i=0; i<5; i++)
result->rotate_person(i, 022);
}
result->rotation &= 1;
}
else if (((attr::slimit(result) & ~07776) == 1)) {
// We have a setup of an even number of people. We know how to canonicalize
// this. The resulting rotation should be 0 or 1.
if (result->rotation & 2) {
// Must turn this setup upside-down.
int offs = (attr::slimit(result)+1) >> 1; // Half the setup size.
for (int i=0; i<offs; i++) {
result->swap_people(i, i+offs);
result->rotate_person(i, 022);
result->rotate_person(i+offs, 022);
}
}
result->rotation &= 1;
}
}
extern void reinstate_rotation(const setup *ss, setup *result) THROW_DECL
{
int globalrotation;
switch (ss->kind) {
case s_dead_concentric:
case s_normal_concentric:
globalrotation = 0;
break;
default:
globalrotation = ss->rotation;
}
switch (result->kind) {
case s_normal_concentric:
result->inner.srotation += globalrotation;
result->outer.srotation += globalrotation;
break;
case s_dead_concentric:
result->inner.srotation += globalrotation;
if ((globalrotation & 1) && ((result->concsetup_outer_elongation + 1) & 2))
result->concsetup_outer_elongation ^= 3;
break;
case nothing:
break;
default:
result->rotation += globalrotation;
break;
}
if (ss->eighth_rotation) {
result->eighth_rotation ^= 1;
if (!result->eighth_rotation)
result->rotation++;
}
// If we turned by 90 degrees, we have to to swap the "split_info" fields.
if (globalrotation & 1)
result->result_flags.swap_split_info_fields();
canonicalize_rotation(result);
}
static const expand::thing exp72 = {{1, 3, 4, 5, 7, 9, 10, 11}, s2x4, s2x6, 0, 0, 07272};
static const expand::thing exp27 = {{0, 1, 2, 4, 6, 7, 8, 10}, s2x4, s2x6, 0, 0, 02727};
static const expand::thing exp52 = {{1, 3, 5, 7, 9, 11}, s2x3, s2x6, 0, 0, 05252};
static const expand::thing exp25 = {{0, 2, 4, 6, 8, 10}, s2x3, s2x6, 0, 0, 02525};
static const expand::thing exp56 = {{1, 2, 3, 5, 7, 8, 9, 11}, s2x4, s2x6, 0, 0, 05656};
static const expand::thing exp65 = {{0, 2, 4, 5, 6, 8, 10, 11}, s2x4, s2x6, 0, 0, 06565};
static const expand::thing exp35 = {{0, 2, 3, 4, 6, 8, 9, 10}, s2x4, s2x6, 0, 0, 03535};
static const expand::thing exp53 = {{0, 1, 3, 5, 6, 7, 9, 11}, s2x4, s2x6, 0, 0, 05353};
static const expand::thing exp3u = {{1, 3, 4, 5, 6, 7, 8, 10}, s2x4, s2x6, 0, 0, 02772};
static const expand::thing exp3d = {{0, 1, 2, 4, 7, 9, 10, 11}, s2x4, s2x6, 0, 0, 07227};
static const expand::thing exp70 = {{3, 4, 5, 9, 10, 11}, s2x3, s2x6, 0, 0, 07070};
static const expand::thing exp07 = {{0, 1, 2, 6, 7, 8}, s2x3, s2x6, 0, 0, 00707};
static const expand::thing expxF0 = {{4, 5, 6, 7, 12, 13, 14, 15}, s2x4, s2x8, 0, 0, 0xF0F0};
static const expand::thing expx0F = {{0, 1, 2, 3, 8, 9, 10, 11}, s2x4, s2x8, 0, 0, 0x0F0F};
static const expand::thing expxAA = {{1, 3, 5, 7, 9, 11, 13, 15}, s2x4, s2x8, 0, 0, 0xAAAA};
static const expand::thing expx55 = {{0, 2, 4, 6, 8, 10, 12, 14}, s2x4, s2x8, 0, 0, 0x5555};
static const expand::thing exp4x4x71 = {{12, 13, 14, 0, 4, 5, 6, 8}, s2x4, s4x4, 0, 0, 0x7171};
static const expand::thing exp4x4x8E = {{10, 15, 3, 1, 2, 7, 11, 9}, s2x4, s4x4, 0, 0, 0x8E8E};
static const expand::thing exp4x4x17 = {{8, 9, 10, 12, 0, 1, 2, 4}, s2x4, s4x4, 1, 0, 0x1717};
static const expand::thing exp4x4xE8 = {{6, 11, 15, 13, 14, 3, 7, 5}, s2x4, s4x4, 1, 0, 0xE8E8};
static const expand::thing exp12m = {{9, 10, 1, 3, 4, 7}, s_2x1dmd, s3dmd, 0, 0, 03232};
static const expand::thing exp21m = {{8, 11, 0, 2, 5, 6}, s2x3, s3dmd, 1, 0, 04545};
static const expand::thing exp46 = {{1, 2, 5, 7, 8, 11}, s2x3, s2x6, 0, 0, 04646};
static const expand::thing exp64 = {{2, 4, 5, 8, 10, 11}, s2x3, s2x6, 0, 0, 06464};
static const expand::thing exp54 = {{2, 3, 5, 8, 9, 11}, s2x3, s2x6, 0, 0, 05454};
static const expand::thing exp45 = {{0, 2, 5, 6, 8, 11}, s2x3, s2x6, 0, 0, 04545};
static const expand::thing exp51 = {{0, 3, 5, 6, 9, 11}, s2x3, s2x6, 0, 0, 05151};
static const expand::thing exp15 = {{0, 2, 3, 6, 8, 9}, s2x3, s2x6, 0, 0, 01515};
static const expand::thing exp31 = {{0, 3, 4, 6, 9, 10}, s2x3, s2x6, 0, 0, 03131};
static const expand::thing exp13 = {{0, 1, 3, 6, 7, 9}, s2x3, s2x6, 0, 0, 01313};
static const expand::thing expb31 = {{9, 10, 0, 3, 4, 6}, s2x3, s3x4, 1, 0, 03131};
static const expand::thing expb46 = {{8, 11, 1, 2, 5, 7}, s2x3, s3x4, 1, 0, 04646};
static const expand::thing expl52 = {{1, 3, 5, 7, 9, 11}, s1x6, s1x12, 0, 0, 05252};
static const expand::thing expl25 = {{0, 2, 4, 6, 8, 10}, s1x6, s1x12, 0, 0, 02525};
static const expand::thing expg72 = {{1, 3, 5, 4, 7, 9, 11, 10}, s1x8, s1x12, 0, 0, 07272};
static const expand::thing expg27 = {{0, 1, 4, 2, 6, 7, 10, 8}, s1x8, s1x12, 0, 0, 02727};
static const expand::thing expg56 = {{1, 2, 5, 3, 7, 8, 11, 9}, s1x8, s1x12, 0, 0, 05656};
static const expand::thing expg35 = {{0, 2, 4, 3, 6, 8, 10, 9}, s1x8, s1x12, 0, 0, 03535};
static const expand::thing exprig12a = {{9, 10, 11, 1, 3, 4, 5, 7}, s1x3dmd, srigger12, 0, 0, 07272};
static const expand::thing exprig12b = {{0, 1, 2, 4, 6, 7, 8, 10}, s_spindle, srigger12, 0, 0, 02727};
static const expand::thing expsp3 = {{1, 2, 3, 5, 7, 8, 9, 11}, s_spindle, sd3x4, 0, 0, 05656};
static const expand::thing expd34s6 = {{9, 11, 1, 3, 5, 7}, s_short6, sd3x4, 1, 0, 05252};
static const expand::thing expd3423 = {{0, 2, 4, 6, 8, 10}, s2x3, sd3x4, 0, 0, 02525};
static const expand::thing exp3d3 = {{10, 11, 0, -1, -1, 2, 4, 5, 6, -1, -1, 8}, s3dmd, sd3x4, 1};
static const expand::thing exp323 = {{10, 11, 0, 2, 4, 5, 6, 8}, s_323, sd3x4, 1, 0, 06565};
static const expand::thing exp303 = {{10, 11, 0, 4, 5, 6}, s2x3, sd3x4, 1, 0, 06161};
static const expand::thing exp030 = {{1, 2, 3, 7, 8, 9}, s2x3, sd3x4, 0, 0, 01616};
static const expand::thing exp4141 = {{17, 18, 11, 0, 5, 6, 23, 12}, s2x4, s4x6, 1, 0, 041414141};
static const expand::thing expb51 = {{0, 3, 5, 6, 9, 11}, s_bone6, s3x4, 0, 0, 05151};
static const expand::thing expb26 = {{8, 10, 1, 2, 4, 7}, s_short6, s3x4, 1, 0, 02626};
static const expand::thing expl65 = {{0, 2, 4, 5}, s1x4, s1x6, 0, 0, 065};
static const expand::thing expl56 = {{1, 2, 3, 5}, s1x4, s1x6, 0, 0, 056};
static const expand::thing expl72 = {{1, 5, 3, 4}, s1x4, s1x6, 0, 0, 072};
static const expand::thing expl27 = {{0, 1, 4, 2}, s1x4, s1x6, 0, 0, 027};
void fix_roll_transparency_stupidly(const setup *ss, setup *result)
{
// Can only do this if we understand the setups, as indicated by the "slimit" being defined.
if ((ss->cmd.cmd_misc3_flags & (CMD_MISC3__ROLL_TRANSP|CMD_MISC3__ROLL_TRANSP_IF_Z)) != 0 &&
(attr::slimit(result) >= 0) &&
(attr::slimit(ss) >= 0)) {
// We may turn on the "moving_people_cant_roll" flag. But only if the
// the starting and ending setups are the same. (If they aren't the same,
// we can't tell whether people moved.) In this case, we only perform
// the special "roll_transparent" operation for people who didn't move
// to a different location. For people who moved, we leave their
// roll-neutral status in place.
//
// This is required for "and cross" in such things as percolate.
// Everyone has hinged and therefore has roll direction. The "and
// cross" is invoked with "roll_transparent" on, so that the people
// who don't move on the "and cross" will still be able to roll.
// But the people who crossed need to preserve their "ZM" status
// and not have it reset to the previous call.
bool moving_people_cant_roll = ss->cmd.callspec &&
(ss->cmd.callspec->the_defn.callflagsf & CFLAG2_IF_MOVE_CANT_ROLL) != 0 &&
result->kind == ss->kind;
for (int u=0; u<=attr::slimit(result); u++) {
uint32 *thispid1 = &result->people[u].id1;
if (*thispid1) {
uint32 rollinfo = *thispid1 & ROLL_DIRMASK;
// Look for people marked "M", that is, roll-neutral.
// But if in "DFM1_ROLL_TRANSPARENT_IF_Z" mode, also look for people marked undefined,
// and force them to "M" rather than being transparent.
if ((ss->cmd.cmd_misc3_flags & CMD_MISC3__ROLL_TRANSP_IF_Z) != 0 && rollinfo == 0) {
*thispid1 |= ROLL_IS_M;
}
else if (rollinfo == ROLL_DIRMASK) {
// This person is roll-neutral. Reinstate his original roll info.
// But do *NOT* restore his "this person moved" bit from its
// previous state. Leave it in its current state.
// But we do *NOT* do this if the before and after setups
// were the same, the call was marked "moving_people_cant_roll",
// and the person finished on a different spot.
// Find this person in the starting setup.
int v;
for (v=0; v<=attr::slimit(ss); v++) {
if (((*thispid1 ^ ss->people[v].id1) & (XPID_MASK|BIT_PERSON)) == 0) {
break;
}
}
if (v > attr::slimit(ss))
fail("INTERNAL ERROR: LOST SOMEONE!!!!!");
*thispid1 &= ~ROLL_DIRMASK;
if (moving_people_cant_roll && (u != v)) {
*thispid1 |= ROLL_IS_M; // This person moved. Take away his rollability.
}
else {
*thispid1 |= (ss->people[v].id1 & ROLL_DIRMASK); // Restore rollability from original.
}
}
}
}
}
}
extern void remove_mxn_spreading(setup *ss) THROW_DECL
{
if (!(ss->result_flags.misc & RESULTFLAG__DID_MXN_EXPANSION))
return;
uint32 livemasklittle = little_endian_live_mask(ss);
static const expand::thing *unwind_2x6_table[] = {
&exp52, &exp25, &exp72, &exp27,
&exp56, &exp65, &exp35, &exp53,
&exp46, &exp64, &exp54, &exp45,
&exp51, &exp15, &exp31, &exp13,
&exp70, &exp07,
(const expand::thing *) 0};
static const expand::thing *unwind_2x8_table[] = {
&expx0F, &expxF0, &expx55, &expxAA,
(const expand::thing *) 0};
static const expand::thing *unwind_4x4_table[] = {
&exp4x4x71, &exp4x4x8E, &exp4x4x17, &exp4x4xE8,
(const expand::thing *) 0};
static const expand::thing *unwind_3dmd_table[] = {
&exp12m, &exp21m,
(const expand::thing *) 0};
static const expand::thing *unwind_3x4_table[] = {
&s_qtg_3x4, &expb51, &expb26, &expb31, &expb46,
(const expand::thing *) 0};
static const expand::thing *unwind_1x6_table[] = {
&expl72, &expl27, &expl56, &expl65,
(const expand::thing *) 0};
static const expand::thing *unwind_d3x4_table[] = {
&exp323, &exp303, &expsp3, &expd34s6, &expd3423, &exp030,
(const expand::thing *) 0};
static const expand::thing *unwind_1x12_table[] = {
&expl52, &expl25, &expg72, &expg27, &expg56, &expg35,
(const expand::thing *) 0};
static const expand::thing *unwind_rigger12_table[] = {
&exprig12a, &exprig12b,
(const expand::thing *) 0};
static const expand::thing *unwind_4x6_table[] = {
&exp4141,
(const expand::thing *) 0};
const expand::thing **p = (const expand::thing **) 0;
switch (ss->kind) {
case s2x8:
p = unwind_2x8_table;
break;
case s4x4:
p = unwind_4x4_table;
break;
case s2x6:
p = unwind_2x6_table;
break;
case s3dmd:
p = unwind_3dmd_table;
break;
case s3x4:
p = unwind_3x4_table;
break;
case s1x6:
p = unwind_1x6_table;
break;
case sd3x4:
p = unwind_d3x4_table;
break;
case s1x12:
p = unwind_1x12_table;
break;
case srigger12:
p = unwind_rigger12_table;
break;
case s4x6:
p = unwind_4x6_table;
break;
}
const expand::thing *final = (const expand::thing *) 0;
if (p) {
for ( ; *p ; p++) {
if (livemasklittle == (*p)->biglivemask) {
// Exact match, accept it immediately. We know it's unambiguous.
final = *p;
break;
}
else if ((livemasklittle & ~(*p)->biglivemask) == 0) {
if (final) return; // Ambiguous.
final = *p;
}
}
if (final) {
expand::compress_setup(*final, ss);
if (final == &expg72)
ss->result_flags.misc |= RESULTFLAG__VERY_ENDS_ODD;
else if (final == &expg27)
ss->result_flags.misc |= RESULTFLAG__VERY_CTRS_ODD;
ss->result_flags.misc &= ~RESULTFLAG__DID_MXN_EXPANSION;
}
}
}
extern bool do_1x3_type_expansion(setup *ss, uint32 heritflags_to_check) THROW_DECL
{
struct Nx1_checker {
uint32 directions;
bool unsymm;
const expand::thing *action_if_Nx1;
const expand::thing *action_if_1xN;
};
static const Nx1_checker Nx1_checktable_2x4[] = {
{0x2A80, false, &exp72, &exp72}, // These are independent of whether we said "1x3" or "3x1".
{0x6AC0, false, &exp72, &exp72},
{0xEA40, false, &exp72, &exp72},
// Then swap
{0x802A, false, &exp72, &exp72},
{0xC06A, false, &exp72, &exp72},
{0x40EA, false, &exp72, &exp72},
{0x7FD5, false, &exp72, &exp72},
{0x3F95, false, &exp72, &exp72},
{0xBF15, false, &exp72, &exp72},
// Then swap
{0xD57F, false, &exp72, &exp72},
{0x953F, false, &exp72, &exp72},
{0x15BF, false, &exp72, &exp72},
{0xA802, false, &exp27, &exp27},
{0xA903, false, &exp27, &exp27},
{0xAB01, false, &exp27, &exp27},
// Then swap
{0x02A8, false, &exp27, &exp27},
{0x03A9, false, &exp27, &exp27},
{0x01AB, false, &exp27, &exp27},
{0xFD57, false, &exp27, &exp27},
{0xFC56, false, &exp27, &exp27},
{0xFE54, false, &exp27, &exp27},
// Then swap
{0x57FD, false, &exp27, &exp27},
{0x56FC, false, &exp27, &exp27},
{0x54FE, false, &exp27, &exp27},
{0x208A, false, &exp56, &exp56},
{0x8A20, false, &exp56, &exp56},
{0x75DF, false, &exp56, &exp56},
{0xDF75, false, &exp56, &exp56},
{0xA208, false, &exp35, &exp35},
{0x08A2, false, &exp35, &exp35},
{0xF75D, false, &exp35, &exp35},
{0x5DF7, false, &exp35, &exp35},
{0x2AA8, true, &exp3u, &exp3u}, // These 8 are unsymmetrical.
{0x8002, true, &exp3u, &exp3u},
{0x7FFD, true, &exp3u, &exp3u},
{0xD557, true, &exp3u, &exp3u},
{0xA82A, true, &exp3d, &exp3d},
{0x0280, true, &exp3d, &exp3d},
{0xFD7F, true, &exp3d, &exp3d},
{0x57D5, true, &exp3d, &exp3d},
{0x55FF, false, &exp72, &exp27}, // These are specific to "1x3" or "3x1".
{0x00AA, false, &exp72, &exp27},
{0xFF55, false, &exp27, &exp72},
{0xAA00, false, &exp27, &exp72},
{0}};
static const Nx1_checker Nx0_checktable_2x3[] = {
{02577, false, &exp70, &exp07},
{00052, false, &exp70, &exp07},
{07725, false, &exp07, &exp70},
{05200, false, &exp07, &exp70},
{0}};
static const Nx1_checker Nx0_checktable_2x4[] = {
{0x55FF, false, &expxF0, &expx0F},
{0x00AA, false, &expxF0, &expx0F},
{0xFF55, false, &expx0F, &expxF0},
{0xAA00, false, &expx0F, &expxF0},
{0}};
static const Nx1_checker Nx1_checktable_1x8[] = {
{0x2A80, false, &expg72, &expg72}, // These are independent of whether we said "1x3" or "3x1".
{0x802A, false, &expg72, &expg72},
{0x7FD5, false, &expg72, &expg72},
{0xD57F, false, &expg72, &expg72},
{0xA208, false, &expg27, &expg27},
{0x08A2, false, &expg27, &expg27},
{0xF75D, false, &expg27, &expg27},
{0x5DF7, false, &expg27, &expg27},
{0x208A, false, &expg56, &expg56},
{0x8A20, false, &expg56, &expg56},
{0x75DF, false, &expg56, &expg56},
{0xDF75, false, &expg56, &expg56},
{0xA802, false, &expg35, &expg35},
{0x02A8, false, &expg35, &expg35},
{0xFD57, false, &expg35, &expg35},
{0x57FD, false, &expg35, &expg35},
{0x55FF, false, &expg72, &expg27}, // These are specific to "1x3" or "3x1".
{0x00AA, false, &expg72, &expg27},
{0xFF55, false, &expg27, &expg72},
{0xAA00, false, &expg27, &expg72},
{0}};
static const Nx1_checker Nx1_checktable_2x3[] = {
{01240, false, &exp52, &exp52}, // These are independent of whether we said "1x2" or "2x1".
{04012, false, &exp52, &exp52},
{03765, false, &exp52, &exp52},
{06537, false, &exp52, &exp52},
{05002, false, &exp25, &exp25},
{00250, false, &exp25, &exp25},
{07527, false, &exp25, &exp25},
{02775, false, &exp25, &exp25},
{02577, false, &exp52, &exp25}, // These are specific to "1x2" or "2x1".
{00052, false, &exp52, &exp25},
{07725, false, &exp25, &exp52},
{05200, false, &exp25, &exp52},
{0}};
static const Nx1_checker Nx1_checktable_1x6[] = {
{01240, false, &expl52, &expl52}, // These are independent of whether we said "1x2" or "2x1".
{04012, false, &expl52, &expl52},
{03765, false, &expl52, &expl52},
{06537, false, &expl52, &expl52},
{05002, false, &expl25, &expl25},
{00250, false, &expl25, &expl25},
{07527, false, &expl25, &expl25},
{02775, false, &expl25, &expl25},
{02577, false, &expl52, &expl25}, // These are specific to "1x2" or "2x1".
{00052, false, &expl52, &expl25},
{07725, false, &expl25, &expl52},
{05200, false, &expl25, &expl52},
{0}};
uint32 directions;
uint32 dblbitlivemask;
const Nx1_checker *getin_search;
uint32 full_occupation = (uint32) ((1U << ((attr::klimit(ss->kind)+1) << 1)) - 1);
big_endian_get_directions(ss, directions, dblbitlivemask);
if (heritflags_to_check == INHERITFLAGMXNK_3X1 ||
heritflags_to_check == INHERITFLAGMXNK_1X3) {
if (ss->kind == s2x4) {
getin_search = Nx1_checktable_2x4;
goto do_Nx1_search;
}
else if (ss->kind == s1x8) {
getin_search = Nx1_checktable_1x8;
goto do_Nx1_search;
}
else if (ss->kind == s3x4) {
if (dblbitlivemask == 0x3CF3CF || dblbitlivemask == 0xC3FC3F ||
dblbitlivemask == 0x33FCCF || dblbitlivemask == 0xCCF33F) return true;
}
else if (ss->kind == s2x6) {
if (dblbitlivemask == 0x33F33F || dblbitlivemask == 0xFCCFCC ||
dblbitlivemask == 0x30CFFF || dblbitlivemask == 0xFFF30C) return true;
}
else if (ss->kind == s_spindle) {
if (dblbitlivemask == 0xFFFF) {
expand::expand_setup(expsp3, ss);
return true;
}
}
else if (ss->kind == s3dmd) {
if (dblbitlivemask == 0xFC3FC3) {
expand::expand_setup(exp3d3, ss);
return true;
}
}
else if (ss->kind == s_323) {
if (dblbitlivemask == 0xFFFF) {
expand::expand_setup(exp323, ss);
return true;
}
}
else if (ss->kind == s2x3) {
if (dblbitlivemask == 0x33F || dblbitlivemask == 0xFCC) return true;
}
}
else if (heritflags_to_check == INHERITFLAGMXNK_2X1 ||
heritflags_to_check == INHERITFLAGMXNK_1X2) {
if (ss->kind == s2x3) {
getin_search = Nx1_checktable_2x3;
goto do_Nx1_search;
}
else if (ss->kind == s1x6) {
getin_search = Nx1_checktable_1x6;
goto do_Nx1_search;
}
else if (ss->kind == s_bone6) {
if (directions == 01240 || directions == 04012 ||
directions == 01042 || directions == 04210 ||
directions == 03765 || directions == 06537 ||
directions == 03567 || directions == 06735) {
expand::expand_setup(expb51, ss);
return true;
}
}
else if (ss->kind == s_short6) {
if (directions == 00052 || directions == 05200 ||
directions == 07725 || directions == 02577 ||
directions == 03567 || directions == 06735 ||
directions == 01042 || directions == 04210) {
expand::expand_setup(expb26, ss);
return true;
}
}
}
else if (heritflags_to_check == INHERITFLAGMXNK_4X0 ||
heritflags_to_check == INHERITFLAGMXNK_0X4) {
if (ss->kind == s2x4) {
getin_search = Nx0_checktable_2x4;
goto do_Nx1_search;
}
}
else if (heritflags_to_check == INHERITFLAGMXNK_3X0 ||
heritflags_to_check == INHERITFLAGMXNK_0X3) {
if (ss->kind == s2x3) {
getin_search = Nx0_checktable_2x3;
goto do_Nx1_search;
}
}
return false;
do_Nx1_search:
// Search the table for a unique getin map.
// *** We used to check only the direction bits that were masked on by dblbitlivemask,
// and demand that the result be unique. (That's what the "if (final) return false"
// is about.) We also used to try not to demand that dblbitlivemask have all bits
// on. But that really doesn't work. We can't search for hard Nx1 and 1xN
// formulations in the presence of phantoms.
const expand::thing *highquality = (const expand::thing *) 0;
const expand::thing *lowquality = (const expand::thing *) 0;
bool lowqualityisambiguous = false;
for ( ; getin_search->directions ; getin_search++) {
if (((getin_search->directions ^ directions) & dblbitlivemask) == 0) {
// Unsymmetrical maps require full occupation.
if (getin_search->unsymm && dblbitlivemask != full_occupation)
continue;
if (getin_search->action_if_Nx1 != getin_search->action_if_1xN) {
// This is a high quality map. It can tell what to do without requiring lots of people.
if (highquality) return false; // If high quality maps are ambiguous, we lose.
highquality = (heritflags_to_check == INHERITFLAGMXNK_3X1 ||
heritflags_to_check == INHERITFLAGMXNK_4X0 ||
heritflags_to_check == INHERITFLAGMXNK_3X0 ||
heritflags_to_check == INHERITFLAGMXNK_2X1) ?
getin_search->action_if_Nx1 :
getin_search->action_if_1xN;
}
else {
// This is a low quality map. Ambiguity is OK, up to two, if a high quality map is present.
if (lowquality) lowqualityisambiguous = true;
lowquality = getin_search->action_if_Nx1;
}
}
}
if (!highquality) {
// No high quality map; must use an unambiguous low quality one.
if (lowqualityisambiguous)
return false;
highquality = lowquality;
}
if (highquality) {
expand::expand_setup(*highquality, ss);
return true;
}
return false;
}
extern bool divide_for_magic(
setup *ss,
uint32 heritflags_to_check,
setup *result) THROW_DECL
{
warning_info saved_warnings;
uint32 division_code;
uint32 heritflags_to_use = ss->cmd.cmd_final_flags.herit;
// If "magic" was specified, we have to be sure the level is
// high enough (e.g. C3B). At C1, only real magic columns,
// and whatever calls have something explicit in the database,
// are permitted.
if (heritflags_to_check & INHERITFLAG_MAGIC) {
bool booljunk;
assumption_thing tt;
tt.assumption = cr_magic_only;
tt.assump_col = 1;
tt.assump_both = 0;
tt.assump_negate = 0;
tt.assump_live = 0;
tt.assump_cast = 0;
if (ss->kind != s2x4 || verify_restriction(ss, tt, false, &booljunk) != restriction_passes) {
if (calling_level < general_magic_level)
warn_about_concept_level();
}
}
switch (ss->kind) {
case s2x4:
if (heritflags_to_check == INHERITFLAG_MAGIC) {
// "Magic" was specified. Split it into 1x4's
// in the appropriate magical way.
division_code = MAPCODE(s1x4,2,MPKIND__MAGIC,1);
goto divide_us;
}
break;
case s_qtag:
// Indicate that we have done a diamond division
// and the concept name needs to be changed.
ss->cmd.cmd_misc3_flags |= CMD_MISC3__NEED_DIAMOND;
if (heritflags_to_check == INHERITFLAG_MAGIC) {
division_code = MAPCODE(sdmd,2,MPKIND__MAGIC,1);
goto divide_us;
}
else if (heritflags_to_check == INHERITFLAG_INTLK) {
division_code = MAPCODE(sdmd,2,MPKIND__INTLKDMD,1);
goto divide_us;
}
else if (heritflags_to_check == (INHERITFLAG_MAGIC | INHERITFLAG_INTLK)) {
division_code = MAPCODE(sdmd,2,MPKIND__MAGICINTLKDMD,1);
goto divide_us;
}
else if (heritflags_to_check == INHERITFLAGMXNK_3X1 ||
heritflags_to_check == INHERITFLAGMXNK_1X3) {
expand::expand_setup(s_qtg_3x4, ss);
goto do_3x3;
}
break;
case s_ptpd:
ss->cmd.cmd_misc3_flags |= CMD_MISC3__NEED_DIAMOND;
if (heritflags_to_check == INHERITFLAG_MAGIC) {
division_code = spcmap_ptp_magic;
goto divide_us;
}
else if (heritflags_to_check == INHERITFLAG_INTLK) {
division_code = spcmap_ptp_intlk;
goto divide_us;
}
else if (heritflags_to_check == (INHERITFLAG_MAGIC | INHERITFLAG_INTLK)) {
division_code = spcmap_ptp_magic_intlk;
goto divide_us;
}
break;
}
// Now check for 1x3 types of stuff.
if (heritflags_to_check == INHERITFLAGMXNK_3X1 ||
heritflags_to_check == INHERITFLAGMXNK_1X3 ||
heritflags_to_check == INHERITFLAGMXNK_3X0 ||
heritflags_to_check == INHERITFLAGMXNK_0X3 ||
heritflags_to_check == INHERITFLAGMXNK_4X0 ||
heritflags_to_check == INHERITFLAGMXNK_0X4 ||
heritflags_to_check == INHERITFLAGMXNK_2X1 ||
heritflags_to_check == INHERITFLAGMXNK_1X2) {
// If we have already expanded, don't do it again.
if (ss->cmd.cmd_heritflags_to_save_from_mxn_expansion != heritflags_to_check) {
if (do_1x3_type_expansion(ss, heritflags_to_check))
goto do_3x3;
}
else {
goto do_3x3;
}
}
return false;
divide_us:
ss->cmd.cmd_final_flags.herit = (heritflags) (heritflags_to_use & ~heritflags_to_check);
divided_setup_move(ss, division_code, phantest_ok, true, result);
return true;
do_3x3:
bool sixteen = (heritflags_to_use == INHERITFLAGMXNK_0X4 || heritflags_to_use == INHERITFLAGMXNK_4X0);
ss->cmd.cmd_final_flags.herit = (heritflags)
((heritflags_to_use & ~(INHERITFLAG_MXNMASK|INHERITFLAG_NXNMASK)) |
(sixteen ? INHERITFLAGNXNK_4X4 : INHERITFLAGNXNK_3X3));
if (attr::slimit(ss) > 7)
ss->cmd.cmd_final_flags.set_heritbit(sixteen ? INHERITFLAG_16_MATRIX : INHERITFLAG_12_MATRIX);
saved_warnings = configuration::save_warnings();
impose_assumption_and_move(ss, result);
result->result_flags.misc |= RESULTFLAG__DID_MXN_EXPANSION;
result->result_flags.res_heritflags_to_save_from_mxn_expansion =
heritflags_to_use & (INHERITFLAG_MXNMASK|INHERITFLAG_NXNMASK);
// Shut off "each 2x3" types of warnings -- they will arise spuriously
// while the people do the calls in isolation.
configuration::clear_multiple_warnings(dyp_each_warnings);
configuration::set_multiple_warnings(saved_warnings);
return true;
}
extern bool do_simple_split(
setup *ss,
split_command_kind split_command,
setup *result) THROW_DECL
{
uint32 mapcode;
bool recompute_id = true;
ss->cmd.cmd_misc_flags &= ~CMD_MISC__MUST_SPLIT_MASK;
switch (ss->kind) {
case s3x4:
if (split_command == split_command_2x3) {
mapcode = MAPCODE(s2x3,2,MPKIND__SPLIT,1);
break;
}
else if (split_command == split_command_none) {
if (ss->people[0].id1 & ss->people[1].id1 &
ss->people[4].id1 & ss->people[5].id1 &
ss->people[6].id1 & ss->people[7].id1 &
ss->people[10].id1 & ss->people[11].id1) {
mapcode = MAPCODE(s2x2,2,MPKIND__OFFS_R_HALF,0);
break;
}
else if (ss->people[2].id1 & ss->people[3].id1 &
ss->people[4].id1 & ss->people[5].id1 &
ss->people[8].id1 & ss->people[9].id1 &
ss->people[10].id1 & ss->people[11].id1) {
mapcode = MAPCODE(s2x2,2,MPKIND__OFFS_L_HALF,0);
break;
}
}
return true;
case s2x4:
mapcode = (split_command == split_command_none) ?
MAPCODE(s2x2,2,MPKIND__SPLIT,0) : MAPCODE(s1x4,2,MPKIND__SPLIT,1);
break;
case s2x6:
if (split_command == split_command_2x3) {
mapcode = MAPCODE(s2x3,2,MPKIND__SPLIT,0);
break;
}
else if (split_command == split_command_1x4) {
if (ss->cmd.cmd_heritflags_to_save_from_mxn_expansion == INHERITFLAGMXNK_3X1 ||
ss->cmd.cmd_heritflags_to_save_from_mxn_expansion == INHERITFLAGMXNK_1X3 ||
ss->cmd.cmd_heritflags_to_save_from_mxn_expansion == INHERITFLAGMXNK_2X1 ||
ss->cmd.cmd_heritflags_to_save_from_mxn_expansion == INHERITFLAGMXNK_1X2) {
mapcode = MAPCODE(s1x6,2,MPKIND__SPLIT,1);
break;
}
else if (ss->people[0].id1 & ss->people[1].id1 &
ss->people[2].id1 & ss->people[3].id1 &
ss->people[6].id1 & ss->people[7].id1 &
ss->people[8].id1 & ss->people[9].id1) {
mapcode = MAPCODE(s1x4,2,MPKIND__OFFS_L_HALF,1);
break;
}
else if (ss->people[2].id1 & ss->people[3].id1 &
ss->people[4].id1 & ss->people[5].id1 &
ss->people[8].id1 & ss->people[9].id1 &
ss->people[10].id1 & ss->people[11].id1) {
mapcode = MAPCODE(s1x4,2,MPKIND__OFFS_R_HALF,1);
break;
}
}
fail("Can't figure out how to split this call.");
case s1x8:
mapcode = MAPCODE(s1x4,2,MPKIND__SPLIT,0);
if (split_command == split_command_1x8) recompute_id = false;
break;
case s_qtag:
mapcode = MAPCODE(sdmd,2,MPKIND__SPLIT,1);