/* hmm.... shouldn`t main be moved to the interface routines */ int main (int argc, char **argv) { char *xwin = 0; char *Lang = NULL; gsrand (starttime = ((unsigned int) time ((long *) 0))); /* init urand */ #ifdef ttblsz ttblsize = ttblsz; rehash = -1; #endif /* ttblsz */ if (argc > 2) { if (argv[1][0] == '-' && argv[1][1] == 'L') { Lang = argv[2]; argv += 2; argc -= 2; } } InitConst (Lang); ColorStr[0] = CP[118]; ColorStr[1] = CP[119]; while (argc > 1 && ((argv[1][0] == '-') || (argv[1][0] == '+'))) { switch (argv[1][1]) { case 'a': ahead = ((argv[1][0] == '-') ? false : true); break; case 'b': argv++; argc--; if (argc > 1) { bookfile = argv[1]; #ifdef BINBOOK binbookfile = NULL; #endif } break; #ifdef BINBOOK case 'B': argv++; argc--; if (argc > 1) binbookfile = argv[1]; break; #endif case 'h': hash = ((argv[1][0] == '-') ? false : true); break; case 's': argc--; argv++; if (argc > 1) strcpy (savefile, argv[1]); break; case 'l': argc--; argv++; if (argc > 1) strcpy (listfile, argv[1]); break; #ifndef GDBM case 'S': argc--; argv++; if(argc > 1)booksize = atoi(argv[1]); break; #endif case 'P': argc--; argv++; if(argc > 1)bookmaxply = atoi(argv[1]); break; #if ttblsz case 'r': if (argc > 2) rehash = atoi (argv[2]); argc--; argv++; if (rehash > MAXrehash) rehash = MAXrehash; break; case 'T': if (argc > 2) ttblsize = atoi (argv[2]); argc--; argv++; if (ttblsize > 0 && ttblsize < 24) ttblsize = (1 << ttblsize); else ttblsize = ttblsz; break; #ifdef HASHFILE case 't': /* create or test persistent transposition * table */ hashfile = fopen (HASHFILE, RWA_ACC); if (hashfile) { fseek (hashfile, 0L, SEEK_END); filesz = (ftell (hashfile) / sizeof (struct fileentry)) - 1; } if (hashfile != NULL) { long i, j; int nr[MAXDEPTH]; struct fileentry n; printf (CP[49]); for (i = 0; i < MAXDEPTH; i++) nr[i] = 0; fseek (hashfile, 0L, SEEK_END); i = ftell (hashfile) / sizeof (struct fileentry); fseek (hashfile, 0L, SEEK_SET); for (j = 0; j < i + 1; j++) { fread (&n, sizeof (struct fileentry), 1, hashfile); if(n.depth >MAXDEPTH) {printf("ERROR\n");exit(1);} if (n.depth) { nr[n.depth]++; nr[0]++; } } printf (CP[109], nr[0], i); for (j = 1; j < MAXDEPTH; j++) printf ("%d ", nr[j]); printf ("\n"); } return 0; case 'c': /* create or test persistent transposition * table */ if (argc > 2) filesz = atoi (argv[2]); if (filesz > 0 && filesz < 24) filesz = (1 << filesz) - 1 + MAXrehash; else filesz = Deffilesz + MAXrehash; if ((hashfile = fopen (HASHFILE, RWA_ACC)) == NULL) hashfile = fopen (HASHFILE, WA_ACC); if (hashfile != NULL) { long j; struct fileentry n; printf (CP[66]); n.f = n.t = 0; n.flags = 0; n.depth = 0; n.sh = n.sl = 0; for (j = 0; j < filesz + 1; j++) fwrite (&n, sizeof (struct fileentry), 1, hashfile); fclose (hashfile); } else printf (CP[50], HASHFILE); return (0); #endif /* HASHFILE */ #endif /* ttblsz */ case 'x': xwin = &argv[1][2]; break; case 'v': fprintf (stderr, CP[102], version, patchlevel); exit (1); default: fprintf (stderr, CP[113]); exit (1); } argv++; argc--; } XC = 0; MaxResponseTime = 0; #if defined CHESSTOOL || defined XBOARD signal (SIGTERM, TerminateChess); TCflag = true; TCmoves = 40; TCminutes = 5; TCseconds = 0; TCadd = 0; OperatorTime = 0; #else TCflag = false; OperatorTime = 0; #endif if (argc == 2) { char *p; MaxResponseTime = 100L * strtol (argv[1], &p, 10); if (*p == ':') MaxResponseTime = 60L * MaxResponseTime + 100L * strtol (++p, (char **) NULL, 10); TCflag = false; TCmoves = 0; TCminutes = 0; TCseconds = 0; } if (argc >= 3) { char *p; if (argc > 9) { printf ("%s\n", CP[220]); exit (1); } TCmoves = atoi (argv[1]); TCminutes = (short)strtol (argv[2], &p, 10); if (*p == ':') TCseconds = (short)strtol (p + 1, (char **) NULL, 10); else TCseconds = 0; TCflag = true; argc -= 3; argv += 3; while (argc > 1) { XCmoves[XC] = atoi (argv[0]); XCminutes[XC] = (short)strtol (argv[1], &p, 10); if (*p == ':') XCseconds[XC] = (short)strtol (p + 1, (char **) NULL, 10); else XCseconds[XC] = 0; if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC])) XC++; else { printf (CP[220]); exit (1); } argc -= 2; argv += 2; } if (argc) { printf ("%s\n", CP[220]); exit (1); } } Initialize (); Initialize_dist (); Initialize_moves (); NewGame (); flag.easy = ahead; flag.hash = hash; if (xwin) xwndw = atoi (xwin); hashfile = NULL; #if ttblsz #ifdef HASHFILE hashfile = fopen (HASHFILE, RWA_ACC); if (hashfile) { fseek (hashfile, 0L, SEEK_END); filesz = ftell (hashfile) / sizeof (struct fileentry) - 1 - MAXrehash; hashmask = filesz>>1; hashbase = hashmask+1; } #if !defined CHESSTOOL && !defined XBOARD else
void NewGame(void) { short l, c, p, max_opening_sequence; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; #endif compptr = oppptr = 0; stage = 0; stage2 = -1; /* the game is not yet started */ flag.illegal = flag.mate = flag.post = flag.quit = flag.reverse = flag.bothsides = flag.onemove = flag.force = false; flag.material = flag.coords = flag.hash = flag.easy = flag.beep = flag.rcptr = true; flag.stars = flag.shade = flag.back = flag.musttimeout = false; flag.gamein = false; flag.rv = true; mycnt1 = mycnt2 = 0; GenCnt = NodeCnt = et0 = dither = XCmore = 0; znodes = ZNODES; WAwindow = WAWNDW; WBwindow = WBWNDW; BAwindow = BAWNDW; BBwindow = BBWNDW; xwndw = BXWNDW; if (!MaxSearchDepth) MaxSearchDepth = MAXDEPTH - 1; contempt = 0; GameCnt = 0; Game50 = 1; CptrFlag[0] = TesujiFlag[0] = false; hint = OPENING_HINT; ZeroRPT(); GameType[0] = GameType[1] = UNKNOWN; Pscore[0] = Tscore[0] = (SCORE_LIMIT + 3000); opponent = player = black; computer = white; for (l = 0; l < TREE; l++) Tree[l].f = Tree[l].t = 0; gsrand((unsigned int) 1); if (!InitFlag) { for (c = black; c <= white; c++) { for (p = pawn; p <= king; p++) { for (l = 0; l < NO_SQUARES; l++) { (*hashcode)[c][p][l].key = (((unsigned long) urand())); (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 16); (*hashcode)[c][p][l].bd = (((unsigned long) urand())); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 16); #if SIZEOF_LONG == 8 /* 64-bit long i.e. 8 bytes */ (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 32); (*hashcode)[c][p][l].key += (((unsigned long) urand()) << 48); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 32); (*hashcode)[c][p][l].bd += (((unsigned long) urand()) << 48); #endif } } } for (c = black; c <= white; c++) { for (p = pawn; p <= king; p++) { for (l = 0; l < MAX_CAPTURED; l++) { (*drop_hashcode)[c][p][l].key = (((unsigned long) urand())); (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 16); (*drop_hashcode)[c][p][l].bd = (((unsigned long) urand())); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 16); #if SIZEOF_LONG == 8 /* 64-bit long i.e. 8 bytes */ (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 32); (*drop_hashcode)[c][p][l].key += (((unsigned long) urand()) << 48); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 32); (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand()) << 48); #endif } } } } for (l = 0; l < NO_SQUARES; l++) { board[l] = Stboard[l]; color[l] = Stcolor[l]; Mvboard[l] = 0; } ClearCaptured(); ClearScreen(); InitializeStats(); #ifdef HAVE_GETTIMEOFDAY gettimeofday(&tv, NULL); time0 = tv.tv_sec*100 + tv.tv_usec/10000; #else time0 = time((long *) 0); #endif /* resetting reference time */ ElapsedTime(COMPUTE_AND_INIT_MODE); flag.regularstart = true; Book = BOOKFAIL; if (!InitFlag) { char sx[256]; strcpy(sx, CP[169]); if (TCflag) SetTimeControl(); else if (MaxResponseTime == 0) SelectLevel(sx); UpdateDisplay(0, 0, 1, 0); GetOpenings(); GetOpeningPatterns(&max_opening_sequence); InitFlag = true; } #if ttblsz if (TTadd) { ZeroTTable(); TTadd = 0; } #endif /* ttblsz */ hashbd = hashkey = 0; return; }