forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdpreds.cpp
More file actions
2988 lines (2643 loc) · 120 KB
/
Copy pathsdpreds.cpp
File metadata and controls
2988 lines (2643 loc) · 120 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-2007 William B. Ackerman.
//
// This file is part of "Sd".
//
// 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 2 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
// along with Sd; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// This is for version 37.
/* This defines the following function:
selectp
and the following external variables:
selector_used
direction_used
number_used
mandatory_call_used
pred_table which is filled with pointers to the predicate functions
selector_preds
*/
#include "sd.h"
// These variables are external.
bool selector_used;
bool direction_used;
bool number_used;
bool mandatory_call_used;
extern bool selectp(const setup *ss, int place, int allow_some /*= 0*/) THROW_DECL
{
uint32 p1, p2, p3;
selector_kind s;
int thing_to_test;
uint32 selected_person_mask = ~0U;
uint32 directions;
uint32 livemask;
big_endian_get_directions(ss, directions, livemask);
selector_used = true;
// Pull out the cases that do not require the person to be real.
switch (current_options.who) {
case selector_all:
case selector_everyone:
return true;
case selector_none:
return false;
}
uint32 pid1 = ss->people[place].id1;
uint32 pid2 = ss->people[place].id2;
uint32 pid3 = ss->people[place].id3;
// Demand that the subject be real, or that
// we can evaluate based on position alone.
if (!(pid1 & BIT_PERSON)) {
// We can still do it for some selectors. However, this violates
// the rules about using the *original* centers in calls like
// "rims trade back". But, if the person isn't real, this is the best
// we can do.
//
// We do this based on the stuff in the attribute tables. If the
// setup is larger than 8, we can't -- the tables become very complicated
// based on the actual occupancy, and we are looking at an unoccupied
// space.
if (attr::slimit(ss) < 8) {
const id_bit_table *ptr = setup_attrs[ss->kind].id_bit_table_ptr;
if (ptr) {
switch (current_options.who) {
case selector_centers:
case selector_ends:
case selector_center2:
case selector_outer6:
case selector_verycenters:
case selector_center6:
case selector_outer2:
case selector_veryends:
case selector_ctrdmd:
case selector_ctr_1x4:
case selector_ctr_1x6:
case selector_outer1x3s:
case selector_center4:
case selector_center_wave:
case selector_center_line:
case selector_center_col:
case selector_center_wave_of_6:
case selector_center_line_of_6:
case selector_center_col_of_6:
case selector_center_box:
case selector_outerpairs:
pid2 = ptr[place][0] & ID2_BITS_TO_CLEAR_FOR_PHANTOM_SELECTOR;
goto do_switch;
}
}
}
fail("Can't decide who are selected.");
}
do_switch:
switch (current_options.who) {
case selector_boys:
if ((pid3 & (ID3_PERM_BOY|ID3_PERM_GIRL)) == ID3_PERM_BOY) return true;
else if ((pid3 & (ID3_PERM_BOY|ID3_PERM_GIRL)) == ID3_PERM_GIRL) return false;
break;
case selector_girls:
if ((pid3 & (ID3_PERM_BOY|ID3_PERM_GIRL)) == ID3_PERM_GIRL) return true;
else if ((pid3 & (ID3_PERM_BOY|ID3_PERM_GIRL)) == ID3_PERM_BOY) return false;
break;
case selector_heads:
if ((pid3 & (ID3_PERM_HEAD|ID3_PERM_SIDE)) == ID3_PERM_HEAD) return true;
else if ((pid3 & (ID3_PERM_HEAD|ID3_PERM_SIDE)) == ID3_PERM_SIDE) return false;
break;
case selector_sides:
if ((pid3 & (ID3_PERM_HEAD|ID3_PERM_SIDE)) == ID3_PERM_SIDE) return true;
else if ((pid3 & (ID3_PERM_HEAD|ID3_PERM_SIDE)) == ID3_PERM_HEAD) return false;
break;
case selector_headcorners:
if ((pid3 & (ID3_PERM_HCOR|ID3_PERM_SCOR)) == ID3_PERM_HCOR) return true;
else if ((pid3 & (ID3_PERM_HCOR|ID3_PERM_SCOR)) == ID3_PERM_SCOR) return false;
break;
case selector_sidecorners:
if ((pid3 & (ID3_PERM_HCOR|ID3_PERM_SCOR)) == ID3_PERM_SCOR) return true;
else if ((pid3 & (ID3_PERM_HCOR|ID3_PERM_SCOR)) == ID3_PERM_HCOR) return false;
break;
case selector_headboys:
if ((pid3 & (ID3_PERM_ALL_ID|ID3_PERM_NHB)) == (ID3_PERM_HEAD|ID3_PERM_BOY))
return true;
else if ((pid3 & ID3_PERM_NHB) == ID3_PERM_NHB)
return false;
break;
case selector_headgirls:
if ((pid3 & (ID3_PERM_ALL_ID|ID3_PERM_NHG)) == (ID3_PERM_HEAD|ID3_PERM_GIRL))
return true;
else if ((pid3 & ID3_PERM_NHG) == ID3_PERM_NHG)
return false;
break;
case selector_sideboys:
if ((pid3 & (ID3_PERM_ALL_ID|ID3_PERM_NSB)) == (ID3_PERM_SIDE|ID3_PERM_BOY))
return true;
else if ((pid3 & ID3_PERM_NSB) == ID3_PERM_NSB)
return false;
break;
case selector_sidegirls:
if ((pid3 & (ID3_PERM_ALL_ID|ID3_PERM_NSG)) == (ID3_PERM_SIDE|ID3_PERM_GIRL))
return true;
else if ((pid3 & ID3_PERM_NSG) == ID3_PERM_NSG)
return false;
break;
case selector_centers:
case selector_ends:
p2 = pid2 & (ID2_CENTER|ID2_END);
if (p2 == ID2_CENTER) s = selector_centers;
else if (p2 == ID2_END) s = selector_ends;
else break;
goto eq_return;
case selector_leads:
case selector_trailers:
p2 = pid2 & (ID2_LEAD|ID2_TRAILER);
if (p2 == ID2_LEAD) s = selector_leads;
else if (p2 == ID2_TRAILER) s = selector_trailers;
else break;
goto eq_return;
case selector_lead_ends:
case selector_lead_ctrs:
case selector_trail_ends:
case selector_trail_ctrs:
p2 = pid2 & (ID2_LEAD|ID2_TRAILER|ID2_CENTER|ID2_END);
if (p2 == (ID2_LEAD|ID2_END)) s = selector_lead_ends;
else if (p2 == (ID2_LEAD|ID2_CENTER)) s = selector_lead_ctrs;
else if (p2 == (ID2_TRAILER|ID2_END)) s = selector_trail_ends;
else if (p2 == (ID2_TRAILER|ID2_CENTER)) s = selector_trail_ctrs;
else break;
goto eq_return;
case selector_end_boys:
case selector_end_girls:
case selector_center_boys:
case selector_center_girls:
p3 = pid3 & (ID3_PERM_BOY|ID3_PERM_GIRL);
p2 = pid2 & (ID2_CENTER|ID2_END);
if (p2 == ID2_END && p3 == ID3_PERM_BOY) s = selector_end_boys;
else if (p2 == ID2_END && p3 == ID3_PERM_GIRL) s = selector_end_girls;
else if (p2 == ID2_CENTER && p3 == ID3_PERM_BOY) s = selector_center_boys;
else if (p2 == ID2_CENTER && p3 == ID3_PERM_GIRL) s = selector_center_girls;
else break;
goto eq_return;
case selector_beaus:
case selector_belles:
p2 = pid2 & (ID2_BEAU|ID2_BELLE);
if (p2 == ID2_BEAU) s = selector_beaus;
else if (p2 == ID2_BELLE) s = selector_belles;
else break;
goto eq_return;
case selector_mysticbeaus:
case selector_mysticbelles:
p2 = pid2 & (ID2_BEAU|ID2_BELLE|ID2_CTR4|ID2_END);
p1 = pid2 & (ID2_BEAU|ID2_BELLE|ID2_OUTRPAIRS);
if (p2 == (ID2_END|ID2_BEAU) ||
p2 == (ID2_CTR4|ID2_BELLE)) s = selector_mysticbeaus;
else if (p2 == (ID2_END|ID2_BELLE) ||
p2 == (ID2_CTR4|ID2_BEAU)) s = selector_mysticbelles;
else if (p1 == (ID2_OUTRPAIRS|ID2_BEAU)) s = selector_mysticbeaus;
else if (p1 == (ID2_OUTRPAIRS|ID2_BELLE)) s = selector_mysticbelles;
else break;
goto eq_return;
case selector_center2:
case selector_outer6:
if (ss->kind == s3x4 && current_options.who == selector_center2) {
return (pid2 & ID2_CTR2) != 0; // This one is always valid, even if we don't know who the "outer 6" are.
}
else if (ss->kind == s1x6) {
p2 = pid2 & (ID2_CTR2|ID2_OUTRPAIRS);
if (p2 == ID2_CTR2) s = selector_center2;
else if (p2 == ID2_OUTRPAIRS) s = selector_outerpairs;
else break;
}
else if (ss->kind == s2x7 || ss->kind == s_23232 || ss->kind == sdblspindle) {
if (current_options.who == selector_center2)
return (pid2 & ID2_CTR2) != 0;
else break;
}
else {
p2 = pid2 & (ID2_CTR2|ID2_OUTR6);
if (p2 == ID2_CTR2) s = selector_center2;
else if (p2 == ID2_OUTR6) s = selector_outer6;
else break;
}
goto eq_return;
case selector_verycenters: /* Gotta fix this stuff - use fall-through variable. */
if (ss->kind == s1x6) {
p2 = pid2 & (ID2_CTR2|ID2_OUTRPAIRS);
if (p2 == ID2_CTR2) return true;
else if (p2 == ID2_OUTRPAIRS) s = selector_outerpairs;
else break;
}
else if (ss->kind == s2x7) {
return (pid2 & ID2_CTR2) != 0;
}
else {
p2 = pid2 & (ID2_CTR2|ID2_OUTR6);
if (p2 == ID2_CTR2) return true;
else if (p2 == ID2_OUTR6) s = selector_outer6;
else break;
}
goto eq_return;
case selector_center6:
case selector_outer2:
p2 = pid2 & (ID2_CTR6|ID2_OUTR2);
if (p2 == ID2_CTR6) s = selector_center6;
else if (p2 == ID2_OUTR2) s = selector_outer2;
else break;
goto eq_return;
case selector_veryends: /* Gotta fix this stuff - use fall-through variable. */
p2 = pid2 & (ID2_CTR6|ID2_OUTR2);
if (p2 == ID2_CTR6) s = selector_center6;
else if (p2 == ID2_OUTR2) s = selector_veryends;
else break;
goto eq_return;
case selector_ctrdmd:
case selector_notctrdmd:
p2 = pid2 & (ID2_CTRDMD|ID2_NCTRDMD);
if (p2 == ID2_CTRDMD) s = selector_ctrdmd;
else if (p2 == ID2_NCTRDMD) s = selector_notctrdmd;
else break;
goto eq_return;
case selector_center_col_of_6:
// In these three setups, "center column of 6" has a different meaning than the 1x6
// meaning used in the rest of this program. It means the same as "center 6".
// Of course, in a 3x4, the population will have to be correct.
if (ss->kind == s3x4 || ss->kind == s_qtag || ss->kind == s_spindle) {
p2 = pid2 & (ID2_CTR6|ID2_OUTR2);
if (p2 == ID2_CTR6) return true;
else if (p2 == ID2_OUTR2) return false;
else break;
}
// FALL THROUGH!!!
case selector_ctr_1x6:
case selector_center_wave_of_6:
case selector_center_line_of_6:
// FELL THROUGH!!!
if ((pid2 & (ID2_CTR1X6|ID2_NCTR1X6)) == ID2_CTR1X6) return true;
else if ((pid2 & (ID2_CTR1X6|ID2_NCTR1X6)) == ID2_NCTR1X6) return false;
break;
case selector_outer1x3s:
if ((pid2 & (ID2_OUTR1X3|ID2_NOUTR1X3)) == ID2_OUTR1X3) return true;
else if ((pid2 & (ID2_OUTR1X3|ID2_NOUTR1X3)) == ID2_NOUTR1X3) return false;
break;
case selector_ctr_1x4:
case selector_center_wave:
case selector_center_line:
case selector_center_col:
if ((pid2 & (ID2_CTR1X4|ID2_NCTR1X4)) == ID2_CTR1X4) return true;
else if ((pid2 & (ID2_CTR1X4|ID2_NCTR1X4)) == ID2_NCTR1X4) return false;
break;
case selector_center4:
if ((pid2 & (ID2_CTR4|ID2_OUTRPAIRS)) == ID2_CTR4) return true;
else if ((pid2 & (ID2_CTR4|ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return false;
else if ((pid2 & (ID2_CTR4|ID2_END)) == ID2_CTR4) return true;
else if ((pid2 & (ID2_CTR4|ID2_END)) == ID2_END) return false;
else if ((pid2 & (ID2_CTR4|ID2_NCTR1X4)) == ID2_CTR4) return true;
else if ((pid2 & (ID2_CTR4|ID2_NCTR1X4)) == ID2_NCTR1X4) return false;
break;
case selector_center_box:
if ((pid2 & (ID2_CTR4|ID2_OUTRPAIRS)) == ID2_CTR4) return true;
else if ((pid2 & (ID2_CTR4|ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return false;
else if ((pid2 & (ID2_CTR4|ID2_END)) == ID2_CTR4) return true;
else if ((pid2 & (ID2_CTR4|ID2_END)) == ID2_END) return false;
break;
case selector_outerpairs:
if (ss->kind == s1x6) {
if ((pid2 & (ID2_CTR2 |ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return true;
else if ((pid2 & (ID2_CTR2 |ID2_OUTRPAIRS)) == ID2_CTR2) return false;
}
else {
if ((pid2 & (ID2_CTR4 |ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return true;
else if ((pid2 & (ID2_CENTER|ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return true;
else if ((pid2 & (ID2_CTR1X4|ID2_OUTRPAIRS)) == ID2_OUTRPAIRS) return true;
else if ((pid2 & (ID2_CTR4 |ID2_OUTRPAIRS)) == ID2_CTR4) return false;
else if ((pid2 & (ID2_CENTER|ID2_OUTRPAIRS)) == ID2_CENTER) return false;
else if ((pid2 & (ID2_CTR1X4|ID2_OUTRPAIRS)) == ID2_CTR1X4) return false;
}
break;
case selector_the2x3:
switch (ss->kind) {
case s_spindle:
selected_person_mask = 0x77;
break;
case s_qtag:
selected_person_mask = 0xBB;
break;
case s4x4:
if (livemask == 0x0F03333FU)
selected_person_mask = 0xE888;
else if (livemask == 0x3F0F0333U)
selected_person_mask = 0x888E;
else if (livemask == 0x333F0F03U)
selected_person_mask = 0x88E8;
else if (livemask == 0x03333F0FU)
selected_person_mask = 0x8E88;
break;
}
break;
case selector_thediamond:
p2 = pid2 & (ID2_CTRDMD|ID2_NCTRDMD);
if (p2 == ID2_CTRDMD) return true;
else if (p2 == ID2_NCTRDMD) return false;
switch (ss->kind) {
case s1x3p1dmd:
case s3p1x1dmd:
selected_person_mask = 074;
break;
case s1x4p2dmd:
case s4p2x1dmd:
selected_person_mask = 0xD8;
break;
case splinepdmd:
case splinedmd:
selected_person_mask = 0xF0;
break;
case slinepdmd:
case slinedmd:
case sboxpdmd:
case sboxdmd:
selected_person_mask = 0x0F;
break;
}
break;
case selector_theline:
switch (ss->kind) {
case s4x4:
if (livemask == 0x0F03333FU)
selected_person_mask = 0x0A84;
else if (livemask == 0x3F0F0333U)
selected_person_mask = 0xA840;
else if (livemask == 0x333F0F03U)
selected_person_mask = 0x840A;
else if (livemask == 0x03333F0FU)
selected_person_mask = 0x40A8;
break;
case splinepdmd:
case splinedmd:
case slinebox:
if ((directions & livemask & 0x5500) == 0)
selected_person_mask = 0x0F;
break;
case slinepdmd:
case slinedmd:
if ((directions & livemask & 0x0055) == 0)
selected_person_mask = 0xF0;
break;
}
break;
case selector_thecolumn:
switch (ss->kind) {
case s4x4:
if (livemask == 0x0F03333FU)
selected_person_mask = 0x0A84;
else if (livemask == 0x3F0F0333U)
selected_person_mask = 0xA840;
else if (livemask == 0x333F0F03U)
selected_person_mask = 0x840A;
else if (livemask == 0x03333F0FU)
selected_person_mask = 0x40A8;
break;
case splinepdmd:
case splinedmd:
case slinebox:
if (((directions ^ 0x5500) & livemask & 0x5500) == 0)
selected_person_mask = 0x0F;
break;
case slinepdmd:
case slinedmd:
if (((directions ^ 0x0055) & livemask & 0x0055) == 0)
selected_person_mask = 0xF0;
break;
}
break;
case selector_headliners:
p2 = pid2 & (ID2_FACEFRONT|ID2_FACEBACK|ID2_FACELEFT|ID2_FACERIGHT);
if (p2 == ID2_FACEFRONT || p2 == ID2_FACEBACK) return true;
else if (p2 == ID2_FACELEFT || p2 == ID2_FACERIGHT) return false;
break;
case selector_sideliners:
p2 = pid2 & (ID2_FACEFRONT|ID2_FACEBACK|ID2_FACELEFT|ID2_FACERIGHT);
if (p2 == ID2_FACELEFT || p2 == ID2_FACERIGHT) return true;
else if (p2 == ID2_FACEFRONT || p2 == ID2_FACEBACK) return false;
break;
case selector_thosefacing:
if ((pid2 & (ID2_FACING|ID2_NOTFACING)) == ID2_FACING) return true;
else if ((pid2 & (ID2_FACING|ID2_NOTFACING)) == ID2_NOTFACING) return false;
break;
case selector_facingfront:
if (pid2 & ID2_FACEFRONT) return true;
else if (pid2 & (ID2_FACEBACK|ID2_FACELEFT|ID2_FACERIGHT)) return false;
break;
case selector_facingback:
if (pid2 & ID2_FACEBACK) return true;
else if (pid2 & (ID2_FACEFRONT|ID2_FACELEFT|ID2_FACERIGHT)) return false;
break;
case selector_facingleft:
if (pid2 & ID2_FACELEFT) return true;
else if (pid2 & (ID2_FACEFRONT|ID2_FACEBACK|ID2_FACERIGHT)) return false;
break;
case selector_facingright:
if (pid2 & ID2_FACERIGHT) return true;
else if (pid2 & (ID2_FACEFRONT|ID2_FACEBACK|ID2_FACELEFT)) return false;
break;
case selector_lineleft:
if (pid2 & ID2_LEFTLINE) return true;
else if (pid2 & ID2_RIGHTLINE) return false;
break;
case selector_lineright:
if (pid2 & ID2_RIGHTLINE) return true;
else if (pid2 & ID2_LEFTLINE) return false;
break;
case selector_columnleft:
if (pid2 & ID2_LEFTCOL) return true;
else if (pid2 & ID2_RIGHTCOL) return false;
break;
case selector_columnright:
if (pid2 & ID2_RIGHTCOL) return true;
else if (pid2 & ID2_LEFTCOL) return false;
break;
case selector_boxleft:
if (pid2 & ID2_LEFTBOX) return true;
else if (pid2 & ID2_RIGHTBOX) return false;
break;
case selector_boxright:
if (pid2 & ID2_RIGHTBOX) return true;
else if (pid2 & ID2_LEFTBOX) return false;
break;
case selector_nearline:
if (pid3 & ID3_NEARLINE) return true;
else if (pid3 & (ID3_FARLINE|ID3_FARCOL|ID3_FARBOX|ID3_FARFOUR)) return false;
break;
case selector_farline:
if (pid3 & ID3_FARLINE) return true;
else if (pid3 & (ID3_NEARLINE|ID3_NEARCOL|ID3_NEARBOX|ID3_NEARFOUR)) return false;
break;
case selector_nearcolumn:
if (pid3 & ID3_NEARCOL) return true;
else if (pid3 & (ID3_FARLINE|ID3_FARCOL|ID3_FARBOX|ID3_FARFOUR)) return false;
break;
case selector_farcolumn:
if (pid3 & ID3_FARCOL) return true;
else if (pid3 & (ID3_NEARLINE|ID3_NEARCOL|ID3_NEARBOX|ID3_NEARFOUR)) return false;
break;
case selector_nearbox:
if (pid3 & ID3_NEARBOX) return true;
else if (pid3 & (ID3_FARLINE|ID3_FARCOL|ID3_FARBOX)) return false;
break;
case selector_farbox:
if (pid3 & ID3_FARBOX) return true;
else if (pid3 & (ID3_NEARLINE|ID3_NEARCOL|ID3_NEARBOX)) return false;
break;
case selector_nearfour:
if (pid3 & ID3_NEARFOUR) return true;
else if (pid3 & ID3_FARFOUR) return false;
break;
case selector_farfour:
if (pid3 & ID3_FARFOUR) return true;
else if (pid3 & ID3_NEARFOUR) return false;
break;
case selector_neartwo:
if (pid3 & ID3_NEARTWO) return true;
else if (pid3 & ID3_FARSIX) return false;
break;
case selector_fartwo:
if (pid3 & ID3_FARTWO) return true;
else if (pid3 & ID3_NEARSIX) return false;
break;
case selector_nearsix:
if (pid3 & ID3_NEARSIX) return true;
else if (pid3 & ID3_FARTWO) return false;
break;
case selector_farsix:
if (pid3 & ID3_FARSIX) return true;
else if (pid3 & ID3_NEARTWO) return false;
break;
case selector_nearthree:
if (pid3 & ID3_NEARTHREE) return true;
else if (pid3 & ID3_FARFIVE) return false;
break;
case selector_farthree:
if (pid3 & ID3_FARTHREE) return true;
else if (pid3 & ID3_NEARFIVE) return false;
break;
case selector_nearfive:
if (pid3 & ID3_NEARFIVE) return true;
else if (pid3 & ID3_FARTHREE) return false;
break;
case selector_farfive:
if (pid3 & ID3_FARFIVE) return true;
else if (pid3 & ID3_NEARTHREE) return false;
break;
case selector_farthest1:
if (pid3 & ID3_FARTHEST1) return true;
else if (pid3 & (ID3_NOTFARTHEST1)) return false;
break;
case selector_nearest1:
if (pid3 & ID3_NEAREST1) return true;
else if (pid3 & (ID3_NOTNEAREST1)) return false;
break;
// For the unsymmetrical selectors, we demand that the person not be virtual
// (e.g. tandem person) or active phantom. The former requirement could cause
// us to lose a few extremely rare cases, but it isn't worth using up zillions of bits.
case selector_boy1:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0000;
break;
case selector_girl1:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0100;
break;
case selector_cpl1:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK & ~0100) == 0000;
break;
case selector_boy2:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0200;
break;
case selector_girl2:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0300;
break;
case selector_cpl2:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK & ~0100) == 0200;
break;
case selector_boy3:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0400;
break;
case selector_girl3:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0500;
break;
case selector_cpl3:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK & ~0100) == 0400;
break;
case selector_boy4:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0600;
break;
case selector_girl4:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK) == 0700;
break;
case selector_cpl4:
if (!(pid1 & (XPID_MASK & ~PID_MASK))) return (pid1 & PID_MASK & ~0100) == 0600;
break;
case selector_cpls1_2:
if (!(pid1 & (XPID_MASK & ~PID_MASK)))
return (pid1 & PID_MASK & ~0300) == 0000;
break;
case selector_cpls2_3:
if (!(pid1 & (XPID_MASK & ~PID_MASK)))
return ((pid1+0200) & PID_MASK & ~0300) == 0400;
break;
case selector_cpls3_4:
if (!(pid1 & (XPID_MASK & ~PID_MASK)))
return (pid1 & PID_MASK & ~0300) == 0400;
break;
case selector_cpls4_1:
if (!(pid1 & (XPID_MASK & ~PID_MASK)))
return ((pid1+0200) & PID_MASK & ~0300) == 0000;
break;
case selector_firstone:
case selector_lastone:
case selector_firsttwo:
case selector_lasttwo:
case selector_firstthree:
case selector_lastthree:
if (ss->kind == s2x4) {
if (directions == (livemask & 0x55FF))
thing_to_test = place & 3; // Right column.
else if (directions == (livemask & 0xFF55))
thing_to_test = 3-(place & 3); // Left column.
else
break;
goto first_last_test;
}
break;
case selector_leftmostone:
case selector_rightmostone:
case selector_leftmosttwo:
case selector_rightmosttwo:
case selector_leftmostthree:
case selector_rightmostthree:
if (ss->kind == s2x4) {
if (directions == (livemask & 0x00AA))
thing_to_test = place & 3; // Lines out.
else if (directions == (livemask & 0xAA00))
thing_to_test = 3-(place & 3); // Lines in.
else
break;
goto first_last_test;
}
break;
case selector_some:
// We have to figure out how to group the people, based on unambiguous information from facing directions.
thing_to_test = -1;
switch (attr::slimit(ss)) {
uint32 A, B, C, D, E, F;
case 5:
A = (directions >> 4) & 00303;
B = (directions >> 2) & 00303;
C = (directions >> 0) & 00303;
if (allow_some == 2) {
switch (ss->kind) {
case s_1x2dmd:
if (A == B) thing_to_test = 0x3;
break;
case s_short6:
if (A == C) thing_to_test = 0x5;
break;
case s1x6:
if (A == B && B != C) thing_to_test = 0x3;
else if (B == C && A != B) thing_to_test = 0x6;
break;
case s2x3:
if (A == B && B != C) thing_to_test = 0x3;
else if (B == C && A != B) thing_to_test = 0x6;
break;
}
}
if (thing_to_test != -1) return ((thing_to_test >> (place % 3)) & 1) != 0;
break;
case 7:
A = (directions >> 6) & 0x0303;
B = (directions >> 4) & 0x0303;
C = (directions >> 2) & 0x0303;
D = (directions >> 0) & 0x0303;
if (allow_some == 2) {
switch (ss->kind) {
case s1x3dmd:
if (A == B && B != C) thing_to_test = 0x3;
else if (B == C && A != B) thing_to_test = 0x6;
break;
case s1x8:
if (A == B && B != D && C != D) thing_to_test = 0x3;
else if (B == D && C != D && A != B) thing_to_test = 0xA;
else if (C == D && B != D && A != B) thing_to_test = 0xC;
break;
case s2x4:
if (A == B && B != C && C != D) thing_to_test = 0x3;
else if (B == C && C != D && A != B) thing_to_test = 0x6;
else if (C == D && B != C && A != B) thing_to_test = 0xC;
break;
case s_ptpd:
if (B == D) thing_to_test = 0xA;
break;
case s_bone:
if ((C ^ D) == 0x202 && (A ^ B) == 0x202) thing_to_test = 0x3;
break;
case s_rigger:
if ((C ^ D) == 0x202 && (A ^ B) == 0x202) thing_to_test = 0x3;
break;
}
}
else if (allow_some == 3) {
switch (ss->kind) {
case s_323:
case s1x3dmd:
if (A == B && B == C) thing_to_test = 0x7;
break;
case s_qtag:
if ((A ^ 0x0202) == B && B == D) thing_to_test = 0xB;
break;
case s1x8:
if (A == B && B == D && C != D) thing_to_test = 0xB;
else if (B == C && C == D && A != B) thing_to_test = 0xE;
break;
case s2x4:
if (A == B && B == C && C != D) thing_to_test = 0x7;
else if (B == C && C == D && A != B) thing_to_test = 0xE;
break;
}
}
if (thing_to_test != -1) return ((thing_to_test >> (place & 3)) & 1) != 0;
break;
case 11:
A = (directions >> 10) & 0x003003;
B = (directions >> 8) & 0x003003;
C = (directions >> 6) & 0x003003;
D = (directions >> 4) & 0x003003;
E = (directions >> 2) & 0x003003;
F = (directions >> 0) & 0x003003;
if (allow_some == 3) {
switch (ss->kind) {
case s3x4:
if (livemask == 0xC3FC3F && (A ^ 0x002002) == D && D == E) thing_to_test = 0x19;
else if (livemask == 0x3CF3CF && (B ^ 0x002002) == C && C == F) thing_to_test = 0x26;
break;
}
}
if (thing_to_test != -1) return ((thing_to_test >> (place % 6)) & 1) != 0;
break;
}
break;
default:
fail("INTERNAL ERROR - selector failed to get initialized.");
}
if (selected_person_mask != ~0U) {
if (selected_person_mask & (1 << place)) return true;
else return false;
}
fail("Can't decide who are selected.");
eq_return:
return (current_options.who == s);
first_last_test:
switch (current_options.who) {
case selector_firstone: case selector_rightmostone:
return thing_to_test >= 3;
case selector_firsttwo: case selector_rightmosttwo:
return thing_to_test >= 2;
case selector_firstthree: case selector_rightmostthree:
return thing_to_test >= 1;
case selector_lastone: case selector_leftmostone:
return thing_to_test < 1;
case selector_lasttwo: case selector_leftmosttwo:
return thing_to_test < 2;
case selector_lastthree: case selector_leftmostthree:
return thing_to_test < 3;
}
fail("Can't decide who are selected."); // Won't happen.
}
static const int32 iden_tab[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
static const int32 dbl_tab01[4] = {0, 1, 0, 1};
static const int32 dbl_tab21[4] = {2, 1, 1, 0};
static const int32 x22tabtandem[4] = {3, 0, 1, 0};
static const int32 x22tabantitandem[4] = {3, 2, 1, 0};
static const int32 x22tabfacing[4] = {3, 2, 1, 0x1B};
static const int32 x24tabtandem[4] = {7, 0, 1, 0};
static const int32 x24tabantitandem[4] = {7, 2, 1, 0};
static const int32 x24tabfacing[4] = {7, 2, 1, 0x1B1B};
static const int32 boystuff_no_rh[3] = {ID3_PERM_BOY, ID3_PERM_GIRL, 0};
static const int32 girlstuff_no_rh[3] = {ID3_PERM_GIRL, ID3_PERM_BOY, 0};
static const int32 boystuff_rh[3] = {ID3_PERM_BOY, ID3_PERM_GIRL, 1};
static const int32 girlstuff_rh[3] = {ID3_PERM_GIRL, ID3_PERM_BOY, 1};
static const int32 samesex[2] = {0, ID3_PERM_BOY|ID3_PERM_GIRL};
static const int32 semi_squeeze_tab[8] = {0xD, 0xE, 0x9, 0x9, 0x2, 0xD, 0x2, 0xE};
// Here are the predicates. They will get put into the array "pred_table".
/* ARGSUSED */
static bool someone_selected(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
return selectp(real_people, real_index ^ (*extra_stuff));
}
/* ARGSUSED */
static bool sum_mod_selected(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int otherindex = (*extra_stuff) - real_index;
int size = attr::slimit(real_people)+1;
if (otherindex >= size) otherindex -= size;
else if (otherindex < 0) otherindex += size;
return selectp(real_people, otherindex);
}
/* ARGSUSED */
static bool sum_mod_selected_for_12p(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int otherindex = (*extra_stuff) - real_index;
if ((real_index % 6) >= 3) otherindex += 4;
int size = attr::slimit(real_people)+1;
if (otherindex >= size) otherindex -= size;
return selectp(real_people, otherindex);
}
/* ARGSUSED */
static bool plus_mod_selected(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int otherindex = real_index + (*extra_stuff);
int size = attr::slimit(real_people)+1;
if (otherindex >= size) otherindex -= size;
return selectp(real_people, otherindex);
}
static const int32 l_4x3_tab[12] = {
-99, -99, -99, -99, 3, 2, 4, 5, 11, 10, 0, 1};
static const int32 r_4x3_tab[12] = {
10, 11, 5, 4, 6, 7, -99, -99, -99, -99, 9, 8};
static const int32 adj_4x4_tab[16] =
{14, 3, 7, 1, 5, 4, 8, 2, 6, 11, 15, 9, 13, 12, 0, 10};
static const int32 or_4x4_tab[16] =
{13, 15, 11, 10, 6, 8, 4, 9, 5, 7, 3, 2, 14, 0, 12, 1};
static const int32 ctr_4x4_tab[16] =
{-99, -99, -99, 15, -99, 6, 5, 11, -99, -99, -99, 7, -99, 14, 13, 3};
static const int32 end_4x4_tab[16] =
{12, 10, 9, -99, 8, -99, -99, -99, 4, 2, 1, -99, 0, -99, -99, -99};
/* ARGSUSED */
static bool select_with_special(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
if (!selectp(real_people, real_index)) return false;
int32 otherindex = extra_stuff[northified_index]+real_index-northified_index;
if (otherindex < -50) return false; // Check for -99 even though it's been finagled.
int size = attr::slimit(real_people)+1;
if (otherindex >= size) otherindex -= size;
else if (otherindex < 0) otherindex += size;
if (!(real_people->people[otherindex].id1 & BIT_PERSON)) return false;
return selectp(real_people, otherindex);
}
/* ARGSUSED */
static bool semi_squeezer_select(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int other_index = ((northified_index ^ extra_stuff[northified_index&7]) + real_index - northified_index) & 0xF;
return (real_people->people[other_index].id1 & BIT_PERSON) &&
selectp(real_people, other_index);
}
/* ARGSUSED */
static bool unselect(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
return !selectp(real_people, real_index);
}
/* ARGSUSED */
static bool select_near_select(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
if (!selectp(real_people, real_index)) return false;
if (current_options.who == selector_all || current_options.who == selector_everyone)
return true;
return (real_people->people[real_index ^ 1].id1 & BIT_PERSON) &&
selectp(real_people, real_index ^ 1);
}
static int base_table[12] = {0, 0, 0, 3, 3, 3, 6, 6, 6, 9, 9, 9};
/* ARGSUSED */
static bool select_near_select_or_phantom(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int lim, base_person;
if (!selectp(real_people, real_index))
return false;
else if (current_options.who == selector_all || current_options.who == selector_everyone)
return true;
if (attr::slimit(real_people) == 11) {
base_person = base_table[real_index];
lim = 2;
}
if (attr::slimit(real_people) == 15) {
base_person = real_index & 4;
lim = 3;
}
else {
return
!(real_people->people[real_index ^ 1].id1 & BIT_PERSON) ||
selectp(real_people, real_index ^ 1);
}
for ( ; lim >= 0 ; lim--) {
if ((real_people->people[base_person+lim].id1 & BIT_PERSON) &&
!selectp(real_people, base_person+lim))
return false;
}
return true;
}
/* ARGSUSED */
static bool select_near_unselect(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
if (!selectp(real_people, real_index)) return false;
if (current_options.who == selector_all || current_options.who == selector_everyone)
return false;
return !(real_people->people[real_index ^ 1].id1 & BIT_PERSON) ||
!selectp(real_people, real_index ^ 1);
}
/* ARGSUSED */
static bool unselect_near_select(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
if (selectp(real_people, real_index)) return false;
if (current_options.who == selector_none) return false;
return (real_people->people[real_index ^ 1].id1 & BIT_PERSON) &&
selectp(real_people, real_index ^ 1);
}
/* ARGSUSED */
static bool unselect_near_unselect(setup *real_people, int real_index,
int real_direction, int northified_index, const int32 *extra_stuff) THROW_DECL
{
int lim, base_person;
if (selectp(real_people, real_index)) return false;
else if (current_options.who == selector_none) return true;