forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdconc.cpp
More file actions
7057 lines (6233 loc) · 285 KB
/
Copy pathsdconc.cpp
File metadata and controls
7057 lines (6233 loc) · 285 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:
get_multiple_parallel_resultflags
initialize_sel_tables
initialize_fix_tables
conc_tables::initialize
conc_tables::analyze_this
conc_tables::synthesize_this
normalize_concentric
concentric_move
merge_table::map_tgl4l
merge_table::map_tgl4b
merge_table::map_2234b
merge_table::map_24r24a
merge_table::map_24r24b
merge_table::map_24r24c
merge_table::map_24r24d
merge_table::initialize
merge_table::lookup
merge_table::merge_setups
on_your_own_move
punt_centers_use_concept
selective_move
inner_selective_move
*/
#include "sd.h"
#define CONTROVERSIAL_CONC_ELONG 0x200
extern resultflag_rec get_multiple_parallel_resultflags(setup outer_inners[], int number) THROW_DECL
{
resultflag_rec result_flags;
result_flags.clear_split_info();
result_flags.misc = 0;
result_flags.res_heritflags_to_save_from_mxn_expansion = 0;
bool clear_split_fields = false; // In case we have to clear both fields.
// If a call was being done "piecewise" or "random", we demand that both
// calls run out of parts at the same time, and, when that happens, we
// report it to the higher level in the recursion.
for (int i=0 ; i<number ; i++) {
if (!(outer_inners[i].result_flags.misc & RESULTFLAG__PARTS_ARE_KNOWN))
outer_inners[i].result_flags.misc &= ~(RESULTFLAG__DID_LAST_PART|RESULTFLAG__SECONDARY_DONE);
if (((outer_inners[i].result_flags.misc & outer_inners[0].result_flags.misc) & RESULTFLAG__PARTS_ARE_KNOWN) &&
((outer_inners[i].result_flags.misc ^ outer_inners[0].result_flags.misc) & (RESULTFLAG__DID_LAST_PART|RESULTFLAG__SECONDARY_DONE)))
fail("Two calls must use the same number of fractions.");
result_flags.misc |= outer_inners[i].result_flags.misc;
if (i == 0)
result_flags.copy_split_info(outer_inners[i].result_flags);
else {
// For each field (X or Y), if both setups have nonzero values but
// those values don't match, that field gets cleared.
if (result_flags.split_info[0] != outer_inners[i].result_flags.split_info[0] &&
result_flags.split_info[0] != 0 &&
outer_inners[i].result_flags.split_info[0] != 0)
clear_split_fields = true;
if (result_flags.split_info[1] != outer_inners[i].result_flags.split_info[1] &&
result_flags.split_info[1] != 0 &&
outer_inners[i].result_flags.split_info[1] != 0)
clear_split_fields = true;
result_flags.split_info[0] |= outer_inners[i].result_flags.split_info[0];
result_flags.split_info[1] |= outer_inners[i].result_flags.split_info[1];
}
}
if (clear_split_fields) result_flags.clear_split_info();
return result_flags;
}
select::sel_item *select::sel_hash_table[select::NUM_SEL_HASH_BUCKETS];
select::fixer *select::fixer_ptr_table[fx_ENUM_EXTENT];
void select::initialize()
{
sel_item *selp;
int i;
for (i=0 ; i<NUM_SEL_HASH_BUCKETS ; i++) sel_hash_table[i] = (sel_item *) 0;
for (selp = sel_init_table ; selp->kk != nothing ; selp++) {
uint32 hash_num = (5*selp->kk) & (NUM_SEL_HASH_BUCKETS-1);
selp->next = sel_hash_table[hash_num];
sel_hash_table[hash_num] = selp;
}
fixer *fixp;
for (i=fx0 ; i<fx_ENUM_EXTENT ; i++) fixer_ptr_table[i] = (fixer *) 0;
for (fixp = fixer_init_table ; fixp->mykey != fx0 ; fixp++) {
if (fixer_ptr_table[fixp->mykey])
gg77->iob88.fatal_error_exit(1, "Fixer table initialization failed", "dup");
fixer_ptr_table[fixp->mykey] = fixp;
}
for (i=fx0+1 ; i<fx_ENUM_EXTENT ; i++) {
if (!fixer_ptr_table[i])
gg77->iob88.fatal_error_exit(1, "Fixer table initialization failed", "undef");
}
}
const select::fixer *select::hash_lookup(setup_kind kk, uint32 thislivemask,
bool allow_phantoms,
uint32 key, uint32 arg, const setup *ss)
{
uint32 hash_num = (5*kk) & (NUM_SEL_HASH_BUCKETS-1);
for (const sel_item *p = sel_hash_table[hash_num] ; p ; p = p->next) {
// The livemask must match exactly unless "allow_phantoms" is on.
if ((p->key & key) && p->kk == kk &&
(~p->thislivemask & thislivemask) == 0 &&
(allow_phantoms || p->thislivemask == thislivemask)) {
const fixer *fixp = fixer_ptr_table[p->fixp];
// We make an extremely trivial test here to see which way the distortion goes.
// It will be checked thoroughly later.
if (p->use_fixp2 >= 0 && ((ss->people[p->use_fixp2].id1 ^ arg) & 1))
fixp = fixer_ptr_table[p->fixp2];
return fixp;
}
}
return (const fixer *) 0;
}
conc_tables::cm_thing *conc_tables::conc_hash_synthesize_table[conc_tables::NUM_CONC_HASH_BUCKETS];
conc_tables::cm_thing *conc_tables::conc_hash_analyze_table[conc_tables::NUM_CONC_HASH_BUCKETS];
void conc_tables::initialize()
{
cm_thing *tabp;
int i;
for (i=0 ; i<NUM_CONC_HASH_BUCKETS ; i++) conc_hash_synthesize_table[i] = (cm_thing *) 0;
for (i=0 ; i<NUM_CONC_HASH_BUCKETS ; i++) conc_hash_analyze_table[i] = (cm_thing *) 0;
for (tabp = conc_init_table ; tabp->bigsetup != nothing ; tabp++) {
// For synthesize.
if ((tabp->elongrotallow & 0x100) == 0) {
uint32 hash_num = ((tabp->outsetup + (5*(tabp->insetup + 5*tabp->getout_schema))) * 25) & (NUM_CONC_HASH_BUCKETS-1);
tabp->next_synthesize = conc_hash_synthesize_table[hash_num];
conc_hash_synthesize_table[hash_num] = tabp;
}
// For analyze.
if ((tabp->elongrotallow & 0x200) == 0) {
uint32 hash_num = ((tabp->bigsetup + (5*tabp->lyzer)) * 25) & (NUM_CONC_HASH_BUCKETS-1);
tabp->next_analyze = conc_hash_analyze_table[hash_num];
conc_hash_analyze_table[hash_num] = tabp;
}
tabp->used_mask_analyze = 0;
tabp->used_mask_synthesize = 0;
int mapsize = (attr::klimit(tabp->insetup)+1)*tabp->center_arity +
(attr::klimit(tabp->outsetup)+1);
for (i=0 ; i<mapsize ; i++) {
if (tabp->maps[i] >= 0) {
tabp->used_mask_analyze |= 1 << tabp->maps[i];
tabp->used_mask_synthesize |= 1 << i;
}
}
}
}
static void fix_missing_centers(
setup *inners,
setup *outers,
setup_kind kki,
setup_kind kko,
int center_arity,
bool enforce_kk) THROW_DECL
{
int i;
/* Fix up nonexistent centers, in a rather inept way. */
for (i=0 ; i<center_arity ; i++) {
if (inners[i].kind == nothing) {
inners[i].kind = kki;
inners[i].rotation = 0;
inners[i].eighth_rotation = 0;
inners[i].result_flags = outers->result_flags;
inners[i].clear_people();
}
else if (inners[i].kind != kki && enforce_kk)
fail("Don't recognize concentric ending setup.");
}
if (outers->kind != kko && enforce_kk)
fail("Don't recognize concentric ending setup.");
}
bool conc_tables::analyze_this(
setup *ss,
setup *inners,
setup *outers,
int *center_arity_p,
int & mapelong,
int & inner_rot,
int & outer_rot,
calldef_schema & analyzer)
{
uint32 hash_num = ((ss->kind + (5*analyzer)) * 25) &
(conc_tables::NUM_CONC_HASH_BUCKETS-1);
const conc_tables::cm_thing *lmap_ptr;
for (lmap_ptr = conc_tables::conc_hash_analyze_table[hash_num] ;
lmap_ptr ;
lmap_ptr = lmap_ptr->next_analyze) {
if (lmap_ptr->bigsetup == ss->kind && lmap_ptr->lyzer == analyzer) {
for (int k=0; k<=attr::slimit(ss); k++) {
if (ss->people[k].id1 && !(lmap_ptr->used_mask_analyze & (1<<k)))
goto not_this_one;
}
int inlim = attr::klimit(lmap_ptr->insetup)+1;
int outlim = attr::klimit(lmap_ptr->outsetup)+1;
*center_arity_p = lmap_ptr->center_arity;
outers->kind = lmap_ptr->outsetup;
outers->rotation = (-lmap_ptr->outer_rot) & 3;
outers->eighth_rotation = 0;
gather(outers, ss, &lmap_ptr->maps[inlim*lmap_ptr->center_arity],
outlim-1, lmap_ptr->outer_rot * 011);
for (int m=0; m<lmap_ptr->center_arity; m++) {
uint32 rr = lmap_ptr->inner_rot;
// Need to flip alternating triangles upside down.
if (lmap_ptr->insetup == s_trngl && (m&1)) rr ^= 2;
inners[m].clear_people();
inners[m].kind = lmap_ptr->insetup;
inners[m].rotation = (0-rr) & 3;
inners[m].eighth_rotation = 0;
gather(&inners[m], ss, &lmap_ptr->maps[m*inlim], inlim-1, rr * 011);
}
mapelong = lmap_ptr->mapelong;
inner_rot = lmap_ptr->inner_rot;
outer_rot = lmap_ptr->outer_rot;
return true;
}
not_this_one: ;
}
return false;
}
bool conc_tables::synthesize_this(
setup *inners,
setup *outers,
int center_arity,
uint32 orig_elong_is_controversial,
int relative_rotation,
uint32 matrix_concept,
int outer_elongation,
calldef_schema synthesizer,
calldef_schema orig_synthesizer,
setup *result)
{
int index;
if (inners[0].kind == s_trngl) {
// For triangles, we use the "2" bit of the rotation, demanding that it be even.
if (relative_rotation&1) fail("Ends can't figure out what spots to finish on.");
index = (relative_rotation&2) >> 1;
}
else
index = relative_rotation&1;
uint32 allowmask;
if (outer_elongation == 3)
allowmask = 0x10 << index;
else if (outer_elongation <= 0 || outer_elongation > 3)
allowmask = 5 << index;
else
allowmask = 1 << (index + ((((outer_elongation-1) ^ outers->rotation) & 1) << 1));
if (matrix_concept) allowmask |= 0x40;
if (orig_synthesizer == schema_rev_checkpoint_concept) allowmask |= 0x80;
uint32 hash_num =
((outers->kind + (5*(inners[0].kind + 5*synthesizer))) * 25) &
(conc_tables::NUM_CONC_HASH_BUCKETS-1);
const conc_tables::cm_thing *lmap_ptr;
int q;
int inlim, outlim;
bool reverse_centers_order = false;
for (lmap_ptr = conc_tables::conc_hash_synthesize_table[hash_num] ;
lmap_ptr ;
lmap_ptr = lmap_ptr->next_synthesize) {
if (lmap_ptr->outsetup == outers->kind &&
lmap_ptr->insetup == inners[0].kind &&
lmap_ptr->center_arity == center_arity &&
lmap_ptr->getout_schema == synthesizer &&
(lmap_ptr->elongrotallow & allowmask) == 0) {
// Find out whether inners need to be flipped around.
q = relative_rotation + lmap_ptr->inner_rot - lmap_ptr->outer_rot;
if (q & 1) fail("Sorry, bug 1 in normalize_concentric.");
reverse_centers_order = false;
if (synthesizer != schema_concentric_others &&
synthesizer != schema_3x3k_concentric &&
synthesizer != schema_3x3k_cross_concentric &&
synthesizer != schema_4x4k_concentric &&
synthesizer != schema_4x4k_cross_concentric) { // This test is a crock!!!!!
if ((outers->rotation + lmap_ptr->outer_rot + outer_elongation-1) & 2)
reverse_centers_order = true;
}
inlim = attr::klimit(lmap_ptr->insetup)+1;
outlim = attr::klimit(lmap_ptr->outsetup)+1;
// If inner (that is, outer) setups are triangles, we won't be able to
// turn them upside-down. So accept it. We don't have multiple maps
// for such things in any case.
if (inlim & 1) goto gotit;
int inners_xorstuff = 0;
if (q & 2) inners_xorstuff = inlim >> 1;
uint32 synth_mask = 1;
for (int k=0; k<lmap_ptr->center_arity; k++) {
int k_reorder = reverse_centers_order ? lmap_ptr->center_arity-k-1 : k;
for (int j=0; j<inlim; j++) {
if (inners[k_reorder].people[(j+inners_xorstuff)%inlim].id1 &&
!(lmap_ptr->used_mask_synthesize & synth_mask))
goto not_this_one;
synth_mask <<= 1;
}
}
for (int m=0; m<outlim; m++) {
if (outers->people[m].id1 &&
!(lmap_ptr->used_mask_synthesize & synth_mask))
goto not_this_one;
synth_mask <<= 1;
}
goto gotit;
}
not_this_one: ;
}
return false;
gotit:
q = relative_rotation + lmap_ptr->inner_rot - lmap_ptr->outer_rot;
if (orig_elong_is_controversial) {
// See if the table selection depended on knowing the actual elongation.
if (lmap_ptr->elongrotallow & (5 << index))
warn(warn_controversial);
}
if (reverse_centers_order) {
if (lmap_ptr->center_arity == 2) {
setup tt = inners[0];
inners[0] = inners[1];
inners[1] = tt;
}
else if (lmap_ptr->center_arity == 3) {
setup tt = inners[0];
inners[0] = inners[2];
inners[2] = tt;
}
}
const veryshort *map_indices = lmap_ptr->maps;
for (int k=0; k<lmap_ptr->center_arity; k++) {
uint32 rr = lmap_ptr->inner_rot;
// Need to flip alternating triangles upside down.
if (lmap_ptr->insetup == s_trngl && (k&1)) rr ^= 2;
if (q & 2) {
inners[k].rotation += 2;
canonicalize_rotation(&inners[k]);
}
if (k != 0) {
if (((inners[k].rotation ^ inners[k-1].rotation ^ lmap_ptr->inner_rot ^ rr) & 3) != 0)
fail("Sorry, bug 2 in normalize_concentric.");
}
install_scatter(result, inlim, map_indices, &inners[k], ((0-rr) & 3) * 011);
map_indices += inlim;
}
install_scatter(result, outlim, map_indices, outers,
((0-lmap_ptr->outer_rot) & 3) * 011);
result->kind = lmap_ptr->bigsetup;
result->rotation = outers->rotation + lmap_ptr->outer_rot;
result->eighth_rotation = 0;
return true;
}
// This overwrites its "outer_inners" argument setups.
extern void normalize_concentric(
const setup *ss, // The "dyp_squash" schemata need to see this; it's allowed to be null.
calldef_schema synthesizer,
int center_arity,
setup outer_inners[], // Outers in position 0, inners follow.
int outer_elongation,
uint32 matrix_concept,
setup *result) THROW_DECL
{
// If "outer_elongation" < 0, the outsides can't deduce their ending spots on
// the basis of the starting formation. In this case, it is an error unless
// they go to some setup for which their elongation is obvious, like a 1x4.
// The "CONTROVERSIAL_CONC_ELONG" is similar, but says that the low 2 bits
// are sort of OK, and that a warning needs to be raised.
int j;
setup *inners = &outer_inners[1];
setup *outers = &outer_inners[0];
calldef_schema table_synthesizer = synthesizer;
if (synthesizer == schema_rev_checkpoint_concept) table_synthesizer = schema_rev_checkpoint;
uint32 orig_elong_is_controversial = outer_elongation & CONTROVERSIAL_CONC_ELONG;
outer_elongation &= ~CONTROVERSIAL_CONC_ELONG;
result->clear_people();
result->result_flags = get_multiple_parallel_resultflags(outer_inners, center_arity+1);
// Only the first setup (centers) counts when check for space invasion.
if (!(inners->result_flags.misc & RESULTFLAG__INVADED_SPACE))
result->result_flags.misc &= ~RESULTFLAG__INVADED_SPACE;
if (outers->kind == s2x3 && (outers->result_flags.misc & RESULTFLAG__DID_SHORT6_2X3)) {
expand::expand_setup(s_short6_2x3, outers);
outer_elongation = (outers->rotation & 1) + 1;
}
if (inners[0].kind == nothing && outers->kind == nothing) {
result->kind = nothing;
return;
}
compute_rotation_again:
int relative_rotation = (inners[0].rotation - outers->rotation) & 3;
// Handle the special "do your part" mechanism for "slant [] and []".
// Then do the normal squash processing.
if (synthesizer == schema_in_out_triple_dyp_squash) {
setup *i0p = &inners[0];
setup *i1p = &inners[1];
uint32 mask0 = little_endian_live_mask(i0p);
uint32 mask1 = little_endian_live_mask(i1p);
// Convert from the outsides of a qtag to the outsides of a 2x4.
// The mask check is so that we won't ever get into a situation in which
// one of the formations was compressed but the other wasn't.
// (Compress_from_hash_table does its own checking.)
if (i0p->kind == s_qtag && i1p->kind == s_qtag && ((mask0 | mask1) & 0xCC) == 0) {
expand::compress_from_hash_table(i0p, plain_normalize, mask0, false);
expand::compress_from_hash_table(i1p, plain_normalize, mask1, false);
mask0 = little_endian_live_mask(i0p);
mask1 = little_endian_live_mask(i1p);
}
bool originals_were_on_left = false;
bool originals_were_on_right = false;
// Find out whether the active dancers were on the left side or the right side,
// in order to check for moving to the far side.
if (ss) {
uint32 ssmask = little_endian_live_mask(ss);
if (ss->kind == s3x4) {
if ((ssmask & 0x30C) == 0) originals_were_on_left = true;
else if ((ssmask & 0x0C3) == 0) originals_were_on_right = true;
}
else if (ss->kind == sbigh) {
if ((ssmask & 0x0C3) == 0) originals_were_on_left = true;
else if ((ssmask & 0x30C) == 0) originals_were_on_right = true;
}
else if (ss->kind == sbigdmd || ss->kind == sbigbone) {
if ((ssmask & 0x0C3) == 0) originals_were_on_left = true;
else if ((ssmask & 0xC30) == 0) originals_were_on_right = true;
}
}
bool swap_setups = false;
bool swap_fix_ptrs = false;
enum { fix_no_action, fix_bad, fix_1x8_to_1x4, fix_2x4_to_1x4, fix_2x4_to_2x2, fix_qtag_to_gal } todo = fix_bad;
if (outer_elongation == 1) {
if (i0p->kind == s2x4 && i0p->rotation == 1) {
if ((mask0 & 0x6F) == 0 && (mask1 & 0xF6) == 0) {
copy_person(i0p, 0, i1p, 0);
i1p->clear_person(0);
copy_person(i1p, 4, i0p, 4);
i0p->clear_person(4);
swap_setups = true;
outer_elongation = 2;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
todo = fix_2x4_to_1x4;
}
else if ((mask0 & 0xC3) == 0 && (mask1 & 0x3C) == 0) {
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
if ((mask0 & 0x24) != 0 || (mask1 & 0x42) != 0)
warn(warn__this_is_tight);
outer_elongation = 2;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x3C) == 0 && (mask1 & 0xC3) == 0) {
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
if ((mask0 & 0x42) != 0 || (mask1 & 0x24) != 0)
warn(warn__this_is_tight);
swap_setups = true;
outer_elongation = 2;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
todo = fix_2x4_to_1x4;
}
}
else if (i0p->kind == s2x4 && i0p->rotation == 0) {
if ((mask0 & 0x6F) == 0 && (mask1 & 0xF6) == 0) {
copy_person(i0p, 0, i1p, 0);
i1p->clear_person(0);
copy_person(i1p, 4, i0p, 4);
i0p->clear_person(4);
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xF6) == 0 && (mask1 & 0x6F) == 0) {
copy_person(i1p, 0, i0p, 0);
i0p->clear_person(0);
copy_person(i0p, 4, i1p, 4);
i1p->clear_person(4);
swap_setups = true;
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x3C) == 0 && (mask1 & 0xC3) == 0) {
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xC3) == 0 && (mask1 & 0x3C) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
outer_elongation = 2;
todo = fix_2x4_to_1x4;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
outer_elongation = 2;
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
swap_setups = true;
todo = fix_2x4_to_1x4;
}
}
else if (i0p->kind == s1x8 && i0p->rotation == 0) {
if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
swap_fix_ptrs = true;
todo = fix_1x8_to_1x4;
}
else if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
swap_fix_ptrs = true;
todo = fix_1x8_to_1x4;
}
}
else if (i0p->kind == s1x8 && i0p->rotation == 1) {
if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
outer_elongation = 2;
todo = fix_1x8_to_1x4;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
outer_elongation = 2;
swap_setups = true;
todo = fix_1x8_to_1x4;
}
}
else if (i0p->kind == s_qtag && i0p->rotation == 0) {
if (mask0 == 0x41 && mask1 == 0x14) {
todo = fix_qtag_to_gal;
}
else if (mask0 == 0x60 && mask1 == 0x06) {
todo = fix_qtag_to_gal;
}
else if (mask0 == 0x81 && mask1 == 0x18) {
warn(warn__this_is_tight);
todo = fix_qtag_to_gal;
}
else if (mask0 == 0xA0 && mask1 == 0x0A) {
warn(warn__this_is_tight);
todo = fix_qtag_to_gal;
}
}
else {
// If get here, there probably were phantoms that got
// turned into 2x2's or something. Take no action, other than setting to schema_in_out_triple_squash.
todo = fix_no_action;
}
}
else if (outer_elongation == 2) {
if (i0p->kind == s2x4 && i0p->rotation == 0) {
if ((mask0 & 0x6F) == 0 && (mask1 & 0xF6) == 0) {
copy_person(i0p, 0, i1p, 0);
i1p->clear_person(0);
copy_person(i1p, 4, i0p, 4);
i0p->clear_person(4);
outer_elongation = 1;
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
todo = fix_2x4_to_1x4;
}
else if ((mask0 & 0xC3) == 0 && (mask1 & 0x3C) == 0) {
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
if ((mask0 & 0x24) != 0 || (mask1 & 0x42) != 0)
warn(warn__this_is_tight);
swap_setups = true;
outer_elongation = 1;
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x3C) == 0 && (mask1 & 0xC3) == 0) {
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
if ((mask0 & 0x42) != 0 || (mask1 & 0x24) != 0)
warn(warn__this_is_tight);
outer_elongation = 1;
swap_fix_ptrs = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
todo = fix_2x4_to_1x4;
}
}
else if (i0p->kind == s2x4 && i0p->rotation == 1) {
if ((mask0 & 0xF6) == 0 && (mask1 & 0x6F) == 0) {
copy_person(i1p, 0, i0p, 0);
i0p->clear_person(0);
copy_person(i0p, 4, i1p, 4);
i1p->clear_person(4);
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x6F) == 0 && (mask1 & 0xF6) == 0) {
copy_person(i0p, 0, i1p, 0);
i1p->clear_person(0);
copy_person(i1p, 4, i0p, 4);
i0p->clear_person(4);
swap_setups = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xC3) == 0 && (mask1 & 0x3C) == 0) {
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0x3C) == 0 && (mask1 & 0xC3) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
todo = fix_2x4_to_2x2;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
outer_elongation = 1;
swap_setups = true;
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
todo = fix_2x4_to_1x4;
}
else if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
outer_elongation = 1;
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
todo = fix_2x4_to_1x4;
}
}
else if (i0p->kind == s1x8 && i0p->rotation == 1) {
if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
todo = fix_1x8_to_1x4;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
warn(warn__went_to_other_side);
swap_setups = true;
todo = fix_1x8_to_1x4;
}
}
else if (i0p->kind == s1x8 && i0p->rotation == 0) {
if ((mask0 & 0x0F) == 0 && (mask1 & 0xF0) == 0) {
if (originals_were_on_right) {
warn(warn__went_to_other_side);
}
outer_elongation = 1;
swap_setups = true;
swap_fix_ptrs = true;
todo = fix_1x8_to_1x4;
}
else if ((mask0 & 0xF0) == 0 && (mask1 & 0x0F) == 0) {
if (originals_were_on_left) {
warn(warn__went_to_other_side);
}
outer_elongation = 1;
swap_fix_ptrs = true;
todo = fix_1x8_to_1x4;
}
}
else if (i0p->kind == s_qtag && i0p->rotation == 1) {
if (mask0 == 0x14 && mask1 == 0x41) {
todo = fix_qtag_to_gal;
}
else if (mask0 == 0x06 && mask1 == 0x60) {
todo = fix_qtag_to_gal;
}
else if (mask0 == 0x18 && mask1 == 0x81) {
warn(warn__this_is_tight);
todo = fix_qtag_to_gal;
}
else if (mask0 == 0x0A && mask1 == 0xA0) {
warn(warn__this_is_tight);
todo = fix_qtag_to_gal;
}
}
else {
// If get here, there probably were phantoms that got
// turned into 2x2's or something. Take no action, other than setting to schema_in_out_triple_squash.
todo = fix_no_action;
}
}
if (swap_setups) {
setup t = *i0p;
*i0p = *i1p;
*i1p = t;
}
if (swap_fix_ptrs) {
setup *t = i0p;
i0p = i1p;
i1p = t;
}
switch (todo) {
case fix_1x8_to_1x4:
i0p->swap_people(0, 6);
i0p->swap_people(1, 7);
i0p->swap_people(3, 5);
i0p->swap_people(2, 4);
i0p->kind = s1x4;
i1p->kind = s1x4;
break;
case fix_2x4_to_1x4:
i0p->swap_people(0, 7);
i0p->swap_people(1, 6);
i0p->swap_people(3, 5);
i0p->swap_people(2, 4);
i1p->swap_people(2, 3);
i0p->kind = s1x4;
i1p->kind = s1x4;
break;
case fix_2x4_to_2x2:
i0p->swap_people(0, 2);
i0p->swap_people(1, 3);
i0p->swap_people(2, 4);
i0p->swap_people(3, 5);
i1p->swap_people(2, 6);
i1p->swap_people(3, 7);
i0p->kind = s2x2;
i1p->kind = s2x2;
break;
case fix_qtag_to_gal:
// Create just one outside setup, which is a diamond.
for (j=0 ; j<8 ; j++) install_person(i1p, j, i0p, j);
install_person(i1p, 2, i1p, 3);
install_person(i1p, 6, i1p, 7);
install_person(i1p, 1, i1p, 0);
install_person(i1p, 4, i1p, 5);
copy_rot(i0p, 0, i1p, 4, 011);
copy_rot(i0p, 1, i1p, 6, 011);
copy_rot(i0p, 2, i1p, 1, 011);
copy_rot(i0p, 3, i1p, 2, 011);
i0p->kind = sdmd;
i0p->rotation--;
canonicalize_rotation(i0p);
// Change schema to normal, and compensate for the fact that the "triple"
// schemata have reversed the centers and ends.
center_arity = 1;
synthesizer = schema_concentric;
warn(warn__may_be_fudgy);
{
setup t = *inners;
*inners = *outers;
*outers = t;
}
goto compute_rotation_again;
case fix_bad:
fail("Can't figure out what to do.");
break;
}
canonicalize_rotation(i0p);
canonicalize_rotation(i1p);
synthesizer = schema_in_out_triple_squash;
goto compute_rotation_again;
}
if (synthesizer == schema_in_out_triple_squash) {
// Do special stuff to put setups back properly for squashed schema.
setup *i0p = &inners[0];
setup *i1p = &inners[1];
if (i0p->kind == s2x2) {
// Move people to the closer parts of 2x2 setups.
if (outer_elongation == 2) {
if (!(i1p->people[2].id1 | i1p->people[3].id1)) {
i1p->swap_people(0, 3);
i1p->swap_people(1, 2);
}
if (!(i0p->people[0].id1 | i0p->people[1].id1)) {
i0p->swap_people(0, 3);
i0p->swap_people(1, 2);
}
}
else if (outer_elongation == 1) {
if (!(i1p->people[0].id1 | i1p->people[3].id1)) {
i1p->swap_people(0, 1);
i1p->swap_people(3, 2);
}
if (!(i0p->people[2].id1 | i0p->people[1].id1)) {
i0p->swap_people(0, 1);
i0p->swap_people(3, 2);
}
}
center_arity = 2;
table_synthesizer = schema_in_out_triple;
}
else if (i0p->kind == s1x4) {
// Move people to the closer parts of 1x4 setups.
if (i0p->rotation == 1 && outer_elongation == 2) {
if (!(i1p->people[2].id1 | i1p->people[3].id1)) {
i1p->swap_people(0, 3);
i1p->swap_people(1, 2);
}
else if (!(i1p->people[2].id1)) {
i1p->swap_people(2, 3);
i1p->swap_people(1, 3);
i1p->swap_people(1, 0);
warn(warn__compress_carefully);
}
if (!(i0p->people[0].id1 | i0p->people[1].id1)) {
i0p->swap_people(0, 3);
i0p->swap_people(1, 2);
}
else if (!(i0p->people[0].id1)) {
i0p->swap_people(1, 0);
i0p->swap_people(1, 3);
i0p->swap_people(2, 3);
warn(warn__compress_carefully);
}
}
else if (i0p->rotation == 0 && outer_elongation == 1) {
if (!(i0p->people[2].id1 | i0p->people[3].id1)) {
i0p->swap_people(0, 3);
i0p->swap_people(1, 2);
}
else if (!(i0p->people[2].id1)) {
i0p->swap_people(2, 3);
i0p->swap_people(1, 3);
i0p->swap_people(1, 0);
warn(warn__compress_carefully);
}
if (!(i1p->people[0].id1 | i1p->people[1].id1)) {
i1p->swap_people(0, 3);
i1p->swap_people(1, 2);
}
else if (!(i1p->people[0].id1)) {
i1p->swap_people(1, 0);
i1p->swap_people(1, 3);
i1p->swap_people(2, 3);
warn(warn__compress_carefully);
}
}
center_arity = 2;
table_synthesizer = schema_in_out_triple;