File: rcfile.c

package info (click to toggle)
sjeng 11.2-8
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, squeeze, stretch, wheezy
  • size: 952 kB
  • ctags: 710
  • sloc: ansic: 13,313; sh: 324; makefile: 83
file content (190 lines) | stat: -rw-r--r-- 5,113 bytes parent folder | download
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
/*
    Sjeng - a chess variants playing program
    Copyright (C) 2000 Gian-Carlo Pascutto

    This program 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.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                                                          
    File: rcfile.c
    Purpose: Read in config file, allocate hash/caches                  

*/

#include "sjeng.h"
#include "protos.h"
#include "extvars.h"
#include "config.h"

FILE *rcfile;
char line[STR_BUFF];

int TTSize;
int ECacheSize;
int PBSize;

int cfg_booklearn;
int cfg_razordrop;
int cfg_cutdrop;
int cfg_ksafety[15][9];
int cfg_tropism[5][7];
int havercfile;
int cfg_futprune;
int cfg_devscale;
int cfg_onerep;
int cfg_recap;
int cfg_smarteval;
int cfg_attackeval;
float cfg_scalefac;

void read_rcfile (void) 
{
  int i;
  unsigned int setc;
  
  if ((rcfile = fopen ("sjeng.rc", "r")) == NULL)
    {
      printf("No configuration file!\n");

      TTSize = 300000;
      ECacheSize = 200000;
      PBSize = 200000;
      EGTBCacheSize = 0;
      strcpy(EGTBDir, "TB");
      
      cfg_devscale = 1;
      cfg_scalefac = 1.0;
      cfg_razordrop = 1;
      cfg_cutdrop = 0;
      cfg_futprune = 1;
      cfg_smarteval = 1;
      cfg_attackeval = 0;

      havercfile = 0;

      setc =   havercfile 
	    + (cfg_devscale << 1) 
	    + (((cfg_scalefac == 1.0) ? 1 : 0) << 2)
	    + (cfg_razordrop << 3)
	    + (cfg_cutdrop << 4)
	    + (cfg_futprune << 5)
	    + (cfg_smarteval << 6)
	    + (cfg_attackeval << 7);
	    
      
      sprintf(setcode, "%u", setc);
      
      initialize_eval();
      alloc_hash();
      alloc_ecache();
      
      return;
    }

  havercfile = 1;
  
  /* read in values, possibly seperated by # commented lines */
  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &TTSize);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &ECacheSize);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &PBSize);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%f", &cfg_scalefac); 

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_devscale); 

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_razordrop);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_cutdrop);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_booklearn);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_futprune);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_onerep);
    
  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_recap);
  
  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_smarteval);
  
  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  sscanf(line, "%d", &cfg_attackeval);

  fgets(line, STR_BUFF, rcfile);
  while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
  
  for(i = 0; i < 5; i++)
  {
      sscanf(line, "%d %d %d %d %d %d %d", 
	  &cfg_tropism[i][0], &cfg_tropism[i][1], &cfg_tropism[i][2],&cfg_tropism[i][3],
	  &cfg_tropism[i][4], &cfg_tropism[i][5], &cfg_tropism[i][6]);
      
          do { fgets(line, STR_BUFF, rcfile);} while (line[0] == '#');
  }
  

  for(i = 0; i < 15; i++)
  {
      sscanf(line, "%d %d %d %d %d %d %d %d %d",
	  &cfg_ksafety[i][0], &cfg_ksafety[i][1],&cfg_ksafety[i][2],&cfg_ksafety[i][3],
	  &cfg_ksafety[i][4], &cfg_ksafety[i][5],&cfg_ksafety[i][6],&cfg_ksafety[i][7],
	  &cfg_ksafety[i][8]);
      
          do {fgets(line, STR_BUFF, rcfile);} while ((line[0] == '#') && !feof(rcfile));
  }

  setc =   havercfile 
            + (cfg_devscale << 1) 
	    + (((cfg_scalefac == 1.0) ? 1 : 0) << 2)
	    + (cfg_razordrop << 3)
	    + (cfg_cutdrop << 4)
	    + (cfg_futprune << 5)
	    + (cfg_smarteval << 6)
	    + (cfg_attackeval << 7);
	    
      
  sprintf(setcode, "%u", setc);

  initialize_eval();
  alloc_hash();
  alloc_ecache();
      
  return; 
  
}