forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdconcpt.cpp
More file actions
8900 lines (7446 loc) · 345 KB
/
Copy pathsdconcpt.cpp
File metadata and controls
8900 lines (7446 loc) · 345 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:
do_big_concept
nose_move
stable_move
and the following external variables:
global_tbonetest
global_livemask
global_selectmask
global_tboneselect
concept_table
*/
// For sprintf.
#include <stdio.h>
#include "sd.h"
static uint32 orig_tbonetest;
uint32 global_tbonetest;
uint32 global_livemask;
uint32 global_selectmask;
uint32 global_tboneselect;
static void do_concept_expand_some_matrix(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
// We used to turn on the "FINAL__16_MATRIX" call modifier for 2x8 matrix,
// but that makes tandem stuff not work (it doesn't like
// call modifiers preceding it) and 4x4 stuff not work
// (it wants the matrix expanded, but doesn't want you to say
// "16 matrix"). So we need to let the CMD_MISC__EXPLICIT_MATRIX
// bit control the desired effects.
if ( ss->kind != ((setup_kind) parseptr->concept->arg1) &&
// "16 matrix of parallel diamonds" needs to accept 4dmd or 4ptpd.
(ss->kind != s4ptpd || ((setup_kind) parseptr->concept->arg1) != s4dmd))
fail("Can't make the required matrix out of this.");
ss->cmd.cmd_misc_flags |= CMD_MISC__EXPLICIT_MATRIX;
move(ss, false, result);
}
// A remnant of some old stuff.
#define C_const
typedef struct {
C_const int sizem1;
C_const setup_kind ikind;
C_const veryshort map1[8];
C_const veryshort map2[8];
} phan_map;
static phan_map map_c1_phan = {7, s2x4, {0, 2, 7, 5, 8, 10, 15, 13}, {4, 6, 11, 9, 12, 14, 3, 1}};
static phan_map map_diag_box = {3, s2x2, {2, 3, 6, 7}, {0, 1, 4, 5}};
static phan_map map_diag_hinged={3, nothing,{0, 1, 4, 5}, {7, 6, 3, 2}};
static phan_map map_diag_phan1= {3, nothing,{3, 1, 11, 9}, {13, 15, 5, 7}};
static phan_map map_diag_phan2= {3, nothing,{4, 6, 12, 14}, {0, 2, 8, 10}};
static phan_map map_pinwheel1 = {7, s2x4, {10, 15, -1, -1, 2, 7, -1, -1}, {14, 3, -1, -1, 6, 11, -1, -1}};
static phan_map map_pinwheel2 = {7, s2x4, {-1, -1, 3, 1, -1, -1, 11, 9}, {-1, -1, 7, 5, -1, -1, 15, 13}};
static phan_map map_pinwheel3 = {7, s2x4, {12, 13, -1, -1, 4, 5, -1, -1}, {14, 3, -1, -1, 6, 11, -1, -1}};
static phan_map map_pinwheel4 = {7, s2x4, {-1, -1, 14, 0, -1, -1, 6, 8}, {-1, -1, 7, 5, -1, -1, 15, 13}};
static phan_map map_pinwheel5 = {7, s2x4, {10, 15, -1, -1, 2, 7, -1, -1}, {0, 1, -1, -1, 8, 9, -1, -1}};
static phan_map map_pinwheel6 = {7, s2x4, {-1, -1, 3, 1, -1, -1, 11, 9}, {-1, -1, 2, 4, -1, -1, 10, 12}};
static phan_map map_tophat1 = {7, s2x4, {-1, -1, 3, 1, 2, 7, -1, -1}, {-1, -1, -1, -1, 6, 11, 15, 13}};
static phan_map map_tophat2 = {7, s2x4, {10, 15, 3, 1, -1, -1, -1, -1}, {-1, -1, 7, 5, 6, 11, -1, -1}};
static phan_map map_tophat3 = {7, s2x4, {10, 15, -1, -1, -1, -1, 11, 9}, {14, 3, 7, 5, -1, -1, -1, -1}};
static phan_map map_tophat4 = {7, s2x4, {-1, -1, -1, -1, 2, 7, 11, 9}, {14, 3, -1, -1, -1, -1, 15, 13}};
static phan_map map_pinwheel7 = {7, s2x4, {0, 1, -1, -1, 6, 7, -1, -1}, {2, 5, -1, -1, 8, 11, -1, -1}};
static phan_map map_pinwheel8 = {7, s2x4, {-1, -1, 2, 3, -1, -1, 8, 9}, {-1, -1, 5, 7, -1, -1, 11, 1}};
static phan_map map_o_spots = {7, s2x4, {10, -1, -1, 1, 2, -1, -1, 9}, {14, -1, -1, 5, 6, -1, -1, 13}};
static phan_map map_qt_phan = {7, s_qtag, {-1, -1, 2, 3, -1, -1, 6, 7}, {1, 4, -1, -1, 5, 0, -1, -1}};
static void do_concept_tandem(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
// The "arg3" field of the concept descriptor contains bit fields as follows:
// "100" bit: this takes a selector
// "200" bit: this takes an implicit selector of "some"
// "F0" field: (fractional) twosome info --
// 0=solid all the way
// 1=twosome all the way
// 2=solid-frac-twosome
// 3=twosome-frac-solid
// "8" bit: any twosome is actually "dynamic"
// "4" bit: any twosome is actually "reverse dynamic"
// "0F" field:
// 0=normal
// 2=plain-gruesome
// 3=gruesome-with-wave-assumption
// 4 bit=this is a "melded (phantom)" thing.
// 8 bit=this is a plain "melded" thing.
if (ss->cmd.cmd_final_flags.test_heritbit(INHERITFLAG_TWISTED))
fail("Improper concept order.");
// Look for things like "tandem in a 1/4 tag".
if (parseptr->next && parseptr->next->concept->kind == concept_tandem_in_setup) {
tandem_key master_key = (tandem_key) parseptr->concept->arg4;
// Demand that this not be "gruesome" or "anyone are tandem" or "skew" or
// "triangles are solid" or whatever.
if ((master_key != tandem_key_cpls && master_key != tandem_key_tand) ||
(parseptr->concept->arg3 & ~0x0F0) != 0)
fail("Can do this only with \"as couples\" or \"tandem\".");
// Find out how the matrix is to be expanded.
uint32 orig_bits = parseptr->next->concept->arg2;
if (master_key == tandem_key_tand) {
switch (orig_bits & CONCPROP__NEED_MASK) {
case CONCPROP__NEEDK_4DMD:
orig_bits ^= CONCPROP__NEEDK_TWINQTAG ^ CONCPROP__NEEDK_4DMD;
break;
case CONCPROP__NEEDK_DBLX:
orig_bits ^= CONCPROP__NEEDK_2X8 ^ CONCPROP__NEEDK_DBLX;
break;
case CONCPROP__NEEDK_DEEPXWV:
orig_bits ^= CONCPROP__NEEDK_2X6 ^ CONCPROP__NEEDK_DEEPXWV;
break;
case CONCPROP__NEEDK_1X16:
case CONCPROP__NEEDK_2X8:
orig_bits ^= CONCPROP__NEEDK_2X8 ^ CONCPROP__NEEDK_1X16;
break;
}
}
if (!(ss->cmd.cmd_misc_flags & CMD_MISC__NO_EXPAND_MATRIX))
do_matrix_expansion(ss, orig_bits, false);
// Put in the "VERIFY" bits stating just what type of setup to expect.
ss->cmd.cmd_misc_flags |= CMD_MISC__PHANTOMS | parseptr->next->concept->arg1;
// Skip the "in a whatever" concept.
ss->cmd.parseptr = parseptr->next->next;
}
// The table said this concept was matrix-oblivious. Now that we have
// expanded for "in a whatever", we have to take action.
// Not so!!!! We used to do:
// ss->cmd.cmd_misc_flags |= CMD_MISC__NO_EXPAND_MATRIX;
// Which prevented any further matrix expansion (e.g. the 2x4-4x4 that
// happens on split phantom lines) from happening after any "phantom tandem"
// type of call. We no longer do that, which means that things like
// "phantom as couples split phantom lines square the bases" are now legal.
uint32 mxnflags = ss->cmd.cmd_final_flags.test_heritbits(INHERITFLAG_SINGLE |
INHERITFLAG_MXNMASK |
INHERITFLAG_NXNMASK);
if (parseptr->concept->arg2 == CONCPROP__NEEDK_4DMD ||
parseptr->concept->arg2 == CONCPROP__NEEDK_4D_4PTPD ||
parseptr->concept->arg2 == CONCPROP__NEEDK_TWINQTAG)
ss->cmd.cmd_misc_flags |= CMD_MISC__PHANTOMS;
ss->cmd.cmd_misc_flags |= parseptr->concept->arg1;
ss->cmd.cmd_final_flags.clear_heritbits(INHERITFLAG_SINGLE |
INHERITFLAG_MXNMASK |
INHERITFLAG_NXNMASK);
if (parseptr->concept->arg3 & 0x4) {
// Expand for "phantom tandem" etc. First priority is a 4x4.
do_matrix_expansion(ss, CONCPROP__NEEDK_4X4, true);
if (ss->kind != s4x4) do_matrix_expansion(ss, CONCPROP__NEEDK_2X8, true);
if (ss->kind != s2x8) do_matrix_expansion(ss, CONCPROP__NEEDK_1X16, true);
ss->cmd.cmd_misc_flags |= CMD_MISC__PHANTOMS;
}
tandem_couples_move(
ss,
(parseptr->concept->arg3 & 0x100) ? parseptr->options.who :
((parseptr->concept->arg3 & 0x200) ? selector_some : selector_uninitialized),
(parseptr->concept->arg3 & 0xF0) >> 4, // (fractional) twosome info
parseptr->options.number_fields,
parseptr->concept->arg3 & 0xF, // normal/phantom/gruesome etc.
(tandem_key) parseptr->concept->arg4, // key
mxnflags,
false,
result);
}
static void do_c1_phantom_move(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
// If arg2 is nonzero, this is actually the "diagonal box" concept.
parse_block *next_parseptr;
final_and_herit_flags junk_concepts;
setup the_setups[2];
phan_map *map_ptr = (phan_map *) 0;
// See if this is a "phantom tandem" (or whatever) by searching ahead,
// skipping comments of course. This means we must skip modifiers too,
// so we check that there weren't any.
junk_concepts.clear_all_herit_and_final_bits();
next_parseptr = process_final_concepts(parseptr->next, false, &junk_concepts, true, false);
if (!parseptr->concept->arg2 && (next_parseptr->concept->kind == concept_tandem ||
next_parseptr->concept->kind == concept_frac_tandem)) {
// Find out what kind of tandem call this is.
uint32 what_we_need = 0;
uint32 mxnflags = ss->cmd.cmd_final_flags.test_heritbits(INHERITFLAG_SINGLE |
INHERITFLAG_MXNMASK |
INHERITFLAG_NXNMASK);
if (junk_concepts.test_for_any_herit_or_final_bit())
fail("Phantom couples/tandem must not have intervening concepts.");
// "Phantom tandem" has a higher level than either "phantom" or "tandem".
if (phantom_tandem_level > calling_level) warn_about_concept_level();
switch (next_parseptr->concept->arg4) {
case tandem_key_siam:
case tandem_key_skew:
fail("Phantom not allowed with skew or siamese.");
case tandem_key_box:
// We do not expand the matrix. The caller must say
// "2x8 matrix", or whatever, to get that effect.
break;
case tandem_key_diamond:
// We do not expand the matrix. The caller must say
// "16 matrix or parallel diamonds", or whatever, to get that effect.
break;
case tandem_key_tand3:
case tandem_key_cpls3:
case tandem_key_siam3:
case tandem_key_tand4:
case tandem_key_cpls4:
case tandem_key_siam4:
// We do not expand the matrix. The caller must say
// "2x8 matrix", or whatever, to get that effect.
break;
default:
// This is plain "phantom tandem", or whatever. Expand to whatever is in
// the "arg2" field, or to a 4x4. The "arg2" check allows the user to say
// "phantom as couples in a 1/4 tag". "as couples in a 1/4 tag"
// would have worked also.
// But we don't do this if stuff like "1x3" came in.
if (!mxnflags) {
what_we_need = next_parseptr->concept->arg2;
if (what_we_need == 0) what_we_need = ~0U;
}
break;
}
// Look for things like "tandem in a 1/4 tag". If so, skip the expansion stuff.
if (next_parseptr->next && next_parseptr->next->concept->kind == concept_tandem_in_setup) {
// No matrix expand.
}
else if (!(ss->cmd.cmd_misc_flags & CMD_MISC__NO_EXPAND_MATRIX)) {
if (what_we_need == ~0U) {
// Expand for "phantom tandem" etc. First priority is a 4x4.
do_matrix_expansion(ss, CONCPROP__NEEDK_4X4, true);
if (ss->kind != s4x4) do_matrix_expansion(ss, CONCPROP__NEEDK_2X8, true);
if (ss->kind != s2x8) do_matrix_expansion(ss, CONCPROP__NEEDK_1X16, true);
}
else if (what_we_need != 0) {
do_matrix_expansion(ss, what_we_need, true);
}
}
ss->cmd.cmd_misc_flags |= CMD_MISC__PHANTOMS;
ss->cmd.parseptr = next_parseptr->next;
do_concept_tandem(ss, next_parseptr, result);
return;
}
ss->cmd.cmd_misc_flags |= CMD_MISC__NO_EXPAND_MATRIX; // We didn't do this before.
if (parseptr->concept->arg2) {
if (ss->kind != s2x4)
fail("Need a 2x4 setup to do this concept.");
map_ptr = &map_diag_box;
ss->cmd.cmd_misc_flags &= ~CMD_MISC__MUST_SPLIT_MASK;
goto use_map;
}
if (ss->kind == s4x4 && global_livemask == 0x6666) {
// First, check for everyone on "O" spots. If so, treat them as though
// in equivalent C1 phantom spots.
map_ptr = &map_o_spots;
}
else if (ss->kind == s_c1phan)
// This is a vanilla C1 phantom setup.
map_ptr = &map_c1_phan;
else if (ss->kind == s_bone)
// We allow "phantom" in a bone setup to mean two "dunlap" quarter tags.
map_ptr = &map_qt_phan;
else if (ss->kind == s3x4) {
// Check for a 3x4 occupied as a distorted "pinwheel", and treat it as phantoms.
if (global_livemask == 04747)
map_ptr = &map_pinwheel7;
else if (global_livemask == 05656)
map_ptr = &map_pinwheel8;
}
else if (ss->kind == s4x4) {
setup temp;
// Check for a 4x4 occupied as a "pinwheel" or "tophat", and treat it as phantoms.
if (global_livemask == 0xCCCC) {
map_ptr = &map_pinwheel1;
goto use_map;
}
else if (global_livemask == 0xAAAA) {
map_ptr = &map_pinwheel2;
goto use_map;
}
else if (global_livemask == 0x7878) {
map_ptr = &map_pinwheel3;
goto use_map;
}
else if (global_livemask == 0xE1E1) {
map_ptr = &map_pinwheel4;
goto use_map;
}
else if (global_livemask == 0x8787) {
map_ptr = &map_pinwheel5;
goto use_map;
}
else if (global_livemask == 0x1E1E) {
map_ptr = &map_pinwheel6;
goto use_map;
}
else if (global_livemask == 0xA8CE) {
map_ptr = &map_tophat1;
goto use_map;
}
else if (global_livemask == 0x8CEA) {
map_ptr = &map_tophat2;
goto use_map;
}
else if (global_livemask == 0xCEA8) {
map_ptr = &map_tophat3;
goto use_map;
}
else if (global_livemask == 0xEA8C) {
map_ptr = &map_tophat4;
goto use_map;
}
// Next, check for a "phantom turn and deal" sort of thing from stairsteps.
// Do the call in each line, them remove resulting phantoms carefully.
if (global_livemask == 0x5C5C || global_livemask == 0xA3A3) {
// Split into 4 vertical strips.
divided_setup_move(ss, spcmap_4x4v, phantest_ok, true, result);
}
else if (global_livemask == 0xC5C5 || global_livemask == 0x3A3A) {
// Split into 4 horizontal strips.
divided_setup_move(ss, MAPCODE(s1x4,4,MPKIND__SPLIT,1), phantest_ok, true, result);
}
else
fail("Inappropriate setup for phantom concept.");
if (result->kind != s2x8)
fail("This call is not appropriate for use with phantom concept.");
temp = *result;
result->clear_people();
if (!(temp.people[0].id1 | temp.people[7].id1 | temp.people[8].id1 | temp.people[15].id1)) {
copy_person(result, 0, &temp, 1);
copy_person(result, 3, &temp, 6);
copy_person(result, 4, &temp, 9);
copy_person(result, 7, &temp, 14);
}
else if (!(temp.people[1].id1 | temp.people[6].id1 | temp.people[9].id1 | temp.people[14].id1)) {
copy_person(result, 0, &temp, 0);
copy_person(result, 3, &temp, 7);
copy_person(result, 4, &temp, 8);
copy_person(result, 7, &temp, 15);
}
else
fail("This call is not appropriate for use with phantom concept.");
if (!(temp.people[2].id1 | temp.people[5].id1 | temp.people[10].id1 | temp.people[13].id1)) {
copy_person(result, 1, &temp, 3);
copy_person(result, 2, &temp, 4);
copy_person(result, 5, &temp, 11);
copy_person(result, 6, &temp, 12);
}
else if (!(temp.people[3].id1 | temp.people[4].id1 | temp.people[11].id1 | temp.people[12].id1)) {
copy_person(result, 1, &temp, 2);
copy_person(result, 2, &temp, 5);
copy_person(result, 5, &temp, 10);
copy_person(result, 6, &temp, 13);
}
else
fail("This call is not appropriate for use with phantom concept.");
result->kind = s2x4;
return;
}
use_map:
if (!map_ptr)
fail("Inappropriate setup for phantom concept.");
setup setup1 = *ss;
setup setup2 = *ss;
setup1.kind = map_ptr->ikind;
setup2.kind = map_ptr->ikind;
setup1.rotation = ((parseptr->concept->arg2) ? 0 : ss->rotation);
setup2.rotation = ((parseptr->concept->arg2) ? 0 : ss->rotation+1);
setup1.eighth_rotation = 0;
setup2.eighth_rotation = 0;
setup1.clear_people();
setup2.clear_people();
gather(&setup1, ss, map_ptr->map1, map_ptr->sizem1, 0);
gather(&setup2, ss, map_ptr->map2, map_ptr->sizem1, ((parseptr->concept->arg2) ? 0 : 033));
normalize_setup(&setup1, simple_normalize, false);
normalize_setup(&setup2, simple_normalize, false);
setup1.cmd.cmd_misc_flags |= CMD_MISC__DISTORTED;
setup2.cmd.cmd_misc_flags |= CMD_MISC__DISTORTED;
move(&setup1, false, &the_setups[0]);
move(&setup2, false, &the_setups[1]);
if (parseptr->concept->arg2) {
result->clear_people();
result->result_flags = get_multiple_parallel_resultflags(the_setups, 2);
if (the_setups[0].kind == nothing) {
if (the_setups[1].kind == nothing) {
result->kind = nothing;
clear_result_flags(result); // Do we need this?
return;
}
else {
the_setups[0] = the_setups[1];
the_setups[0].clear_people();
}
}
else if (the_setups[1].kind == nothing) {
the_setups[1] = the_setups[0];
the_setups[1].clear_people();
}
if (the_setups[0].kind == s2x2 && the_setups[1].kind == s2x2) {
result->rotation = 0;
result->eighth_rotation = 0;
result->kind = s2x4;
install_scatter(result, map_ptr->sizem1+1, map_ptr->map1, &the_setups[0], 0);
install_scatter(result, map_ptr->sizem1+1, map_ptr->map2, &the_setups[1], 0);
}
else if (the_setups[0].kind == s1x4 && the_setups[1].kind == s1x4 &&
the_setups[0].rotation == 1 && the_setups[1].rotation == 1) {
map_ptr = &map_diag_hinged;
result->kind = s2x4;
result->rotation = 1;
result->eighth_rotation = 0;
install_scatter(result, map_ptr->sizem1+1, map_ptr->map1, &the_setups[0], 0);
install_scatter(result, map_ptr->sizem1+1, map_ptr->map2, &the_setups[1], 0);
}
else if (the_setups[0].kind == s2x2 && the_setups[1].kind == s1x4 &&
the_setups[1].rotation == 1) {
map_ptr = &map_diag_phan1;
result->kind = s_c1phan;
result->rotation = 1;
result->eighth_rotation = 0;
install_scatter(result, map_ptr->sizem1+1, map_ptr->map1, &the_setups[0], 033);
install_scatter(result, map_ptr->sizem1+1, map_ptr->map2, &the_setups[1], 0);
}
else if (the_setups[0].kind == s1x4 && the_setups[0].rotation == 1 &&
the_setups[1].kind == s2x2) {
map_ptr = &map_diag_phan2;
result->kind = s_c1phan;
result->rotation = 0;
result->eighth_rotation = 0;
install_scatter(result, map_ptr->sizem1+1, map_ptr->map1, &the_setups[0], 011);
install_scatter(result, map_ptr->sizem1+1, map_ptr->map2, &the_setups[1], 0);
}
else {
fail("Can't figure out result setup.");
}
canonicalize_rotation(result);
reinstate_rotation(ss, result);
return;
}
*result = the_setups[1];
result->result_flags = get_multiple_parallel_resultflags(the_setups, 2);
merge_table::merge_setups(&the_setups[0],
merge_c1_phantom_real,
result,
(ss->cmd.parseptr &&
ss->cmd.parseptr->concept &&
ss->cmd.parseptr->concept->kind == marker_end_of_list) ?
ss->cmd.parseptr->call : (call_with_name *) 0);
}
static void do_concept_single_diagonal(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
if (ss->kind != s4x4) fail("Need a 4x4 for this.");
if (global_livemask != 0x2D2D && global_livemask != 0xD2D2)
fail("People must be in blocks -- try specifying the people who should do the call.");
selective_move(ss, parseptr, selective_key_disc_dist, 0,
parseptr->concept->arg1,
global_livemask & 0x9999, selector_uninitialized, false, result);
}
static void do_concept_double_diagonal(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
/* This concept is "standard", which means that it can look at global_tbonetest
and global_livemask, but may not look at anyone's facing direction other
than through global_tbonetest. */
{
uint32 tbonetest;
uint32 map_code;
if (parseptr->concept->arg2 == 2) {
// This is "distorted CLW of 6".
setup ssave = *ss;
if (ss->kind != sbighrgl) global_livemask = 0; // Force error.
if (global_livemask == 0x3CF) { map_code = spcmap_dhrgl1; }
else if (global_livemask == 0xF3C) { map_code = spcmap_dhrgl2; }
else fail("Can't find distorted 1x6.");
if (parseptr->concept->arg1 == 3)
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_WAVES;
else if (parseptr->concept->arg1 == 1)
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_LINES;
else
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_COLS;
divided_setup_move(ss, map_code, phantest_ok, true, result);
// I wish this weren't so sleazy, but a new concentricity schema seems excessive.
if (result->kind != sbighrgl) fail("Can't figure out result setup.");
copy_person(result, 2, &ssave, 2);
copy_person(result, 8, &ssave, 8);
}
else if (parseptr->concept->arg2) {
// This is "diagonal CLW's of 3".
setup ssave = *ss;
int switcher = (parseptr->concept->arg1 ^ global_tbonetest) & 1;
if (ss->kind != s4x4 || (global_tbonetest & 011) == 011) global_livemask = 0; // Force error.
if ( global_livemask == 0x2D2D)
map_code = switcher ? spcmap_diag23a : spcmap_diag23b;
else if (global_livemask == 0xD2D2)
map_code = switcher ? spcmap_diag23c : spcmap_diag23d;
else
fail("There are no diagonal lines or columns of 3 here.");
if (parseptr->concept->arg1 == 3)
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_WAVES;
divided_setup_move(ss, map_code, phantest_ok, true, result);
// I wish this weren't so sleazy, but a new concentricity schema seems excessive.
if (result->kind != s4x4) fail("Can't figure out result setup.");
copy_person(result, 0, &ssave, 0);
copy_person(result, 4, &ssave, 4);
copy_person(result, 8, &ssave, 8);
copy_person(result, 12, &ssave, 12);
}
else {
tbonetest = global_tbonetest;
if (ss->kind == s4x4) {
if (global_livemask == 0x9999) {
if ((parseptr->concept->arg1 ^ tbonetest) & 1) {
map_code = MAPCODE(s1x4,2,MPKIND__NS_CROSS_IN_4X4,0);
tbonetest = ~tbonetest; // Trick the line/column test below, so it does the right thing.
}
else
map_code = MAPCODE(s1x4,2,MPKIND__EW_CROSS_IN_4X4,0);
}
else
tbonetest = ~0U; // Force error.
}
else if (ss->kind == s4x6) {
if ( global_livemask == 0x2A82A8) map_code = spcmap_diag2a;
else if (global_livemask == 0x505505) map_code = spcmap_diag2b;
else
tbonetest = ~0U; // Force error.
}
else
tbonetest = ~0U; // Force error.
if (parseptr->concept->arg1 & 1) {
if (tbonetest & 010) fail("There are no diagonal lines here.");
}
else {
if (tbonetest & 1) fail("There are no diagonal columns here.");
}
if (parseptr->concept->arg1 == 3)
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_WAVES;
divided_setup_move(ss, map_code, phantest_ok, true, result);
}
}
static void do_concept_double_offset(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
if (ss->kind != s2x4) fail("Must have a 2x4 setup to do this concept.");
uint32 topmask, botmask, ctrmask;
uint32 directions, livemask, map_code;
big_endian_get_directions(ss, directions, livemask); // Get big-endian bit-pair masks.
if (global_selectmask == (global_livemask & 0xCC)) {
topmask = 0xF000 & livemask;
botmask = 0x00F0 & livemask;
ctrmask = 0x0F0F & livemask;
map_code = spcmap_dbloff1;
}
else if (global_selectmask == (global_livemask & 0x33)) {
topmask = 0x0F00 & livemask;
botmask = 0x000F & livemask;
ctrmask = 0xF0F0 & livemask;
map_code = spcmap_dbloff2;
}
else
fail("The designated centers are improperly placed.");
// Check that the concept is correctly named.
uint32 errmask = 0;
uint32 case01 = 0;
uint32 case23 = 0;
if (((directions ^ 0x8822) & ctrmask) != 0 &&
((directions ^ 0x2288) & ctrmask) != 0)
case01 = 1;
if (((directions ^ 0xAA00) & ctrmask) != 0 &&
((directions ^ 0x00AA) & ctrmask) != 0)
case23 = 1;
switch (parseptr->concept->arg1) {
case 0:
// Double-offset quarter tag.
errmask = (directions & ctrmask & 0x5555) |
case01 |
((directions ^ 0xAAAA) & topmask) |
(directions & botmask);
break;
case 1:
// Double-offset three-quarter tag.
errmask = (directions & ctrmask & 0x5555) |
case01 |
((directions ^ 0xAAAA) & botmask) |
(directions & topmask);
break;
case 2:
// Double-offset quarter line.
errmask = (directions & ctrmask & 0x5555) |
case23 |
((directions ^ 0xAAAA) & topmask) |
(directions & botmask);
break;
case 3:
// Double-offset three-quarter line.
errmask = (directions & ctrmask & 0x5555) |
case23 |
((directions ^ 0xAAAA) & botmask) |
(directions & topmask);
break;
case 4:
// Double-offset general quarter tag.
errmask = directions & livemask & 0x5555;
break;
case 5:
// Double-offset diamonds.
errmask = (~directions & (topmask | botmask) & 0x5555) |
(directions & ctrmask & 0x5555);
break;
default:
// Case 6 -- double-offset diamond spots -- anything goes.
break;
}
if (errmask != 0)
fail("Facing directions are incorrect for this concept.");
divided_setup_move(ss, map_code, phantest_ok, true, result);
}
static void do_4x4_quad_working(setup *ss, int cstuff, setup *result) THROW_DECL
{
uint32 masks[8];
canonicalize_rotation(ss);
// Initially assign the centers to the upper (masks[1] or masks[2]) group.
masks[0] = 0xF0; masks[1] = 0xF0; masks[2] = 0xFF;
// Look at the center 8 people and put each one in the correct group.
if (cstuff == 8) {
masks[0] = 0xFC; masks[1] = 0xCC; masks[2] = 0xCF; // clockwise
}
else if (cstuff == 9) {
masks[0] = 0xF3; masks[1] = 0x33; masks[2] = 0x3F; // counterclockwise
}
else { // forward/back/left/right
if ((ss->people[10].id1 ^ cstuff) & 2) { masks[1] |= 0x01; masks[2] &= ~0x80; };
if ((ss->people[15].id1 ^ cstuff) & 2) { masks[1] |= 0x02; masks[2] &= ~0x40; };
if ((ss->people[3].id1 ^ cstuff) & 2) { masks[1] |= 0x04; masks[2] &= ~0x20; };
if ((ss->people[1].id1 ^ cstuff) & 2) { masks[1] |= 0x08; masks[2] &= ~0x10; };
if ((ss->people[9].id1 ^ cstuff) & 2) { masks[0] |= 0x01; masks[1] &= ~0x80; };
if ((ss->people[11].id1 ^ cstuff) & 2) { masks[0] |= 0x02; masks[1] &= ~0x40; };
if ((ss->people[7].id1 ^ cstuff) & 2) { masks[0] |= 0x04; masks[1] &= ~0x20; };
if ((ss->people[2].id1 ^ cstuff) & 2) { masks[0] |= 0x08; masks[1] &= ~0x10; };
}
overlapped_setup_move(ss, MAPCODE(s2x4,3,MPKIND__OVERLAP,1), masks, result);
}
static void do_concept_multiple_lines_tog(
setup *ss,
parse_block *parseptr,
setup *result) THROW_DECL
{
// This can only be standard for
// together/apart/clockwise/counterclockwise/toward-the-center,
// not for forward/back/left/right, because we look at
// individual facing directions to determine which other
// line/column the people in the center lines/columns must
// work in.
int rotfix = 0;
setup_kind base_setup = s2x4;
int base_vert = 1;
uint32 masks[8];
// Arg4 = number of C/L/W.
int cstuff = parseptr->concept->arg1;
// cstuff =
// forward (lines) or left (cols) : 0
// backward (lines) or right (cols) : 2
// clockwise : 8
// counterclockwise : 9
// together (must be end-to-end) : 10
// apart (must be end-to-end) : 11
// toward the center (quadruple only) : 12
int linesp = parseptr->concept->arg3;
// If this was multiple columns, we allow stepping to a wave. This makes it
// possible to do interesting cases of turn and weave, when one column
// is a single 8 chain and another is a single DPT. But if it was multiple
// lines, we forbid it.
if (linesp & 1)
ss->cmd.cmd_misc_flags |= CMD_MISC__NO_STEP_TO_WAVE;
if (linesp == 3)
ss->cmd.cmd_misc_flags |= CMD_MISC__VERIFY_WAVES;
if (parseptr->concept->arg4 == 3) {
// Triple C/L/W working.
if (cstuff >= 10) {
if (ss->kind != s1x12) fail("Must have a 1x12 setup for this concept.");
if ((global_tbonetest & 011) == 011) fail("Can't do this from T-bone setup.");
if (linesp & 1) {
if (global_tbonetest & 1) fail("There are no lines of 4 here.");
}
else {
if (!(global_tbonetest & 1)) fail("There are no columns of 4 here.");
}
if (cstuff == 10) { // Working together.
masks[0] = 0xCF; masks[1] = 0xFC;
}
else { // Working apart.
masks[0] = 0x3F; masks[1] = 0xF3;
}
base_setup = s1x8;
base_vert = 0;
}
else {
int i, tbonetest;
if (ss->kind != s3x4) fail("Must have a 3x4 setup for this concept.");
if (cstuff >= 8)
tbonetest = global_tbonetest;
else {
tbonetest = 0;
for (i=0; i<12; i++) tbonetest |= ss->people[i].id1;
}
if ((tbonetest & 011) == 011) fail("Can't do this from T-bone setup.");
if (linesp & 1) {
if (tbonetest & 1) fail("There are no lines of 4 here.");
}
else {
if (!(tbonetest & 1)) fail("There are no columns of 4 here.");
}
// Initially assign the centers to the upper (masks[1]) group.
masks[0] = 0xF0; masks[1] = 0xFF;
// Look at the center line people and put each one in the correct group.
if (cstuff == 8) {
masks[0] = 0xFC; masks[1] = 0xCF; // clockwise
}
else if (cstuff == 9) {
masks[0] = 0xF3; masks[1] = 0x3F; // counterclockwise
}
else { // forward/back/left/right
if ((ss->people[10].id1 ^ cstuff) & 2) { masks[1] &= ~0x80 ; masks[0] |= 0x1; };
if ((ss->people[11].id1 ^ cstuff) & 2) { masks[1] &= ~0x40 ; masks[0] |= 0x2; };
if ((ss->people[5].id1 ^ cstuff) & 2) { masks[1] &= ~0x20 ; masks[0] |= 0x4; };
if ((ss->people[4].id1 ^ cstuff) & 2) { masks[1] &= ~0x10 ; masks[0] |= 0x8; };
}
}
}
else if (parseptr->concept->arg4 == 4) {
// Quadruple C/L/W working.
if (cstuff >= 12) {
if (ss->kind != s4x4) fail("Must have a 4x4 setup to do this concept.");
if ((global_tbonetest & 011) == 011) fail("Sorry, can't do this from T-bone setup.");
rotfix = (global_tbonetest ^ linesp ^ 1) & 1;
ss->rotation += rotfix; // Just flip the setup around and recanonicalize.
canonicalize_rotation(ss);
masks[0] = 0xF0; masks[1] = 0xFF; masks[2] = 0x0F;
}
else if (cstuff >= 10) {
if (ss->kind != s1x16) fail("Must have a 1x16 setup for this concept.");
if ((global_tbonetest & 011) == 011) fail("Can't do this from T-bone setup.");
if (linesp & 1) {
if (global_tbonetest & 1) fail("There are no lines of 4 here.");
}
else {
if (!(global_tbonetest & 1)) fail("There are no columns of 4 here.");
}
if (cstuff == 10) { // Working together end-to-end.
masks[0] = 0xCF; masks[1] = 0xCC; masks[2] = 0xFC;
}
else { // Working apart end-to-end.
masks[0] = 0x3F; masks[1] = 0x33; masks[2] = 0xF3;
}
base_setup = s1x8;
base_vert = 0;
}
else {
int tbonetest;
setup hpeople = *ss;
setup vpeople = *ss;
if (ss->kind != s4x4) fail("Must have a 4x4 setup to do this concept.");
if (cstuff >= 8) {
// Clockwise/counterclockwise can use "standard".
tbonetest = global_tbonetest;
if ((tbonetest & 011) == 011) // But we can't have the standard people inconsistent.
fail("Standard people are inconsistent.");
}
else {
// Others can't use "standard", but can have multiple setups T-bioned to each other.
tbonetest = 0;
for (int i=0; i<16; i++) {
uint32 person = ss->people[i].id1;
tbonetest |= person;
if (person & 1)
vpeople.clear_person(i);
else
hpeople.clear_person(i);
}
}
if ((tbonetest & 011) == 011) {
setup the_setups[2];
// We now have nonempty setups in both hpeople and vpeople.
rotfix = (linesp ^ 1) & 1;
vpeople.rotation += rotfix;
do_4x4_quad_working(&vpeople, cstuff, &the_setups[0]);
the_setups[0].rotation -= rotfix; // Flip the setup back.
rotfix = (linesp) & 1;
hpeople.rotation += rotfix;
do_4x4_quad_working(&hpeople, cstuff, &the_setups[1]);
the_setups[1].rotation -= rotfix; // Flip the setup back.
*result = the_setups[1];
result->result_flags = get_multiple_parallel_resultflags(the_setups, 2);
merge_table::merge_setups(&the_setups[0], merge_strict_matrix, result);
warn(warn__tbonephantom);
}