-
Notifications
You must be signed in to change notification settings - Fork 2
/
option.c
4152 lines (4094 loc) · 152 KB
/
option.c
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
#include <ctype.h>
#include <signal.h>
#include "chess.h"
#include "data.h"
#if defined(UNIX)
# include <unistd.h>
# include <signal.h>
#endif
#include "epdglue.h"
/* last modified 01/16/15 */
/*
*******************************************************************************
* *
* Option() is used to handle user input necessary to control/customize the *
* program. It performs all functions excepting chess move input which is *
* handled by main(). *
* *
*******************************************************************************
*/
int Option(TREE * RESTRICT tree) {
int v;
/*
************************************************************
* *
* parse the input. If it looks like a FEN string, don't *
* parse using "/" as a separator, otherwise do. *
* *
************************************************************
*/
if (StrCnt(buffer, '/') >= 7)
nargs = ReadParse(buffer, args, " \t;=");
else
nargs = ReadParse(buffer, args, " \t;=/");
if (!nargs)
return 1;
if (args[0][0] == '#')
return 1;
/*
************************************************************
* *
* EPD implementation interface code. EPD commands can *
* not be handled if the program is actually searching in *
* a real game, and if Crafty is "pondering" this has to *
* be stopped. *
* *
************************************************************
*/
#if defined(EPD)
if (initialized) {
if (EGCommandCheck(buffer)) {
if (thinking || pondering)
return 2;
else {
EGCommand(buffer);
return 1;
}
}
}
#endif
/*
************************************************************
* *
* "!" character is a 'shell escape' that passes the rest *
* of the command to a shell for execution. Note that it *
* is ignored if in xboard mode because one could use your *
* zippy2password to execute commands on your local *
* machine, probably something that is not wanted. *
* *
************************************************************
*/
if (buffer[0] == '!') {
if (!xboard) {
v = system(strchr(buffer, '!') + 1);
if (v != 0)
perror("Option() system() error: ");
}
}
/*
************************************************************
* *
* "." ignores "." if it happens to get to this point, if *
* xboard is running. *
* *
************************************************************
*/
else if (OptionMatch(".", *args)) {
if (xboard) {
printf("stat01: 0 0 0 0 0\n");
fflush(stdout);
return 1;
} else
return 0;
}
/*
************************************************************
* *
* "accepted" handles the new xboard protocol version 2 *
* accepted command. *
* *
************************************************************
*/
else if (OptionMatch("accepted", *args)) {
}
/*
************************************************************
* *
* "adaptive" sets the new adaptive hash algorithm *
* parameters. It requires five parameters. The first is *
* an estimated NPS, the second is the minimum hash size, *
* and the third is the maximum hash size. The adaptive *
* algorithm will look at the time control, and try to *
* adjust the hash sizes to an optimal value without *
* dropping below the minimum or exceeding the maximum *
* memory size given. The min/max sizes can be given *
* using the same syntax as the hash= command, ie xxx, *
* xxxK or xxxM will all work. The fourth and fifth *
* parameters are used to limit hashp in the same way. *
* *
************************************************************
*/
else if (OptionMatch("adaptive", *args)) {
if (nargs != 6) {
printf("usage: adaptive NPS hmin hmax pmin pmax\n");
return 1;
}
if (nargs > 1) {
adaptive_hash = atoiKMB(args[1]);
adaptive_hash_min = atoiKMB(args[2]);
adaptive_hash_max = atoiKMB(args[3]);
adaptive_hashp_min = atoiKMB(args[4]);
adaptive_hashp_max = atoiKMB(args[5]);
}
Print(32, "adaptive estimated NPS = %s\n", DisplayKMB(adaptive_hash, 1));
Print(32, "adaptive minimum hsize = %s\n", DisplayKMB(adaptive_hash_min,
1));
Print(32, "adaptive maximum hsize = %s\n", DisplayKMB(adaptive_hash_max,
1));
Print(32, "adaptive minimum psize = %s\n", DisplayKMB(adaptive_hashp_min,
1));
Print(32, "adaptive maximum psize = %s\n", DisplayKMB(adaptive_hashp_max,
1));
}
/*
************************************************************
* *
* "alarm" command turns audible move warning on/off. *
* *
************************************************************
*/
else if (OptionMatch("alarm", *args)) {
if (!strcmp(args[1], "on"))
audible_alarm = 0x07;
else if (!strcmp(args[1], "off"))
audible_alarm = 0x00;
else
printf("usage: alarm on|off\n");
}
/*
************************************************************
* *
* "analyze" puts Crafty in analyze mode, where it reads *
* moves in and between moves, computes as though it is *
* trying to find the best move to make. When another *
* move is entered, it switches sides and continues. It *
* will never make a move on its own, rather, it will *
* continue to analyze until an "exit" command is given. *
* *
************************************************************
*/
else if (OptionMatch("analyze", *args)) {
if (thinking || pondering)
return 2;
Analyze();
}
/*
************************************************************
* *
* "annotate" command is used to read a series of moves *
* and analyze the resulting game, producing comments as *
* requested by the user. This also handles the annotateh *
* (html) and annotatet (LaTex) output forms of the *
* command. *
* *
************************************************************
*/
else if (OptionMatch("annotate", *args) || OptionMatch("annotateh", *args)
|| OptionMatch("annotatet", *args)) {
if (thinking || pondering)
return 2;
Annotate();
}
/*
************************************************************
* *
* "autotune" command is used to automatically tune the *
* SMP search parameters that affect search efficiency. *
* *
************************************************************
*/
else if (OptionMatch("autotune", *args)) {
if (thinking || pondering)
return 2;
AutoTune(nargs, args);
}
/*
************************************************************
* *
* "batch" command disables asynchronous I/O so that a *
* stream of commands can be put into a file and they are *
* not executed instantly. *
* *
************************************************************
*/
else if (OptionMatch("batch", *args)) {
if (!strcmp(args[1], "on"))
batch_mode = 1;
else if (!strcmp(args[1], "off"))
batch_mode = 0;
else
printf("usage: batch on|off\n");
}
/*
************************************************************
* *
* "beep" command is ignored. [xboard compatibility] *
* *
************************************************************
*/
else if (OptionMatch("beep", *args)) {
return xboard;
}
/*
************************************************************
* *
* "bench" runs internal performance benchmark. An *
* optional second argument can increase or decrease the *
* time it takes. "bench 1" increases the default depth *
* by one ply, and "bench -1" reduces the depth to speed *
* it up. *
* *
************************************************************
*/
else if (OptionMatch("bench", *args)) {
int mod = 0, time;
if (nargs > 1)
mod = atoi(args[1]);
time = Bench(mod, 0);
Print(32, "time used = %s\n", DisplayTime(time));
}
/*
***************************************************************
* *
* "pgo" runs an internal performance benchmark used for PGO. *
* An optional second argument can increase or decrease *
* the time it takes. "pgo 1" increases the default *
* by one ply, and "pgo -1" reduces the depth to speed *
* it up. *
* *
************************************************************
*/
else if (OptionMatch("pgo", *args)) {
int mod = 0, time;
if (nargs > 1)
mod = atoi(args[1]);
time = Bench_PGO(mod, 0);
Print(32, "time used = %s\n", DisplayTime(time));
}
/*
************************************************************
* *
* "bk" book command from xboard sends the suggested book *
* moves. *
* *
************************************************************
*/
else if (OptionMatch("bk", *args)) {
printf("\t%s\n\n", book_hint);
fflush(stdout);
return xboard;
}
/*
************************************************************
* *
* "black" command sets black to move (Flip(wtm)). *
* *
************************************************************
*/
else if (OptionMatch("white", *args)) {
if (thinking || pondering)
return 2;
game_wtm = 1;
ponder_move = 0;
last_pv.pathd = 0;
last_pv.pathl = 0;
if (!game_wtm)
Pass();
force = 0;
} else if (OptionMatch("black", *args)) {
if (thinking || pondering)
return 2;
game_wtm = 0;
ponder_move = 0;
last_pv.pathd = 0;
last_pv.pathl = 0;
if (game_wtm)
Pass();
force = 0;
}
/*
************************************************************
* *
* "bogus" command is ignored. [xboard compatibility] *
* *
************************************************************
*/
else if (OptionMatch("bogus", *args)) {
return xboard;
}
/*
************************************************************
* *
* "book" command updates/creates the opening book file. *
* *
************************************************************
*/
else if (OptionMatch("book", *args)) {
nargs = ReadParse(buffer, args, " \t;");
Bookup(tree, nargs, args);
} else if (!strcmp("create", *(args + 1))) {
nargs = ReadParse(buffer, args, " \t;");
Bookup(tree, nargs, args);
}
/*
************************************************************
* *
* "bookw" command updates the book selection weights. *
* *
************************************************************
*/
else if (OptionMatch("bookw", *args)) {
if (nargs > 1) {
if (OptionMatch("frequency", args[1]))
book_weight_freq = atof(args[2]);
else if (OptionMatch("evaluation", args[1]))
book_weight_eval = atof(args[2]);
else if (OptionMatch("learning", args[1]))
book_weight_learn = atof(args[2]);
} else {
Print(32, "frequency (freq)..............%4.2f\n", book_weight_freq);
Print(32, "static evaluation (eval)......%4.2f\n", book_weight_eval);
Print(32, "learning (learn)..............%4.2f\n", book_weight_learn);
}
}
/*
************************************************************
* *
* "cache" is used to set the EGTB cache size. As always *
* bigger is better. The default is 1mb. Sizes can be *
* specified in bytes, Kbytes or Mbytes as with the hash *
* commands. *
* *
************************************************************
*/
#if !defined(NOEGTB)
else if (OptionMatch("cache", *args)) {
EGTB_cache_size = atoiKMB(args[1]);
if (EGTB_cache)
free(EGTB_cache);
EGTB_cache = malloc(EGTB_cache_size);
if (!EGTB_cache) {
Print(2095,
"ERROR: unable to malloc specified cache size, using default\n");
EGTB_cache = malloc(4096 * 4096);
}
Print(32, "EGTB cache memory = %s bytes.\n", DisplayKMB(EGTB_cache_size,
1));
FTbSetCacheSize(EGTB_cache, EGTB_cache_size);
}
#endif
/*
************************************************************
* *
* "clock" command displays chess clock. *
* *
************************************************************
*/
else if (OptionMatch("clock", *args)) {
int side;
for (side = white; side >= black; side--) {
Print(32, "time remaining (%s): %s", (side) ? "white" : "black",
DisplayHHMMSS(tc_time_remaining[side]));
if (tc_sudden_death != 1)
Print(32, " (%d more moves)", tc_moves_remaining[side]);
Print(32, "\n");
}
Print(32, "\n");
if (tc_sudden_death == 1)
Print(32, "Sudden-death time control in effect\n");
}
/*
************************************************************
* *
* "computer" lets Crafty know it is playing a computer. *
* *
************************************************************
*/
else if (OptionMatch("computer", *args)) {
Print(32, "playing a computer!\n");
accept_draws = 1;
if (resign)
resign = 10;
resign_count = 4;
usage_level = 0;
books_file = (computer_bs_file) ? computer_bs_file : normal_bs_file;
}
/*
************************************************************
* *
* "display" command displays the chess board. *
* *
* "display" command sets specific display options which *
* control how "chatty" the program is. In the variable *
* display_options, the following bits are set/cleared *
* based on the option chosen. *
* *
* 1 -> display move/time/results/etc. *
* 2 -> display PV. *
* 4 -> display fail high / fail low moves *
* 8 -> display search statistics. *
* 16 -> display root moves as they are searched. *
* 32 -> display general informational messages. *
* 64 -> display ply-1 move list / flags after each *
* iteration. *
* 128 -> display root moves and scores before search *
* begins. *
* 2048 -> error messages (can not be disabled). *
* *
************************************************************
*/
else if (OptionMatch("display", *args)) {
int i, set, old_display_options = display_options;
char *doptions[8] = { "moveinfo", "pv", "fail", "stats", "moves", "info",
"ply1", "movelist"
};
char *descriptions[8] = { "display move time/results/etc",
"principal variation", "fail highs/lows", "search statistics",
"root moves as they are searched", "general information",
"ply1 move list after each iteration",
"root move list and scores prior to search"
};
if (nargs > 1) {
if (!strcmp(args[1], "all"))
old_display_options = ~display_options;
for (i = 0; i < 8; i++) {
if (strstr(args[1], doptions[i])) {
if (strstr(args[1], "no"))
set = 0;
else
set = 1;
display_options &= ~(1 << i);
display_options |= set << i;
break;
}
}
for (i = 0; i < 8; i++) {
if ((old_display_options & (1 << i)) != (display_options & (1 << i))) {
Print(32, "display ");
if (!(display_options & (1 << i)))
Print(32, "no");
Print(32, "%s (%s)\n", doptions[i], descriptions[i]);
}
}
} else
DisplayChessBoard(stdout, display);
}
/*
************************************************************
* *
* "debug" handles the new debug command that is often *
* modified to test some modified code function. *
* *
************************************************************
*/
else if (OptionMatch("debug", *args)) {
Print(32, "ERROR: no debug code included\n");
}
/*
************************************************************
* *
* "depth" command sets a specific search depth to *
* control the tree search depth. [xboard compatibility]. *
* *
************************************************************
*/
else if (OptionMatch("depth", *args)) {
if (nargs < 2) {
printf("usage: depth <n>\n");
return 1;
}
search_depth = atoi(args[1]);
Print(32, "search depth set to %d.\n", search_depth);
}
/*
************************************************************
* *
* "draw" is used to offer Crafty a draw, or to control *
* whether Crafty will offer and/or accept draw offers. *
* *
************************************************************
*/
else if (OptionMatch("draw", *args)) {
if (nargs == 1) {
draw_offer_pending = 1;
if (draw_offered) {
Print(4095, "1/2-1/2 {Draw agreed}\n");
strcpy(pgn_result, "1/2-1/2");
}
} else {
if (!strcmp(args[1], "accept")) {
accept_draws = 1;
Print(32, "accept draw offers\n");
} else if (!strcmp(args[1], "decline")) {
accept_draws = 0;
Print(32, "decline draw offers\n");
} else if (!strcmp(args[1], "dynamic")) {
if (nargs > 2)
dynamic_draw_score = atoi(args[2]);
Print(32, "dynamic draw scores %s\n",
(dynamic_draw_score) ? "enabled" : "disabled");
} else if (!strcmp(args[1], "offer")) {
offer_draws = 1;
Print(32, "offer draws\n");
} else if (!strcmp(args[1], "nooffer")) {
offer_draws = 0;
Print(32, "do not offer draws\n");
} else
Print(32, "usage: draw accept|decline|offer|nooffer\n");
}
}
/*
************************************************************
* *
* "easy" command disables thinking on opponent's time. *
* *
************************************************************
*/
else if (OptionMatch("easy", *args)) {
if (thinking || pondering)
return 2;
ponder = 0;
Print(32, "pondering disabled.\n");
}
/*
************************************************************
* *
* "echo" command displays messages from command file. *
* *
************************************************************
*/
else if (OptionMatch("echo", *args) || OptionMatch("title", *args)) {
}
/*
************************************************************
* *
* "edit" command modifies the board position. *
* *
************************************************************
*/
else if (OptionMatch("edit", *args)) {
if (thinking || pondering)
return 2;
Edit();
move_number = 1; /* discard history */
if (!game_wtm) {
game_wtm = 1;
Pass();
}
ponder_move = 0;
last_pv.pathd = 0;
last_pv.pathl = 0;
strcpy(buffer, "savepos *");
Option(tree);
}
/*
************************************************************
* *
* "egtb" command enables/disables tablebases and sets *
* the number of pieces available for probing. *
* *
************************************************************
*/
#if !defined(NOEGTB)
else if (OptionMatch("egtb", *args)) {
if (!EGTB_setup) {
Print(32, "EGTB access enabled\n");
Print(32, "using tbpath=%s\n", tb_path);
EGTBlimit = IInitializeTb(tb_path);
Print(32, "%d piece tablebase files found\n", EGTBlimit);
if (0 != cbEGTBCompBytes)
Print(32,
"%dkb of RAM used for TB indices and decompression tables\n",
(cbEGTBCompBytes + 1023) / 1024);
if (EGTBlimit) {
if (!EGTB_cache)
EGTB_cache = malloc(EGTB_cache_size);
if (!EGTB_cache) {
Print(32, "ERROR EGTB cache malloc failed\n");
EGTB_cache = malloc(4096 * 4096);
} else
FTbSetCacheSize(EGTB_cache, EGTB_cache_size);
EGTB_setup = 1;
}
} else {
if (nargs == 1)
EGTBPV(tree, game_wtm);
else if (nargs == 2)
EGTBlimit = Min(atoi(args[1]), 5);
}
}
/*
************************************************************
* *
* "egtbd" command sets the probe depth limit. If the *
* remaining depth is < this limit, probes are not done to *
* avoid slowing the search unnecessarily. *
* *
************************************************************
*/
else if (OptionMatch("egtbd", *args)) {
if (nargs > 1)
EGTB_depth = atoi(args[1]);
Print(32, "EGTB probe depth set to %d\n", EGTB_depth);
}
#endif
/*
************************************************************
* *
* "end" (or "quit") command terminates the program. *
* *
************************************************************
*/
else if (OptionMatch("end", *args) || OptionMatch("quit", *args)) {
abort_search = 1;
quit = 1;
last_search_value =
(crafty_is_white) ? last_search_value : -last_search_value;
if (moves_out_of_book)
LearnBook();
if (thinking || pondering)
return 1;
CraftyExit(0);
}
/*
************************************************************
* *
* "evtest" command runs a test suite of problems and *
* prints evaluations only. *
* *
************************************************************
*/
else if (OptionMatch("evtest", *args)) {
if (thinking || pondering)
return 2;
if (nargs < 2) {
printf("usage: evtest <filename>\n");
return 1;
}
EVTest(args[1]);
ponder_move = 0;
last_pv.pathd = 0;
last_pv.pathl = 0;
}
/*
************************************************************
* *
* "exit" command resets input device to STDIN. *
* *
************************************************************
*/
else if (OptionMatch("exit", *args)) {
if (analyze_mode)
return 0;
if (input_stream != stdin)
fclose(input_stream);
input_stream = stdin;
ReadClear();
Print(32, "\n");
}
/*
************************************************************
* *
* "flag" command controls whether Crafty will call the *
* flag in xboard/winboard games (to end the game.) *
* *
************************************************************
*/
else if (OptionMatch("flag", *args)) {
if (nargs < 2) {
printf("usage: flag on|off\n");
return 1;
}
if (!strcmp(args[1], "on"))
call_flag = 1;
else if (!strcmp(args[1], "off"))
call_flag = 0;
if (call_flag)
Print(32, "end game on time forfeits\n");
else
Print(32, "ignore time forfeits\n");
}
/*
************************************************************
* *
* "flip" command flips the board, interchanging each *
* rank with the corresponding rank on the other half of *
* the board, and also reverses the color of all pieces. *
* *
************************************************************
*/
else if (OptionMatch("flip", *args)) {
int file, rank, piece, temp;
if (thinking || pondering)
return 2;
for (rank = 0; rank < 4; rank++) {
for (file = 0; file < 8; file++) {
piece = -PcOnSq((rank << 3) + file);
PcOnSq((rank << 3) + file) = -PcOnSq(((7 - rank) << 3) + file);
PcOnSq(((7 - rank) << 3) + file) = piece;
}
}
game_wtm = Flip(game_wtm);
temp = Castle(0, white);
Castle(0, white) = Castle(0, black);
Castle(0, black) = temp;
SetChessBitBoards(tree);
#if defined(DEBUG)
ValidatePosition(tree, 0, game_wtm, "Option().flip");
#endif
}
/*
************************************************************
* *
* "flop" command flops the board, interchanging each *
* file with the corresponding file on the other half of *
* the board. *
* *
************************************************************
*/
else if (OptionMatch("flop", *args)) {
int file, rank, piece;
if (thinking || pondering)
return 2;
for (rank = 0; rank < 8; rank++) {
for (file = 0; file < 4; file++) {
piece = PcOnSq((rank << 3) + file);
PcOnSq((rank << 3) + file) = PcOnSq((rank << 3) + 7 - file);
PcOnSq((rank << 3) + 7 - file) = piece;
}
}
SetChessBitBoards(tree);
#if defined(DEBUG)
ValidatePosition(tree, 0, game_wtm, "Option().flop");
#endif
}
/*
************************************************************
* *
* "force" command forces the program to make a specific *
* move instead of its last chosen move. *
* *
************************************************************
*/
else if (OptionMatch("force", *args)) {
int move, movenum, save_move_number;
char text[16];
if (thinking || pondering)
return 3;
if (xboard) {
force = 1;
return 3;
}
if (nargs < 2) {
printf("usage: force <move>\n");
return 1;
}
ponder_move = 0;
presult = 0;
last_pv.pathd = 0;
last_pv.pathl = 0;
save_move_number = move_number;
movenum = move_number;
if (game_wtm)
movenum--;
strcpy(text, args[1]);
sprintf(buffer, "reset %d", movenum);
game_wtm = Flip(game_wtm);
Option(tree);
move = InputMove(tree, 0, game_wtm, 0, 0, text);
if (move) {
if (input_stream != stdin)
printf("%s\n", OutputMove(tree, 0, game_wtm, move));
if (history_file) {
fseek(history_file, ((movenum - 1) * 2 + 1 - game_wtm) * 10,
SEEK_SET);
fprintf(history_file, "%9s\n", OutputMove(tree, 0, game_wtm, move));
}
MakeMoveRoot(tree, game_wtm, move);
last_pv.pathd = 0;
last_pv.pathl = 0;
} else if (input_stream == stdin)
printf("illegal move.\n");
game_wtm = Flip(game_wtm);
move_number = save_move_number;
strcpy(ponder_text, "none");
}
/*
************************************************************
* *
* "go" command does nothing, except force main() to start *
* a search. ("move" is an alias for go). *
* *
************************************************************
*/
else if (OptionMatch("go", *args) || OptionMatch("move", *args)) {
int t;
char temp[128];
if (thinking || pondering)
return 2;
if (game_wtm) {
if (strncmp(pgn_white, "Crafty", 6)) {
strcpy(temp, pgn_white);
strcpy(pgn_white, pgn_black);
strcpy(pgn_black, temp);
}
} else {
if (strncmp(pgn_black, "Crafty", 6)) {
strcpy(temp, pgn_white);
strcpy(pgn_white, pgn_black);
strcpy(pgn_black, temp);
}
}
t = tc_time_remaining[white];
tc_time_remaining[white] = tc_time_remaining[black];
tc_time_remaining[black] = t;
t = tc_moves_remaining[white];
tc_moves_remaining[white] = tc_moves_remaining[black];
tc_moves_remaining[black] = t;
force = 0;
return -1;
}
/*
************************************************************
* *
* "history" command displays game history (moves). *
* *
************************************************************
*/
else if (OptionMatch("history", *args)) {
int i;
char buffer[128];
if (history_file) {
printf(" white black\n");
for (i = 0; i < (move_number - 1) * 2 - game_wtm + 1; i++) {
fseek(history_file, i * 10, SEEK_SET);
v = fscanf(history_file, "%s", buffer);
if (v <= 0)
perror("Option() fscanf error: ");
if (!(i % 2))
printf("%3d", i / 2 + 1);
printf(" %-10s", buffer);
if (i % 2 == 1)
printf("\n");
}
if (Flip(game_wtm))
printf(" ...\n");
}
}
/*
************************************************************
* *
* "hard" command enables thinking on opponent's time. *
* *
************************************************************
*/
else if (OptionMatch("hard", *args)) {
ponder = 1;
Print(32, "pondering enabled.\n");
}
/*
************************************************************
* *
* "hash" command controls the transposition table size. *
* The size can be entered in one of four ways: *
* *
* hash=nnn where nnn is in bytes. *
* hash=nnnK where nnn is in K bytes. *
* hash=nnnM where nnn is in M bytes. *
* hash=nnnG where nnn is in G bytes. *
* *
* the only restriction is that the hash table is computed *
* as a perfect power of 2. Any value that is not a *
* perfect power of 2 is rounded down so that it is, in *
* order to avoid breaking the addressing scheme. *
* *
************************************************************
*/
else if (OptionMatch("hash", *args)) {
size_t old_hash_size = hash_table_size, new_hash_size;
if (thinking || pondering)
return 2;
if (nargs > 1) {
allow_memory = 0;
if (xboard)
Print(4095, "Warning-- xboard 'memory' option disabled\n");
new_hash_size = atoiKMB(args[1]);
if (new_hash_size < 64 * 1024) {
printf("ERROR. Minimum hash table size is 64K bytes.\n");
return 1;
}
hash_table_size = ((1ull) << MSB(new_hash_size)) / 16;
AlignedRemalloc((void *) ((void *) &hash_table), 64,
hash_table_size * sizeof(HASH_ENTRY));
if (!hash_table) {
printf("AlignedRemalloc() failed, not enough memory.\n");
exit(1);
}
hash_mask = (hash_table_size - 1) & ~3;
}
Print(32, "hash table memory = %s bytes",
DisplayKMB(hash_table_size * sizeof(HASH_ENTRY), 1));
Print(32, " (%s entries).\n", DisplayKMB(hash_table_size, 1));
InitializeHashTables(old_hash_size != hash_table_size);
}
/*
************************************************************
* *
* "phash" command controls the path hash table size. The *
* size can be entered in one of four ways: *
* *
* phash=nnn where nnn is in bytes. *
* phash=nnnK where nnn is in K bytes. *
* phash=nnnM where nnn is in M bytes. *
* phash=nnnG where nnn is in G bytes. *
* *
* the only restriction is that the path hash table must *
* have a perfect power of 2 entries. The value entered *
* will be rounded down to meet that requirement. *
* *
************************************************************
*/
else if (OptionMatch("phash", *args)) {
size_t old_hash_size = hash_path_size, new_hash_size;
if (thinking || pondering)
return 2;
if (nargs > 1) {
new_hash_size = atoiKMB(args[1]);
if (new_hash_size < 64 * 1024) {
printf("ERROR. Minimum phash table size is 64K bytes.\n");
return 1;
}
hash_path_size = ((1ull) << MSB(new_hash_size / sizeof(HPATH_ENTRY)));
AlignedRemalloc((void *) ((void *) &hash_path), 64,
sizeof(HPATH_ENTRY) * hash_path_size);
if (!hash_path) {
printf("AlignedRemalloc() failed, not enough memory.\n");
hash_path_size = 0;
hash_path = 0;
}
hash_path_mask = (hash_path_size - 1) & ~15;
}
Print(32, "hash path table memory = %s bytes",
DisplayKMB(hash_path_size * sizeof(HPATH_ENTRY), 1));
Print(32, " (%s entries).\n", DisplayKMB(hash_path_size, 1));
InitializeHashTables(old_hash_size != hash_path_size);
}
/*
************************************************************
* *
* "hashp" command controls the pawn hash table size. *
* *
************************************************************
*/
else if (OptionMatch("hashp", *args)) {
size_t old_hash_size = pawn_hash_table_size, new_hash_size;
if (thinking || pondering)
return 2;
if (nargs > 1) {