forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdtop.cpp
More file actions
6926 lines (6065 loc) · 263 KB
/
Copy pathsdtop.cpp
File metadata and controls
6926 lines (6065 loc) · 263 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".
//
// 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 functions:
expand::compress_setup
expand::expand_setup
expand::fix_3x4_to_qtag
update_id_bits
clear_bits_for_update
clear_absolute_proximity_bits
clear_absolute_proximity_and_facing_bits
expand::initialize
full_expand::initialize_touch_tables
full_expand::search_table_1
full_expand::search_table_2
full_expand::search_table_3
big_endian_get_directions
touch_or_rear_back
do_matrix_expansion
initialize_sdlib
check_for_concept_group
crash_print
fail
fail_no_retry
fail2
failp
specialfail
saved_error_info::collect
saved_error_info::throw_saved_error
warn
verify_restriction
assoc
uncompress_position_number
clear_result_flags
setup::setup // big constructor.
clear_result
rotperson
rotcw
rotccw
copy_person
copy_rot
install_person
install_rot
scatter
gather
install_scatter
warn_about_concept_level
turn_4x4_pinwheel_into_c1_phantom
clean_up_unsymmetrical_setup
process_final_concepts
really_skip_one_concept
fix_n_results
warnings_are_unacceptable
normalize_setup
check_concept_parse_tree
check_for_centers_concept
toplevelmove
finish_toplevelmove
deposit_call_tree
do_subcall_query
find_proper_call_list
and the following external variables:
text_line_count
error_message1
error_message2
collision_person1
collision_person2
last_magic_diamond
configuration::history
config_history_ptr
configuration::whole_sequence_low_lim
history_allocation
written_history_items
no_erase_before_this
written_history_nopic
the_topcallflags
there_is_a_call
base_calls
ui_options
enable_file_writing
cardinals
ordinals
getout_strings
writechar_block
num_command_commands
command_commands
command_command_values
num_startup_commands
startup_commands
startup_command_values
resolve_command_values
number_of_resolve_commands
resolve_command_strings
glob_abridge_mode
abs_max_calls
max_base_calls
tagger_menu_list
selector_menu_list
direction_menu_list
circcer_menu_list
tagger_calls
circcer_calls
number_of_taggers
number_of_taggers_allocated
number_of_circcers
number_of_circcers_allocated
parse_state
current_options
no_search_warnings
conc_elong_warnings
dyp_each_warnings
useless_phan_clw_warnings
allowing_all_concepts
allowing_minigrand
enforce_overcast_warning
using_active_phantoms
last_direction_kind
interactivity
database_version
testing_fidelity
level_threshholds_for_pick
allowing_modifications
hashed_randoms
concept_sublist_sizes
concept_sublists
good_concept_sublist_sizes
good_concept_sublists
null_options
verify_options
verify_used_number
verify_used_direction
verify_used_selector
*/
// For memset, memcpy, and strncpy.
#include <string.h>
#include "sd.h"
#include "sdui.h"
// *** There are more globals proclaimed at line 235.
ui_utils *gg77 = 0;
int text_line_count = 0;
char error_message1[MAX_ERR_LENGTH];
char error_message2[MAX_ERR_LENGTH];
uint32 collision_person1;
uint32 collision_person2;
int config_history_ptr;
parse_block *last_magic_diamond;
int history_allocation;
/* This tells how much of the history text written to the UI is "safe". If this
is positive, the history items up to that number, inclusive, have valid
"text_line" fields, and have had their text written to the UI. Furthermore,
the local variable "text_line_count" is >= any of those "text_line" fields,
and each "text_line" field shows the number of lines of text that were
written to the UI when that history item was written. This variable is
-1 when none of the history is safe or the state of the text in the UI
is unknown. */
int written_history_items;
// Normally zero. When this becomes nonzero, the next clear_screen will
// consider the "screen" to go back only that many lines, so that anything
// before that will never be subject to being erased.
int no_erase_before_this;
// When written_history_items is positive, this tells how many of the initial lines
// did not have pictures forced on (other than having been drawn as a natural consequence
// of the "draw_pic" flag being on.) If this number ever becomes greater than
// written_history_items, that's OK. It just means that none of the lines had
// forced pictures.
int written_history_nopic;
// This list tells what level calls will be accepted for the "pick level call"
// operation. When doing a "pick level call, we don't actually require calls
// to be exactly on the indicated level, as long as it's plausibly close.
//
// BEWARE!! This list is keyed to the definition of "dance_level" in database.h .
dance_level level_threshholds_for_pick[] = {
l_mainstream,
l_plus,
l_a1,
l_a1, // If a2 is given, an a1 call is OK.
l_c1,
l_c2,
l_c3a,
l_c3a, // If c3 is given, a c3a call is OK.
l_c3a, // If c3x is given, a c3a call is OK.
l_c3x, // If c4a is given, a c3x call is OK (unless the "no_c3x" switch has been given.)
l_c3x, // Same.
l_c3x, // Same.
l_dontshow,
l_nonexistent_concept};
// BEWARE!! This list is keyed to the definition of "dance_level" in database.h .
Cstring getout_strings[] = {
"Mainstream",
"Plus",
"A1",
"A2",
"C1",
"C2",
"C3A",
"C3",
"C3X",
"C4A",
"C4",
"C4X",
"all",
""};
// *** There are more globals proclaimed at line 164.
uint32 the_topcallflags;
bool there_is_a_call;
call_with_name **base_calls; // Gets allocated as array of pointers in sdinit.
int configuration::whole_sequence_low_lim;
configuration *configuration::history = (configuration *) 0; // Will be allocated in sdmain.
bool enable_file_writing;
// The variable "last_direction_kind" below, gets manipulated
// at startup in order to remove the "zig-zag" and "the music" at certain levels.
int num_command_commands; // Size of the command menu.
Cstring *command_commands;
command_kind *command_command_values;
int num_startup_commands; // Size of the startup menu.
Cstring *startup_commands;
start_select_kind *startup_command_values;
int number_of_resolve_commands;
Cstring *resolve_command_strings;
resolve_command_kind *resolve_command_values;
int abs_max_calls;
int max_base_calls;
Cstring *tagger_menu_list[NUM_TAGGER_CLASSES];
Cstring *selector_menu_list;
Cstring *direction_menu_list;
Cstring *circcer_menu_list;
call_with_name **tagger_calls[NUM_TAGGER_CLASSES];
call_with_name **circcer_calls;
uint32 number_of_taggers[NUM_TAGGER_CLASSES];
uint32 number_of_taggers_allocated[NUM_TAGGER_CLASSES];
uint32 number_of_circcers;
uint32 number_of_circcers_allocated;
parse_state_type parse_state;
call_conc_option_state current_options;
warning_info no_search_warnings;
warning_info conc_elong_warnings;
warning_info dyp_each_warnings;
warning_info useless_phan_clw_warnings;
bool allowing_all_concepts = false;
bool allowing_minigrand = false;
bool enforce_overcast_warning = false;
bool using_active_phantoms = false;
int last_direction_kind = direction_ENUM_EXTENT-1;
interactivity_state interactivity = interactivity_normal;
char database_version[81];
bool testing_fidelity = false;
int allowing_modifications = 0;
int hashed_randoms;
/* These two direct the generation of random concepts when we are searching.
We make an attempt to generate somewhat plausible concepts, depending on the
setup we are in. If we just generated evenly weighted concepts from the entire
concept list, we would hardly ever get a legal one. */
int concept_sublist_sizes[call_list_extent];
short int *concept_sublists[call_list_extent];
/* These two are similar, but contain only "really nice" concepts that
we are willing to use in exhaustive searches. Concepts in these
lists are very "expensive", in that each one causes an exhaustive search
through all calls (with nearly-exhaustive enumeration of numbers/selectors, etc).
Also, these concepts will appear in suggested resolves very early on. So
we don't want anything the least bit ugly in these lists. */
int good_concept_sublist_sizes[call_list_extent];
short int *good_concept_sublists[call_list_extent];
const call_conc_option_state null_options = {
selector_uninitialized,
direction_uninitialized,
0, 0, 0, 0, 0};
call_conc_option_state verify_options;
bool verify_used_number;
bool verify_used_direction;
bool verify_used_selector;
// A few accessors to let the UI stuff survive.
uint32 get_concparseflags(const concept_descriptor *foo) { return foo->concparseflags; }
const char *get_call_name(const call_with_name *foo) { return foo->name; }
const char *get_call_menu_name(const call_with_name *foo) { return foo->menu_name; }
dance_level get_concept_level(const concept_descriptor *foo) { return foo->level; }
Cstring get_concept_name(const concept_descriptor *foo) { return foo->name; }
Cstring get_concept_menu_name(const concept_descriptor *foo) { return foo->menu_name; }
concept_kind get_concept_kind(const concept_descriptor *foo) { return foo->kind; }
const concept_descriptor *access_concept_descriptor_table(int i) { return &concept_descriptor_table[i]; }
bool get_yield_if_ambiguous_flag(call_with_name *foo) {return (foo->the_defn.callflagsf & CFLAG2_YIELD_IF_AMBIGUOUS) != 0; }
call_with_name *access_base_calls(int i) { return base_calls[i]; }
void set_parse_block_concept(parse_block *p, const concept_descriptor *concept) { p->concept = concept; }
void set_parse_block_next(parse_block *p, parse_block *next) { p->next = next; }
void set_parse_block_call(parse_block *p, call_with_name *call) { p->call = call; }
void set_parse_block_call_to_print(parse_block *p, call_with_name *call) { p->call_to_print = call; }
void set_parse_block_replacement_key(parse_block *p, short int key) { p->replacement_key = key; }
parse_block **get_parse_block_subsidiary_root_addr(parse_block *p) { return &p->subsidiary_root; }
const concept_kind constant_with_concept_diagnose = concept_diagnose;
const concept_kind constant_with_marker_end_of_list = marker_end_of_list;
parse_block *get_parse_block_mark() { return parse_block::parse_active_list; }
parse_block *get_parse_block()
{
parse_block *item;
if (parse_block::parse_inactive_list) {
item = parse_block::parse_inactive_list;
parse_block::parse_inactive_list = item->gc_ptr;
}
else {
item = new parse_block;
}
item->gc_ptr = parse_block::parse_active_list;
parse_block::parse_active_list = item;
item->initialize((concept_descriptor *) 0);
return item;
}
warning_info config_save_warnings()
{ return configuration::save_warnings(); }
void config_restore_warnings(const warning_info & rhs)
{ configuration::restore_warnings(rhs); }
void expand::compress_setup(const expand::thing & thing, setup *stuff) THROW_DECL
{
setup temp = *stuff;
stuff->kind = thing.inner_kind;
stuff->clear_people();
gather(stuff, &temp, thing.source_indices, attr::klimit(thing.inner_kind), thing.rot * 011);
stuff->rotation -= thing.rot;
canonicalize_rotation(stuff);
}
void expand::expand_setup(const expand::thing & thing, setup *stuff) THROW_DECL
{
setup temp = *stuff;
stuff->kind = thing.outer_kind;
stuff->clear_people();
scatter(stuff, &temp, thing.source_indices, attr::klimit(thing.inner_kind), thing.rot * 033);
stuff->rotation += thing.rot;
canonicalize_rotation(stuff);
}
// Turn a 3x3 into a 1/4 tag if the spots are occupied appropriately. Otherwise do nothing.
void expand::fix_3x4_to_qtag(setup *stuff) THROW_DECL
{
static const expand::thing foo = {{1, 2, 4, 5, 7, 8, 10, 11}, s_qtag, s3x4, 0};
if ((little_endian_live_mask(stuff) & 01111) == 0)
expand::compress_setup(foo, stuff);
}
extern void update_id_bits(setup *ss)
{
int i;
unsigned short int *face_list = (uint16_t *) 0;
static uint16_t face_qtg[] = {
3, d_west, 7, d_east,
2, d_west, 3, d_east,
7, d_west, 6, d_east,
1, d_west, 0, d_east,
4, d_west, 5, d_east,
1, d_south, 3, d_north,
3, d_south, 4, d_north,
0, d_south, 7, d_north,
7, d_south, 5, d_north,
UINT16_C(~0)};
static uint16_t face_spindle[] = {
0, d_south, 6, d_north,
1, d_south, 5, d_north,
2, d_south, 4, d_north,
0, d_east, 1, d_west,
1, d_east, 2, d_west,
6, d_east, 5, d_west,
5, d_east, 7, d_west,
UINT16_C(~0)};
static uint16_t face_1x4[] = {
2, d_west, 3, d_east,
3, d_west, 1, d_east,
1, d_west, 0, d_east,
UINT16_C(~0)};
static uint16_t face_2x4[] = {
3, d_west, 2, d_east,
2, d_west, 1, d_east,
1, d_west, 0, d_east,
4, d_west, 5, d_east,
5, d_west, 6, d_east,
6, d_west, 7, d_east,
0, d_south, 7, d_north,
1, d_south, 6, d_north,
2, d_south, 5, d_north,
3, d_south, 4, d_north,
UINT16_C(~0)};
static uint16_t face_2x2[] = {
1, d_west, 0, d_east,
2, d_west, 3, d_east,
0, d_south, 3, d_north,
1, d_south, 2, d_north,
UINT16_C(~0)};
static uint16_t face_1x3[] = {
2, d_west, 1, d_east,
1, d_west, 0, d_east,
UINT16_C(~0)};
static uint16_t face_2x3[] = {
2, d_west, 1, d_east,
1, d_west, 0, d_east,
3, d_west, 4, d_east,
4, d_west, 5, d_east,
0, d_south, 5, d_north,
1, d_south, 4, d_north,
2, d_south, 3, d_north,
UINT16_C(~0)};
static uint16_t face_2x6[] = {
5, d_west, 4, d_east,
4, d_west, 3, d_east,
3, d_west, 2, d_east,
2, d_west, 1, d_east,
1, d_west, 0, d_east,
6, d_west, 7, d_east,
7, d_west, 8, d_east,
8, d_west, 9, d_east,
9, d_west, 10, d_east,
10, d_west, 11, d_east,
0, d_south, 11, d_north,
1, d_south, 10, d_north,
2, d_south, 9, d_north,
3, d_south, 8, d_north,
4, d_south, 7, d_north,
5, d_south, 6, d_north,
UINT16_C(~0)};
static uint16_t face_1x8[] = {
1, d_west, 0, d_east,
2, d_west, 3, d_east,
4, d_west, 5, d_east,
7, d_west, 6, d_east,
3, d_west, 1, d_east,
5, d_west, 7, d_east,
6, d_west, 2, d_east,
UINT16_C(~0)};
static uint16_t face_3x4[] = {
1, d_west, 0, d_east,
2, d_west, 1, d_east,
3, d_west, 2, d_east,
11, d_west, 10, d_east,
5, d_west, 11, d_east,
4, d_west, 5, d_east,
8, d_west, 9, d_east,
7, d_west, 8, d_east,
6, d_west, 7, d_east,
0, d_south, 10, d_north,
1, d_south, 11, d_north,
2, d_south, 5, d_north,
3, d_south, 4, d_north,
10, d_south, 9, d_north,
11, d_south, 8, d_north,
5, d_south, 7, d_north,
4, d_south, 6, d_north,
UINT16_C(~0)};
static uint16_t face_4x4[] = {
13, d_west, 12, d_east,
14, d_west, 13, d_east,
0, d_west, 14, d_east,
15, d_west, 10, d_east,
3, d_west, 15, d_east,
1, d_west, 3, d_east,
11, d_west, 9, d_east,
7, d_west, 11, d_east,
2, d_west, 7, d_east,
6, d_west, 8, d_east,
5, d_west, 6, d_east,
4, d_west, 5, d_east,
12, d_south, 10, d_north,
13, d_south, 15, d_north,
14, d_south, 3, d_north,
0, d_south, 1, d_north,
10, d_south, 9, d_north,
15, d_south, 11, d_north,
3, d_south, 7, d_north,
1, d_south, 2, d_north,
9, d_south, 8, d_north,
11, d_south, 6, d_north,
7, d_south, 5, d_north,
2, d_south, 4, d_north,
UINT16_C(~0)};
static uint16_t face_c1phan[] = {
2, d_west, 0, d_east,
5, d_west, 7, d_east,
8, d_west, 10, d_east,
15, d_west, 13, d_east,
1, d_south, 3, d_north,
4, d_south, 6, d_north,
11, d_south, 9, d_north,
14, d_south, 12, d_north,
UINT16_C(~0)};
static uint16_t face_4x5[] = {
1, d_west, 0, d_east,
2, d_west, 1, d_east,
3, d_west, 2, d_east,
4, d_west, 3, d_east,
8, d_west, 9, d_east,
7, d_west, 8, d_east,
6, d_west, 7, d_east,
5, d_west, 6, d_east,
16, d_west, 15, d_east,
17, d_west, 16, d_east,
18, d_west, 17, d_east,
19, d_west, 18, d_east,
13, d_west, 14, d_east,
12, d_west, 13, d_east,
11, d_west, 12, d_east,
10, d_west, 11, d_east,
0, d_south, 9, d_north,
1, d_south, 8, d_north,
2, d_south, 7, d_north,
3, d_south, 6, d_north,
4, d_south, 5, d_north,
9, d_south, 15, d_north,
8, d_south, 16, d_north,
7, d_south, 17, d_north,
6, d_south, 18, d_north,
5, d_south, 19, d_north,
15, d_south, 14, d_north,
16, d_south, 13, d_north,
17, d_south, 12, d_north,
18, d_south, 11, d_north,
19, d_south, 10, d_north,
UINT16_C(~0)};
clear_bits_for_update(ss);
uint32 livemask = little_endian_live_mask(ss);
const id_bit_table *ptr = setup_attrs[ss->kind].id_bit_table_ptr;
switch (ss->kind) {
case s_qtag:
face_list = face_qtg; break;
case s_spindle:
face_list = face_spindle; break;
case s1x4:
face_list = face_1x4; break;
case s2x4:
face_list = face_2x4; break;
case s1x8:
face_list = face_1x8; break;
case s2x2:
face_list = face_2x2; break;
case s2x3:
face_list = face_2x3; break;
case s3x4:
face_list = face_3x4; break;
case s4x4:
face_list = face_4x4; break;
case s_c1phan:
// This doesn't get all legal cases, but ...
if ((livemask & 0x5555) == 0 || (livemask & 0xAAAA) == 0 || (livemask & 0xA55A) == 0 || (livemask & 0x5AA5) == 0)
face_list = face_c1phan;
break;
case s4x5:
face_list = face_4x5; break;
case s2x6:
face_list = face_2x6; break;
case s1x3:
face_list = face_1x3; break;
}
if (face_list) {
for ( ; *face_list != UINT16_C(~0) ; ) {
short idx1 = *face_list++;
if ((ss->people[idx1].id1 & d_mask) == *face_list++) {
short idx2 = *face_list++;
if ((ss->people[idx2].id1 & d_mask) == *face_list++) {
ss->people[idx1].id2 |= ID2_FACING;
ss->people[idx2].id2 |= ID2_FACING;
}
}
else
face_list += 2;
}
for (i=0 ; i<=attr::slimit(ss) ; i++) {
if (ss->people[i].id1 && !(ss->people[i].id2 & ID2_FACING))
ss->people[i].id2 |= ID2_NOTFACING;
}
}
// Some setups are only recognized for ID bits with certain patterns of population.
// The bit tables make those assumptions, so we have to use the bit tables
// only if those assumptions are satisfied.
switch (ss->kind) {
case s2x5:
// We recognize "centers" or "center 4" if they are a Z within the center 6.
if (livemask == 0x3BDU || livemask == 0x2F7U)
ptr = id_bit_table_2x5_z;
// We recognize "center 6"/"outer 2" and "center 2"/"outer 6" if the center 2x3
// is fully occupied.
else if (livemask == 0x3DEU || livemask == 0x1EFU)
ptr = id_bit_table_2x5_ctr6;
break;
case sd2x5:
// We recognize "center 6"/"outer 2" and "center 2"/"outer 6" if the center 2x3
// is fully occupied.
if (livemask == 0x3DEU || livemask == 0x3BDU)
ptr = id_bit_table_d2x5_ctr6;
// We recognize "centers" or "center 4" if they are a Z within the center 6.
else if (livemask != 0x37BU && livemask != 0x1EFU)
ptr = (id_bit_table *) 0;
break;
case sd2x7:
// We recognize "centers" or "center 4" if they are a Z with outer wings.
if (livemask == 0x3C78U || livemask == 0x0D9BU)
ptr = id_bit_table_d2x7a;
else if (livemask == 0x366CU || livemask == 0x078FU)
ptr = id_bit_table_d2x7b;
// Otherwise, the center 6 must be fully occupied, and we
// recognize "center 6"/"outer 2" and "center 2"/"outer 6".
else if ((livemask & 0x0E1CU) != 0x0E1CU)
ptr = (id_bit_table *) 0;
break;
case s2x6:
/* **** This isn't really right -- it would allow "outer pairs bingo".
We really should only allow 2-person calls, unless we say
"outer triple boxes". So we're not completely sure what the right thing is. */
if (livemask == 07474U || livemask == 0x3CFU)
/* Setup is parallelogram, accept slightly stronger table. */
ptr = id_bit_table_2x6_pg;
break;
case s1x10:
/* We recognize center 4 and center 6 if this has center 6 filled, then a gap,
then isolated people. */
if (livemask != 0x3BDU) ptr = (id_bit_table *) 0;
break;
case s3x6:
// If the center 1x6 is fully occupied, use this better table.
if ((livemask & 0700700U) == 0700700U) ptr = id_bit_table_3x6_with_1x6;
// Or, if center 1x4 is occupied, use the standard table.
// Otherwise, fail.
if ((livemask & 0600600U) != 0600600U) ptr = (id_bit_table *) 0;
break;
case sbigdmd:
// If this is populated appropriately, we can identify "outer pairs".
if (livemask == 07474U || livemask == 0x3CFU) ptr = id_bit_table_bigdmd_wings;
break;
case sbigbone:
// If this is populated appropriately, we can identify "outer pairs".
if (livemask == 07474U || livemask == 0x3CFU) ptr = id_bit_table_bigbone_wings;
break;
case sbigdhrgl:
// If this is populated appropriately, we can identify "outer pairs".
if (livemask == 07474U || livemask == 0x3CFU) ptr = id_bit_table_bigdhrgl_wings;
break;
case sbighrgl:
// If this is populated appropriately, we can identify "outer pairs".
if (livemask == 07474U || livemask == 0x3CFU) ptr = id_bit_table_bighrgl_wings;
break;
case sbigh:
// If it's a "double bent tidal line", we can recognize the "center 4"
// and "outer pairs".
if (livemask != 06363U || livemask != 07474U) ptr = id_bit_table_bigh_dblbent;
// Otherwise, we recognize only the center 1x4, and only if it is full.
else if ((livemask & 06060U) != 06060U) ptr = (id_bit_table *) 0;
break;
case s_525:
if (livemask == 04747U) ptr = id_bit_table_525_nw;
else if (livemask == 07474U) ptr = id_bit_table_525_ne;
break;
case s_343:
if ((livemask & 0xE7) == 0xE7) ptr = id_bit_table_343_outr;
else if ((livemask & 0x318) == 0x318) ptr = id_bit_table_343_innr;
break;
case s_545:
if ((livemask & 0xF9F) == 0x387 || (livemask & 0xF9F) == 0xE1C)
ptr = id_bit_table_545_outr;
else if ((livemask & 0x3060) == 0x3060)
ptr = id_bit_table_545_innr;
break;
case s3x4:
// There are three special things we can recognize from here.
// If the setup is populated as an "H", we use a special table
// (*NOT* the usual one picked up from the setup_attrs list)
// that knows about the center 2 and the outer 6 and all that.
// If the center 2x3 is occupied, we use a table for that.
// If the setup is populated as offset lines/columns/whatever,
// we use the table from the setup_attrs list, that knows about
// the "outer pairs".
// If the corners are occupied but the ends of the center line
// are not, use a table that recognizes those corners as "ends".
// If occupied as Z's, recognize "center 4" as the center Z.
// If all else fails, we use the default table. */
if (livemask == 07171U) ptr = id_bit_table_3x4_h;
else if ((livemask & 04646U) == 04646U) ptr = id_bit_table_3x4_ctr6;
else if (livemask == 07474U || livemask == 06363U) ptr = id_bit_table_3x4_offset;
else if ((livemask & 03131U) == 01111U) ptr = id_bit_table_3x4_corners;
else if (livemask == 07272U || livemask == 06565U) ptr = id_bit_table_3x4_zs;
break;
case sd3x4:
if ((livemask & 01616U) != 01616U) ptr = (id_bit_table *) 0;
break;
case s4x4:
// We recognize centers and ends if this is populated as a butterfly.
// Otherwise, we recognize "center 4" only if those 4 spots are occupied.
if (livemask == 0x9999U)
ptr = id_bit_table_butterfly;
else if (livemask == 0xC9C9U || livemask == 0x9C9CU ||
livemask == 0xB8B8U || livemask == 0x8B8BU)
ptr = id_bit_table_4x4_outer_pairs;
else if ((livemask & 0x8888U) != 0x8888U)
ptr = (id_bit_table *) 0;
break;
case s4x6:
// The only selector we recognize is "center 4", when the center
// 2x2 box is full. Unfortunately, the table we get when this is so
// is something of a crock. It will recognize stupid things like
// "center line", "center wave", "center column", and "center 1x4".
// We expect users not to specify such things in a 4x6.
if ((livemask & 014001400U) != 014001400U)
ptr = (id_bit_table *) 0;
break;
case sdeepxwv:
// We recognize outer pairs if they are fully populated.
if ((livemask & 00303U) != 00303U) ptr = (id_bit_table *) 0;
break;
case swqtag:
// We recognize "center 6" if the center 2 spots are empty,
// so that there is a "short 6".
// Otherwise, we recognize the center 1x6 if it is fully populated.
if (livemask == 0x1EF)
ptr = id_bit_table_wqtag_hollow;
else if ((livemask & 0x39CU) != 0x39CU)
ptr = (id_bit_table *) 0;
break;
case s3dmd:
// The standard table requires all points, and centers of center diamond only, occupied.
// But first we look for a few other configurations.
// Look for center 1x6 occupied.
if ((livemask & 0xE38U) == 0xE38U) ptr = id_bit_table_3dmd_ctr1x6;
// Look for center 1x6 having center 1x4 occupied.
else if ((livemask & 0xC30U) == 0xC30U) ptr = id_bit_table_3dmd_ctr1x4;
// Look for center 1x4 and outer points.
else if (livemask == 06565U) ptr = id_bit_table_3dmd_in_out;
// Otherwise, see whether to accept default or reject everything.
else if (livemask != 04747U) ptr = (id_bit_table *) 0;
break;
case s4dmd:
// If center diamonds have only centers and outer ones only points, use this.
if (livemask == 0xC9C9U) ptr = id_bit_table_4dmd_cc_ee;
// Or if center 1x4 is occupied, use standard map.
else if ((livemask & 0xC0C0U) != 0xC0C0U) ptr = (id_bit_table *) 0;
break;
case s3ptpd:
// If the center diamond is full and the inboard points of each outer diamond
// is present, we can do a "triple trade".
if (livemask == 06666U || livemask == 06363U || livemask == 07272U)
ptr = id_bit_table_3ptpd;
break;
case s_hsqtag:
// Only allow it if outer pairs are together.
if (livemask != 0xF3CU && livemask != 0xCF3U) ptr = (id_bit_table *) 0;
break;
}
if (!ptr) return;
for (i=0; i<=attr::slimit(ss); i++) {
if (ss->people[i].id1 & BIT_PERSON)
ss->people[i].id2 |= ptr[i][ss->people[i].id1 & 3];
}
}
extern void clear_bits_for_update(setup *ss)
{
for (int i=0; i<MAX_PEOPLE; i++) {
ss->people[i].id2 &= ~ID2_BITS_TO_CLEAR_FOR_UPDATE;
}
}
extern void clear_absolute_proximity_bits(setup *ss)
{
for (int i=0; i<MAX_PEOPLE; i++) {
ss->people[i].id2 &= ~ID2_ABSOLUTE_PROXIMITY_BITS;
ss->people[i].id3 &= ~ID3_ABSOLUTE_PROXIMITY_BITS;
}
}
extern void clear_absolute_proximity_and_facing_bits(setup *ss)
{
for (int i=0; i<MAX_PEOPLE; i++) {
ss->people[i].id2 &= ~(ID2_ABSOLUTE_FACING_BITS|ID2_ABSOLUTE_PROXIMITY_BITS);
ss->people[i].id3 &= ~ID3_ABSOLUTE_PROXIMITY_BITS;
}
}
full_expand::thing *full_expand::touch_hash_table1[full_expand::NUM_TOUCH_HASH_BUCKETS];
full_expand::thing *full_expand::touch_hash_table2[full_expand::NUM_TOUCH_HASH_BUCKETS];
full_expand::thing *full_expand::touch_hash_table3[full_expand::NUM_TOUCH_HASH_BUCKETS];
expand::thing *expand::expand_hash_table[expand::NUM_EXPAND_HASH_BUCKETS];
expand::thing *expand::compress_hash_table[expand::NUM_EXPAND_HASH_BUCKETS];
void expand::initialize()
{
thing *tabp;
int i;
for (i=0 ; i<NUM_EXPAND_HASH_BUCKETS ; i++) {
expand_hash_table[i] = (thing *) 0;
compress_hash_table[i] = (thing *) 0;
}
for (tabp = init_table ; tabp->inner_kind != nothing ; tabp++) {
uint32 hash_num = (tabp->inner_kind * 25) & (NUM_EXPAND_HASH_BUCKETS-1);
tabp->next_expand = expand_hash_table[hash_num];
expand_hash_table[hash_num] = tabp;
hash_num = (tabp->outer_kind * 25) & (NUM_EXPAND_HASH_BUCKETS-1);
tabp->next_compress = compress_hash_table[hash_num];
compress_hash_table[hash_num] = tabp;
}
}
void full_expand::initialize_touch_tables()
{
thing *tabp;
int i;
for (i=0 ; i<NUM_TOUCH_HASH_BUCKETS ; i++) {
touch_hash_table1[i] = (thing *) 0;
touch_hash_table2[i] = (thing *) 0;
touch_hash_table3[i] = (thing *) 0;
}
for (tabp = touch_init_table1 ; tabp->kind != nothing ; tabp++) {
uint32 hash_num = ((tabp->kind + (5*tabp->live)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
tabp->next = touch_hash_table1[hash_num];
touch_hash_table1[hash_num] = tabp;
}
for (tabp = touch_init_table2 ; tabp->kind != nothing ; tabp++) {
uint32 hash_num = ((tabp->kind + (5*tabp->live)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
tabp->next = touch_hash_table2[hash_num];
touch_hash_table2[hash_num] = tabp;
}
for (tabp = touch_init_table3 ; tabp->kind != nothing ; tabp++) {
uint32 hash_num = ((tabp->kind + (5*tabp->live)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
tabp->next = touch_hash_table3[hash_num];
touch_hash_table3[hash_num] = tabp;
}
}
full_expand::thing *full_expand::search_table_1(setup_kind kind,
uint32 livemask,
uint32 directions)
{
uint32 hash_num = ((kind + (5*livemask)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
for (thing *tptr = touch_hash_table1[hash_num] ; tptr ; tptr = tptr->next) {
if (tptr->kind == kind &&
tptr->live == livemask &&
((tptr->dir ^ directions) & tptr->dirmask) == 0) return tptr;
}
return (thing *) 0;
}
full_expand::thing *full_expand::search_table_2(setup_kind kind,
uint32 livemask,
uint32 directions)
{
uint32 hash_num = ((kind + (5*livemask)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
for (thing *tptr = touch_hash_table2[hash_num] ; tptr ; tptr = tptr->next) {
if (tptr->kind == kind &&
tptr->live == livemask &&
((tptr->dir ^ directions) & tptr->dirmask) == 0) return tptr;
}
return (thing *) 0;
}
full_expand::thing *full_expand::search_table_3(setup_kind kind,
uint32 livemask,
uint32 directions,
uint32 touchflags)
{
uint32 hash_num = ((kind + (5*livemask)) * 25) & (NUM_TOUCH_HASH_BUCKETS-1);
for (thing *tptr = touch_hash_table3[hash_num] ; tptr ; tptr = tptr->next) {
// If it has the evil "32" bit on, don't allow it except for special
// fan-the-top calls, indicated by CFLAG1_STEP_TO_WAVE.
// Well, not that way any longer.
if (tptr->kind == kind &&
tptr->live == livemask &&
((tptr->dir ^ directions) & tptr->dirmask) == 0 &&
(!(tptr->forbidden_elongation & 32) || touchflags == CFLAG1_STEP_TO_WAVE))
return tptr;
}
return (thing *) 0;
}
// This gets a ===> BIG-ENDIAN <=== mask of people's facing directions.
// Each person occupies 2 bits in the resultant masks. The "livemask"
// bits are both on if the person is live.
extern void big_endian_get_directions(
const setup *ss,
uint32 & directions,
uint32 & livemask,
uint32 * high_directions_p /* = 0 */, // These are optional, for setups larger than 16 people.
uint32 * high_livemask_p /* = 0 */)
{
directions = 0;
livemask = 0;
uint32 high_directions = 0;
uint32 high_livemask = 0;
for (int i=0; i<=attr::slimit(ss); i++) {
high_livemask <<= 2;
high_directions <<= 2;
high_livemask |= (livemask >> 30) & 3;
high_directions |= (directions >> 30) & 3;
directions <<= 2;
livemask <<= 2;
uint32 p = ss->people[i].id1;
if (p) { livemask |= 3 ; directions |= p & 3; }
}
if (high_livemask_p) *high_livemask_p = high_livemask;
if (high_directions_p) *high_directions_p = high_directions;
}
extern void touch_or_rear_back(
setup *scopy,
bool did_mirror,