Changeset 195

Show
Ignore:
Timestamp:
10/09/06 22:00:12 (2 years ago)
Author:
ug
Message:

Improved GameList? interface (e.g. for different board sizes). Added Makefile.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/cpptest.cc

    r194 r195  
    1616  } 
    1717 
    18   GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]]", algos, 19); 
     18  ProcessOptions* p_op = new ProcessOptions; 
     19  p_op->algos = ALGO_FINALPOS | ALGO_MOVELIST; 
     20 
     21  GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]]", 0); 
    1922 
    2023  if (process) { // process sgf's. must be first argument 
     
    2831      if (n.substr(n.size()-4) == ".sgf") { 
    2932        ifstream infile; 
    30         printf("%s\n", n.c_str()); 
     33        // printf("%s\n", n.c_str()); 
    3134        infile.open(it->native_file_string().c_str()); 
    3235 
     
    6063  SearchOptions so; 
    6164  // so.searchInVariations = false; 
    62   gl.search(p, so); 
     65  gl.search(p, &so); 
    6366  printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits()); 
    6467  // vector<string> res = gl.currentEntriesAsStrings(); 
  • 06/libkombilo/process.py

    r194 r195  
    1919 
    2020    starttime = time.time() 
    21     algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL | ALGO_HASH_CORNER 
    2221    try: 
    23         gl = GameList('t1.db', 'id', '', algos, 19
     22        gl = GameList('t1.db', 'id', ''
    2423    except DBError: 
    2524        print 'Database error' 
  • 06/libkombilo/search.cc

    r194 r195  
    143143 
    144144int Pattern::operator==(const Pattern& p) { 
     145  if (boardsize != p.boardsize) return 0; 
    145146  if (sizeX != p.sizeX || sizeY != p.sizeY) return 0; 
    146147  if (left != p.left || right != p.right || top != p.top || bottom != p.bottom) return 0;  
     
    174175  sizeX = 0; 
    175176  sizeY = 0; 
    176 
    177  
    178  
    179 Pattern::Pattern(int type, int boardsize, int sX, int sY, char* iPos) { 
     177  boardsize = 0; 
     178
     179 
     180 
     181Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, char* iPos) { 
    180182  flip = 0; 
    181183  colorSwitch = 0; 
    182184  sizeX = sX; 
    183185  sizeY = sY; 
     186  boardsize = BOARDSIZE; 
    184187 
    185188  if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
     
    224227} 
    225228 
    226 Pattern::Pattern(int type, int boardsize, int sX, int sY, 
     229Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, 
    227230                 char* iPos, vector<MoveNC> CONTLIST) { 
    228231  flip = 0; 
     
    230233  sizeX = sX; 
    231234  sizeY = sY; 
     235  boardsize = BOARDSIZE; 
    232236 
    233237  if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
     
    274278} 
    275279 
    276 Pattern::Pattern(int le, int ri, int to, int bo, int sX, int sY, 
     280Pattern::Pattern(int le, int ri, int to, int bo, int BOARDSIZE, int sX, int sY, 
    277281                 char* iPos, const vector<MoveNC>& CONTLIST) { 
    278282  flip = 0; 
     
    283287  top = to; 
    284288  bottom = bo; 
     289  boardsize = BOARDSIZE; 
    285290 
    286291  sizeX = sX; 
     
    307312  top = p.top; 
    308313  bottom = p.bottom; 
     314  boardsize = p.boardsize; 
    309315  sizeX = p.sizeX; 
    310316  sizeY = p.sizeY; 
     
    327333    top = p.top; 
    328334    bottom = p.bottom; 
     335    boardsize = p.boardsize; 
    329336    sizeX = p.sizeX; 
    330337    sizeY = p.sizeY; 
     
    353360    top = p.top; 
    354361    bottom = p.bottom; 
     362    boardsize = p.boardsize; 
    355363    sizeX = p.sizeX; 
    356364    sizeY = p.sizeY; 
     
    374382string Pattern::printPattern() { 
    375383  string result; 
    376   char buf[40]; 
    377   sprintf(buf, "area: %d, %d, %d, %d\nsize: %d, %d\n", left, right, top, bottom, sizeX, sizeY); 
     384  char buf[100]; 
     385  sprintf(buf, "boardsize: %d, area: %d, %d, %d, %d\nsize: %d, %d\n", boardsize, left, right, top, bottom, sizeX, sizeY); 
    378386  result += buf; 
    379387  for(int i=0; i<sizeY; i++) { 
     
    434442} 
    435443 
    436 PatternList::PatternList(Pattern& p, int fColor, int nMove, int bsize) throw(PatternError) { 
     444PatternList::PatternList(Pattern& p, int fColor, int nMove) throw(PatternError) { 
    437445  pattern.copy(p); 
    438446  fixedColor = fColor; 
    439447  nextMove = nMove; 
    440   boardsize = bsize; 
    441448  special = -1; 
    442449  flipTable = new int[16]; 
     
    468475  vector<Pattern> lCS; 
    469476  vector<pair<int,int> > sy; 
     477  int boardsize = pattern.boardsize; 
    470478 
    471479  for(int f = 0; f < 8; f++) { 
     
    506514    } 
    507515 
    508     Pattern pNew(newLeft, newRight, newTop, newBottom, newSizeX, newSizeY, 
     516    Pattern pNew(newLeft, newRight, newTop, newBottom, pattern.boardsize, newSizeX, newSizeY, 
    509517                 newInitialPos, newContList); 
    510518 
     
    549557 
    550558      // printf("new size %d %d", newSizeX, newSizeY); 
    551       Pattern pNew1(newLeft, newRight, newTop, newBottom, newSizeX, newSizeY, 
     559      Pattern pNew1(newLeft, newRight, newTop, newBottom, pattern.boardsize, newSizeX, newSizeY, 
    552560                    newInitialPos, newContList); 
    553561      pNew1.flip = f; 
     
    801809int Algorithm::readDB(sqlite3* DB) { return 0; } 
    802810int Algorithm::search(PatternList& patternList, GameList& gl, SearchOptions& options) {  
    803   printf("enter Algorithm::search\n"); 
    804811  return -1;  
    805812} 
     
    816823void Algo_signature::initialize_process(sqlite3* DB) throw(DBError) { 
    817824  db = DB; 
    818   int rc = sqlite3_exec(db, "create table if not exists algo_signature ( id integer primary key, signature varchar(12) );",  
    819       0, 0, 0); 
     825  char sql[100]; 
     826  sprintf(sql, "create table if not exists algo_signature_%d ( id integer primary key, signature varchar(12) );", boardsize); 
     827  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    820828  if (rc != SQLITE_OK) throw DBError(); 
    821829  // datasig = new vector<char* >; 
     
    910918  } 
    911919  delete [] signature; 
    912   if (dbinsert1blob(db, "insert into algo_signature (id, signature) values (?,?);", gid, min_signature, 12)) throw DBError(); 
     920  char sql[100]; 
     921  sprintf(sql, "insert into algo_signature_%d (id, signature) values (?,?);", boardsize); 
     922  if (dbinsert1blob(db, sql, gid, min_signature, 12)) throw DBError(); 
    913923  // for(int i=0; i<12; i++) printf("%c", min_signature[i]); printf("\n"); 
    914924  delete [] min_signature; 
     
    934944void Algo_finalpos::initialize_process(sqlite3* DB) throw(DBError) { 
    935945  db = DB; 
    936   int rc = sqlite3_exec(db, "create table if not exists algo_finalpos ( id integer primary key, data blob );", 0, 0, 0); 
     946  char sql[100]; 
     947  sprintf(sql, "create table if not exists algo_finalpos_%d ( id integer primary key, data blob );", boardsize); 
     948  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    937949  if (rc != SQLITE_OK) throw DBError(); 
    938950} 
     
    976988 
    977989void Algo_finalpos::endgame_process() throw(DBError) { 
    978   if (dbinsert1blob(db, "insert into algo_finalpos (id, data) values (?,?);", gid, fp, 100)) throw DBError(); 
     990  char sql[100]; 
     991  sprintf(sql, "insert into algo_finalpos_%d (id, data) values (?,?);", boardsize); 
     992  if (dbinsert1blob(db, sql, gid, fp, 100)) throw DBError(); 
    979993  delete [] fp; 
    980994} 
     
    9911005  data = new vector<char* >; 
    9921006  sqlite3_stmt *ppStmt=0; 
    993   char* sql = "select data from algo_finalpos order by id"; 
     1007  char sql[100]; 
     1008  sprintf(sql, "select data from algo_finalpos_%d order by id", boardsize); 
    9941009  int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    9951010  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
     
    11651180void Algo_movelist::initialize_process(sqlite3* DB) throw(DBError) { 
    11661181  db = DB; 
    1167   int rc = sqlite3_exec(db, 
    1168       "create table if not exists algo_movelist ( id integer primary key, movelist blob, fpC blob );",  
    1169       0, 0, 0); 
     1182  char sql[100]; 
     1183  sprintf(sql, "create table if not exists algo_movelist_%d ( id integer primary key, movelist blob, fpC blob );", boardsize); 
     1184  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    11701185  if (rc != SQLITE_OK) throw DBError(); 
    11711186}                                          
     
    12541269    ml[mlIndex++] = *it; 
    12551270  } 
    1256   if (dbinsert2blobs(db, "insert into algo_movelist (id, movelist, fpC) values (?, ?, ?);", gid, ml, mlIndex, fpC, 50)) throw DBError(); 
     1271  char sql[100]; 
     1272  sprintf(sql, "insert into algo_movelist_%d (id, movelist, fpC) values (?, ?, ?);", boardsize); 
     1273  if (dbinsert2blobs(db, sql, gid, ml, mlIndex, fpC, 50)) throw DBError(); 
    12571274  delete [] ml; 
    12581275  delete [] fpC; 
     
    12781295 
    12791296  sqlite3_stmt *ppStmt=0; 
    1280   char* sql = "select movelist,fpC from algo_movelist order by id"; 
     1297  char sql[100]; 
     1298  sprintf(sql, "select movelist,fpC from algo_movelist_%d order by id", boardsize); 
    12811299  int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    12821300  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
     
    20342052    buf[6+2*i] = mn.data[i]%256; 
    20352053  } 
    2036   char* sql = "insert into algo_hash_full (hash, gameid, hit) values (?,?,?);"; 
     2054  char sql[100]; 
     2055  sprintf(sql, "insert into algo_hash_full_%d (hash, gameid, hit) values (?,?,?);", boardsize); 
    20372056  sqlite3_stmt *ppStmt=0; 
    20382057  int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
     
    20532072 
    20542073void Algo_hash_full::initialize_process(sqlite3* DB) throw(DBError) { 
     2074  // printf("enter algo_hash_full::initialize_processing\n"); 
    20552075  db = DB; 
    2056   int rc = sqlite3_exec(db, "create table if not exists algo_hash_full ( id integer primary key, hash integer, gameid integer, hit text );", 0, 0, 0); 
     2076  char sql[200]; 
     2077  sprintf(sql, "create table if not exists algo_hash_full_%d ( id integer primary key, hash integer, gameid integer, hit text );", boardsize); 
     2078  int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    20572079  if (rc != SQLITE_OK) throw DBError(); 
    2058   rc = sqlite3_exec(db, "create index if not exists hash_idx on algo_hash_full(hash);", 0, 0, 0); 
     2080  sprintf(sql, "create index if not exists hash_idx on algo_hash_full_%d(hash);", boardsize); 
     2081  rc = sqlite3_exec(db, sql, 0, 0, 0); 
    20592082  if (rc != SQLITE_OK) throw DBError(); 
     2083  // printf("leave algo_hash_full::initialize_processing\n"); 
    20602084} 
    20612085         
     
    22142238 
    22152239    char sql[100]; 
    2216     sprintf(sql, "select gameid,hit from algo_hash_full where hash = %lld", hashCode); 
     2240    sprintf(sql, "select gameid,hit from algo_hash_full_%d where hash = %lld", boardsize, hashCode); 
    22172241    // printf("hc %lld, %s\n", hashCode, sql); 
    22182242    pair<vpsip, int> rN(results, N); 
     
    22772301// ----------------------------------------------------------------------------------- 
    22782302 
    2279 Algo_hash::Algo_hash(int bsize, const string& DBNAMEEXT) : Algorithm(bsize) { 
     2303Algo_hash::Algo_hash(int bsize, const string& DBNAMEEXT, int MAXNUMSTONES) : Algorithm(bsize) { 
    22802304  dbnameext = DBNAMEEXT; 
    2281   maxNumStones = 20; // FIXME 
    22822305  hi = 0; 
     2306  maxNumStones = MAXNUMSTONES; 
    22832307} 
    22842308 
     
    22902314  // printf("insert %lld\n", hashCode); 
    22912315  char sql[200]; 
    2292   sprintf(sql, "insert into algo_hash%s (hash, gameid, position) values (?,?,?);", dbnameext.c_str()); 
     2316  sprintf(sql, "insert into algo_hash_%d_%s (hash, gameid, position) values (?,?,?);", boardsize, dbnameext.c_str()); 
    22932317  sqlite3_stmt *ppStmt=0; 
    22942318  int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
     
    23082332 
    23092333void Algo_hash::initialize_process(sqlite3* DB) throw(DBError) { 
     2334  // printf("enter algo_hash::initialize_processing\n"); 
    23102335  db = DB; 
    23112336  char buf[200]; 
    2312   sprintf(buf, "create table if not exists algo_hash%s ( hash integer, gameid integer, position integer );", dbnameext.c_str()); 
     2337  sprintf(buf, "create table if not exists algo_hash_%d_%s ( hash integer, gameid integer, position integer );", boardsize, dbnameext.c_str()); 
    23132338  int rc = sqlite3_exec(db, buf, 0, 0, 0); 
    23142339  if (rc != SQLITE_OK) throw DBError(); 
    2315   sprintf(buf, "create index if not exists hash_idx%s on algo_hash%s(hash);", dbnameext.c_str(), dbnameext.c_str()); 
     2340  sprintf(buf, "create index if not exists hash_idx_%d_%s on algo_hash_%d_%s(hash);", boardsize, dbnameext.c_str(), boardsize, dbnameext.c_str()); 
    23162341  rc = sqlite3_exec(db, buf, 0, 0, 0); 
    23172342  if (rc != SQLITE_OK) throw DBError(); 
     2343  // printf("leave algo_hash::initialize_processing\n"); 
    23182344} 
    23192345         
     
    24292455  int fl2 = fl; 
    24302456  char buf[100]; 
    2431   sprintf(buf, "select gameid,position,hash from algo_hash%s where hash = %lld",  
    2432       dbnameext.c_str(), hashCode); 
     2457  sprintf(buf, "select gameid,position,hash from algo_hash_%d_%s where hash = %lld",  
     2458      boardsize, dbnameext.c_str(), hashCode); 
    24332459  string sql = buf; 
    24342460 
     
    25002526} 
    25012527 
    2502 Algo_hash_corner::Algo_hash_corner(int bsize, int SIZE) : Algo_hash(bsize, "CORNER") { 
     2528Algo_hash_corner::Algo_hash_corner(int bsize, int SIZE, int MAXNUMSTONES) : Algo_hash(bsize, "CORNER", MAXNUMSTONES) { 
    25032529  size = SIZE; 
    25042530  char buf[5]; 
     
    31513177  moveLimit = 10000; 
    31523178  nextMove = 0; 
    3153   trustHashFull = 0
     3179  trustHashFull = false
    31543180  searchInVariations = true; 
     3181  algos = (1<<30) - 1; // use all available algorithms 
    31553182} 
    31563183 
     
    31593186  moveLimit = MOVELIMIT; 
    31603187  nextMove = NEXTMOVE; 
    3161   trustHashFull = 0; 
     3188  trustHashFull = false; 
     3189
     3190 
     3191ProcessOptions::ProcessOptions() { 
     3192  processVariations = true; 
     3193  sgfInDB = true; 
     3194  rootNodeTags = "BR,CA,DT,EV,HC,KM,PB,PC,PW,RE,RO,RU,SZ,US,WR"; 
     3195  algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL | ALGO_HASH_CORNER; 
     3196  algo_hash_full_maxNumStones = 50; 
     3197  algo_hash_corner_maxNumStones = 20; 
     3198
     3199 
     3200ProcessOptions::ProcessOptions(string s) { 
     3201  if (s[0] == 't') processVariations = true; 
     3202  else processVariations = false; 
     3203 
     3204  int p = 2; 
     3205  int pn = s.find('|', p) + 1; 
     3206  algos = atoi(s.substr(p, pn-p-1).c_str()); 
     3207   
     3208  p = pn; 
     3209  pn = s.find('|', p) + 1; 
     3210  algo_hash_full_maxNumStones = atoi(s.substr(p, pn-p-1).c_str()); 
     3211   
     3212  p = pn; 
     3213  pn = s.find('|', p) + 1; 
     3214  algo_hash_corner_maxNumStones = atoi(s.substr(p, pn-p-1).c_str()); 
     3215   
     3216  rootNodeTags = s.substr(pn); 
     3217
     3218 
     3219string ProcessOptions::asString() { 
     3220  string result; 
     3221  if (processVariations) result += "t|"; 
     3222  else result += "f|"; 
     3223  char buf[200]; 
     3224  sprintf(buf, "%d|%d|%d|%s", algos, algo_hash_full_maxNumStones, algo_hash_corner_maxNumStones, rootNodeTags.c_str()); 
     3225  result += buf; 
     3226  return result; 
     3227
     3228 
     3229void ProcessOptions::validate() { 
     3230  if (rootNodeTags.find("PB") == string::npos) rootNodeTags += ",PB"; 
     3231  if (rootNodeTags.find("PW") == string::npos) rootNodeTags += ",PW"; 
     3232  if (rootNodeTags.find("RE") == string::npos) rootNodeTags += ",RE"; 
     3233  if (rootNodeTags.find("DT") == string::npos) rootNodeTags += ",DT"; 
     3234  if (rootNodeTags.find("SZ") == string::npos) rootNodeTags += ",SZ"; 
    31623235} 
    31633236 
     
    32183291} 
    32193292 
    3220 GameList::GameList(char* DBNAME, string ORDERBY, string FORMAT, int ALGOS, int BOARDSIZE) throw(DBError) { 
     3293int dbinfo_callback(void *s, int argc, char **argv, char **asColName) { 
     3294  char** cpp = (char**)s; 
     3295  if (argc && argv[0] && argv[0]) { 
     3296    // printf("dbi_cb %s\n", argv[0]); 
     3297    *cpp = new char[strlen(argv[0]+1)]; 
     3298    strcpy(*cpp, argv[0]); 
     3299  } 
     3300  return 0; 
     3301
     3302 
     3303GameList::GameList(char* DBNAME, string ORDERBY, string FORMAT, ProcessOptions* p_options) throw(DBError) { 
    32213304  labels = 0; 
    32223305  continuations = 0; 
    32233306  dbname = new char[strlen(DBNAME)+1]; 
    32243307  strcpy(dbname, DBNAME); 
     3308 
     3309  // try to retrieve basic options from database 
     3310  sqlite3* db; 
     3311  int rc = sqlite3_open(dbname, &db);  
     3312  if (rc) { 
     3313    sqlite3_close(db); 
     3314    db = 0; 
     3315    throw DBError(); 
     3316  } 
     3317 
     3318  rc = sqlite3_exec(db, "create table if not exists db_info ( info text );", 0, 0, 0); 
     3319  if (rc != SQLITE_OK) throw DBError(); 
     3320  char* dbinfo = 0; 
     3321  rc = sqlite3_exec(db, "select * from db_info where rowid = 1;", dbinfo_callback, &dbinfo, 0); 
     3322  if (rc != SQLITE_OK) throw DBError(); 
     3323 
     3324  if (dbinfo) { 
     3325    // printf("dbinfo: %s\n", dbinfo); 
     3326    p_op = new ProcessOptions(dbinfo); 
     3327    char* bsizes = 0; 
     3328    rc = sqlite3_exec(db, "select * from db_info where rowid = 2;", dbinfo_callback, &bsizes, 0); 
     3329    if (rc != SQLITE_OK) throw DBError(); 
     3330    if (bsizes) { 
     3331      // printf("board sizes %s\n", bsizes); // should be a comma-sep. list of integers *ending w/ a comma* 
     3332      string bsizes_str(bsizes); 
     3333      unsigned int p = 0; 
     3334      unsigned int pn = bsizes_str.find(",",p); 
     3335      while (pn != string::npos) { 
     3336        boardsizes.push_back(atoi(bsizes_str.substr(p, pn-p).c_str())); 
     3337        p = pn+1; 
     3338        pn = bsizes_str.find(",",p); 
     3339      } 
     3340    } 
     3341  } else { // if this does not work: create database and read p_options (or use defaults) 
     3342    // printf("retrieving dbinfo failed\n"); 
     3343    if (p_options == 0) p_op = new ProcessOptions(); // use default values 
     3344    else { 
     3345      // printf("use p_options\n"); 
     3346      p_op = new ProcessOptions(*p_op); 
     3347      p_op->validate(); // make sure the most important information is contained in rootNodeTags list 
     3348    } 
     3349    string sql = "insert into db_info (rowid,info) values (1,'"; 
     3350    sql += p_op->asString(); 
     3351    sql += "');"; 
     3352    rc = sqlite3_exec(db, sql.c_str(), 0, 0, 0); 
     3353    if (rc != SQLITE_OK) throw DBError(); 
     3354    rc = sqlite3_exec(db, "insert into db_info (rowid, info) values (2, ',');", 0, 0, 0); 
     3355    if (rc != SQLITE_OK) throw DBError(); 
     3356  } 
     3357  rc = sqlite3_close(db); 
     3358  if (rc != SQLITE_OK) throw DBError(); 
     3359  db = 0; 
     3360 
     3361  // printf("parse the FORMAT string\n"); 
    32253362  if (FORMAT == "") { // use default format string 
    32263363    numColumns = 5; 
    32273364    format1 = "id,re,pw,pb,dt"; 
    3228     format2 = "%2 - %3 (%W), %4"; 
     3365    format2 = "[[2 - [[3 ([[W), [[4"; 
    32293366  } else { 
    32303367    char buf[10]; 
     
    32393376      if (p+2 < format2.size() && q != string::npos) { 
    32403377        string col = format2.substr(p+2, q-p-2); 
    3241         if (col == "id" || col == "filename" || col == "pos" || col == "duplicate" || col == "date" || col == "BR" || col == "CA" || col == "DT" || col == "EV" || col == "HC" || col == "KM" || col == "PB" || col == "PC" || col == "PW" || col == "RE" || col == "RO" || col == "RU" || col == "SZ" || col == "US" || col == "WR") { 
     3378        // check availability 
     3379        if (col == "id" || col == "filename" || col == "pos" || col == "duplicate" || col == "date" || p_op->rootNodeTags.find(col) != string::npos) { 
    32423380          sprintf(buf, "[[%d", numColumns++);  
    32433381          format2.replace(p,q+2-p, buf); 
     
    32513389        } 
    32523390        p++; 
    3253       } else p = string::npos
     3391      } else break
    32543392    } 
    32553393  } 
    32563394  if (ORDERBY == "" || ORDERBY == "id" || ORDERBY == "ID" || ORDERBY == "Id" || ORDERBY == "iD") orderby = "id"; 
    32573395  else orderby = ORDERBY + ",id"; 
    3258   boardsize = BOARDSIZE; 
    3259   algos = ALGOS; 
    3260   algo_ps = new algo_p[20]; 
    3261   for(int i=0; i<20; i++) algo_ps[i]=0; 
    3262   algo_ps[0] = new Algo_signature(boardsize); 
    3263   if (algos & ALGO_FINALPOS)  
    3264     algo_ps[algo_finalpos] = new Algo_finalpos(boardsize); 
    3265   if (algos & ALGO_MOVELIST)  
    3266     algo_ps[algo_movelist] = new Algo_movelist(boardsize); 
    3267   if (algos & ALGO_HASH_FULL)  
    3268     algo_ps[algo_hash_full] = new Algo_hash_full(boardsize); // FIXME need to give MAXNUMSTONES here 
    3269   if (algos & ALGO_HASH_CORNER)  
    3270     algo_ps[algo_hash_corner] = new Algo_hash_corner(boardsize, 7); // FIXME options 
    3271   // if (algos & ALGO_HASH_SIDE)  
    3272   //   algo_ps[algo_hash_side] = new Algo_hash_side(boardsize, 6, 4); // FIXME need to give MAXNUMSTONES here 
     3396 
     3397  // printf("set up Algorithm instances\n"); 
     3398  for(vector<int>::iterator it = boardsizes.begin(); it != boardsizes.end(); it++) 
     3399    addAlgos(*it); 
    32733400  all = 0; 
    32743401  currentList = oldList = 0; 
     
    32763403} 
    32773404 
    3278 void GameList::readDB() { 
     3405void GameList::addAlgos(int bs) { 
     3406  int ctr = algo_ps.size()/20; 
     3407  // printf("add algos %d %d %d\n", bs, ctr, p_op->algos); 
     3408  for(int i=0; i<20; i++) algo_ps.push_back(0); 
     3409 
     3410  algo_ps[20*ctr] = new Algo_signature(bs); 
     3411  if (p_op->algos & ALGO_FINALPOS)  
     3412    algo_ps[algo_finalpos+20*ctr] = new Algo_finalpos(bs); 
     3413  if (p_op->algos & ALGO_MOVELIST)  
     3414    algo_ps[algo_movelist+20*ctr] = new Algo_movelist(bs); 
     3415  if (p_op->algos & ALGO_HASH_FULL)  
     3416    algo_ps[algo_hash_full+20*ctr] = new Algo_hash_full(bs, p_op->algo_hash_corner_maxNumStones); 
     3417  if (p_op->algos & ALGO_HASH_CORNER)  
     3418    algo_ps[algo_hash_corner+20*ctr] = new Algo_hash_corner(bs, 7, p_op->algo_hash_corner_maxNumStones); 
     3419  // for(int a=20*ctr; a<20*(ctr+1); a++) printf("aa %d %p\n", a, algo_ps[a]); 
     3420  // if (algos & ALGO_HASH_SIDE)  
     3421  //   algo_ps[algo_hash_side] = new Algo_hash_side(boardsize, 6, 4, p_op->algo_hash_side_maxNumStones); 
     3422
     3423 
     3424void GameList::readDB() throw(DBError) { 
     3425  // printf("read dbs\n"); 
    32793426  if (oldList) delete oldList; 
    32803427  if (currentList) delete currentList; 
     
    33123459  // printf("sql: %s\n", sql.c_str()); 
    33133460  rc = sqlite3_exec(db, sql.c_str(), insertEntry, this, 0); 
     3461  if (rc != SQLITE_OK && rc != SQLITE_ERROR) { 
     3462    printf("sql error %d\n", rc); 
     3463    throw DBError();  
     3464  } 
     3465  // SQLITE_ERROR may occur since table might not yet exist 
     3466   
    33143467  if (rc == SQLITE_OK) { 
    3315     for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->readDB(db); 
     3468    for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 
     3469      if (a >= algo_ps.size()) printf("ouch\n"); 
     3470      if (algo_ps[a]) algo_ps[a]->readDB(db); 
     3471    } 
    33163472    readDBs = 1; 
    3317   } else readDBs = 0; 
     3473  } 
    33183474  rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
    3319   if (rc) throw DBError(); 
    3320  
    3321   sqlite3_close(db); 
     3475  if (rc != SQLITE_OK) throw DBError(); 
     3476 
     3477  rc = sqlite3_close(db); 
     3478  if (rc != SQLITE_OK) throw DBError(); 
    33223479  db = 0; 
    33233480  reset(); 
     3481  // printf("leave readDB\n"); 
    33243482} 
    33253483 
    33263484GameList::~GameList() { 
    33273485  // printf("enter ~GameList\n"); 
     3486  if (p_op) delete p_op; 
    33283487  if (labels) delete [] labels; 
    33293488  if (continuations) delete [] continuations; 
     
    33373496  if (oldList) delete oldList; 
    33383497  for(int i=0; i<20; i++)  
    3339     if (algo_ps[i]) { 
    3340       delete algo_ps[i]; 
    3341     } 
    3342   delete [] algo_ps; 
     3498    if (algo_ps[i]) delete algo_ps[i]; 
    33433499  // printf("leave ~GameList\n"); 
    33443500} 
     
    34903646 
    34913647void GameList::gisearch(char* sql) throw(DBError) { 
    3492   int rc = sqlite3_open(dbname, &db); 
    3493   if (rc) { 
    3494     sqlite3_close(db); 
    3495     db = 0; 
    3496     throw DBError(); 
    3497   } 
     3648  bool dbWasOpen = false; 
     3649  if (!db) { 
     3650    int rc = sqlite3_open(dbname, &db); 
     3651    if (rc) { 
     3652      sqlite3_close(db); 
     3653      db = 0; 
     3654      throw DBError(); 
     3655    } 
     3656  } else dbWasOpen = true; 
    34983657  if (start_sorted() == 0) {  
    3499     rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
    3500     if (rc) throw DBError(); 
    3501     rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0); 
    3502     if (rc) throw DBError(); 
    3503  
     3658    if (!dbWasOpen) { 
     3659      int rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
     3660      if (rc) throw DBError(); 
     3661      rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0); 
     3662      if (rc) throw DBError(); 
     3663    } 
    35043664    string query = "select id from games where "; 
    35053665    query += sql; 
    35063666    query += " order by id"; 
    3507     rc = sqlite3_exec(db, query.c_str(), gis_callback, this, 0); 
     3667    int rc = sqlite3_exec(db, query.c_str(), gis_callback, this, 0); 
    35083668    if( rc!=SQLITE_OK ) throw DBError(); 
    35093669 
    3510     rc = sqlite3_close(db); 
    3511     if( rc!=SQLITE_OK ) throw DBError(); 
    3512     db = 0; 
     3670    if (!dbWasOpen) { 
     3671      rc = sqlite3_close(db); 
     3672      if( rc!=SQLITE_OK ) throw DBError(); 
     3673      db = 0; 
     3674    } 
    35133675    end_sorted(); 
    35143676  } 
     
    35713733} 
    35723734 
    3573 void GameList::search(Pattern& pattern, SearchOptions& so) throw(DBError) { 
     3735void GameList::search(Pattern& pattern, SearchOptions* so) throw(DBError) { 
     3736  SearchOptions* searchOptions; 
     3737  if (so) searchOptions = new SearchOptions(*so); 
     3738  else searchOptions = new SearchOptions(); 
    35743739  sizeX = pattern.sizeX; // need this in lookupLabel 
    3575   PatternList pl(pattern, so.fixedColor, so.nextMove, boardsize); 
     3740  PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 
    35763741  sqlite3* db; 
    35773742  int rc = sqlite3_open(dbname, &db);  
     
    35863751  if (rc) throw DBError(); 
    35873752 
     3753 
     3754  if (boardsizes.size() != 1 || boardsizes[0] != pattern.boardsize) { 
     3755    char buf[20]; 
     3756    sprintf(buf, "sz = %d", pattern.boardsize); 
     3757    gisearch(buf); 
     3758  } 
    35883759  if (!readDBs) { 
    3589     for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->readDB(db); 
     3760    for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->readDB(db); 
    35903761    readDBs = 1; 
    35913762  } 
     
    35933764  int hash_result = -1; 
    35943765  // FULL BOARD PATTERN? 
    3595   if (pl.pattern.sizeX == 19 && pl.pattern.sizeY == 19 && algo_ps[algo_hash_full]) { 
    3596     hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, so, db); 
     3766  if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX == pattern.boardsize && pattern.sizeY == pattern.boardsize && algo_ps[algo_hash_full]) { 
     3767    hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, *searchOptions, db); 
    35973768    if (hash_result == 1) { 
    35983769    } else if (hash_result == 0) { 
    3599       algo_ps[algo_movelist]->search(pl, *this, so); 
     3770      if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist]) 
     3771        algo_ps[algo_movelist]->search(pl, *this, *searchOptions); 
    36003772    } 
    36013773  } 
     
    36033775 
    36043776    // CORNER PATTERN? 
    3605     if (pl.pattern.sizeX >= 7 && pl.pattern.sizeY >= 7 && algo_ps[algo_hash_corner]) { // FIXME 
    3606       hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, so, db); 
     3777    if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX >= 7 && pattern.sizeY >= 7 && algo_ps[algo_hash_corner]) { 
     3778      hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, *searchOptions, db); 
    36073779      if (hash_result == 0) { 
    3608         printf("corner hashing successful\n"); 
    3609         algo_ps[algo_movelist]->search(pl, *this, so); 
     3780        if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist]) 
     3781          algo_ps[algo_movelist]->search(pl, *this, *searchOptions); 
    36103782      } 
    36113783    } 
    36123784 
    36133785    if (hash_result == -1) { 
    3614       algo_ps[algo_finalpos]->search(pl, *this, so); 
    3615       algo_ps[algo_movelist]->search(pl, *this, so); 
     3786      if (searchOptions->algos & ALGO_FINALPOS && algo_ps[algo_finalpos]) 
     3787        algo_ps[algo_finalpos]->search(pl, *this, *searchOptions); 
     3788      if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist]) 
     3789        algo_ps[algo_movelist]->search(pl, *this, *searchOptions); 
    36163790    } 
    36173791  } 
     
    36233797  continuations = pl.continuations; 
    36243798  pl.continuations = new Continuation[pattern.sizeX*pattern.sizeY]; 
     3799  delete searchOptions; 
    36253800} 
    36263801 
    36273802 
    36283803void GameList::start_processing(int PROCESSVARIATIONS) throw(DBError) { 
    3629   processVariations = PROCESSVARIATIONS; 
     3804  // printf("enter start_processing %p\n", p_op); 
     3805  if (PROCESSVARIATIONS != -1) processVariations = PROCESSVARIATIONS; 
     3806  else processVariations = p_op->processVariations; 
    36303807  readDBs = 0; 
     3808  string question_marks = "?,?,?,?"; // path, filename, pos, date 
     3809  tags = new vector<string>; 
     3810  int ctr = 0; 
     3811  unsigned int p = 0; 
     3812  unsigned int pn = p_op->rootNodeTags.find(',', p); 
     3813  while (pn != string::npos) { 
     3814    tags->push_back(p_op->rootNodeTags.substr(p,pn-p)); 
     3815    question_marks += ",?"; 
     3816    if (p_op->rootNodeTags.substr(p,pn-p) == "DT") posDT = ctr; 
     3817    if (p_op->rootNodeTags.substr(p,pn-p) == "SZ") posSZ = ctr; 
     3818    ctr++; 
     3819    p = pn+1; 
     3820    pn = p_op->rootNodeTags.find(',', p); 
     3821  } 
     3822  tags->push_back(p_op->rootNodeTags.substr(p)); 
     3823  question_marks += ",?"; 
     3824  if (p_op->rootNodeTags.substr(p) == "DT") posDT = ctr; 
     3825  if (p_op->rootNodeTags.substr(p) == "SZ") posSZ = ctr; 
     3826  // printf("dt %d sz %d\n", posDT, posSZ); 
     3827 
     3828  sql_ins_rnp = "insert into games (path, filename, pos, date, "; 
     3829  if (p_op->sgfInDB) { 
     3830    sql_ins_rnp += "sgf, "; 
     3831    question_marks += ",?"; 
     3832  } 
     3833  sql_ins_rnp += p_op->rootNodeTags + ") values (" + question_marks + ");"; 
    36313834  int rc = sqlite3_open(dbname, &db);  
    36323835  if (rc) { 
     
    36353838    throw DBError(); 
    36363839  } 
    3637   char* sql1 = "create table if not exists GAMES ( id integer primary key, path text, filename text, pos integer default 0, duplicate integer, date date, BR text, CA text, DT text, EV text, HC text, KM text, PB text, PC text, PW text, RE text, RO text, RU text, SZ text, US text, WR text);"; 
    3638   rc = sqlite3_exec(db, sql1, 0, 0, 0); 
     3840  string sql1 = "create table if not exists GAMES ( id integer primary key, path text, filename text, pos integer default 0, duplicate integer, date date"; 
     3841  if (p_op->sgfInDB) sql1 += ", sgf text"; 
     3842  for(vector<string>::iterator it = tags->begin(); it != tags->end(); it++) sql1 += ", " + *it + " text"; 
     3843  sql1 +=  ");"; 
     3844  rc = sqlite3_exec(db, sql1.c_str(), 0, 0, 0); 
    36393845  if( rc!=SQLITE_OK ) throw DBError(); 
    36403846 
    36413847  sql1 = "create table if not exists TAGS ( id integer primary key, slug text, description text, visible integer );"; 
    3642   rc = sqlite3_exec(db, sql1, 0, 0, 0); 
     3848  rc = sqlite3_exec(db, sql1.c_str(), 0, 0, 0); 
    36433849  if( rc!=SQLITE_OK ) throw DBError(); 
    36443850 
    36453851  sql1 = "create table if not exists GAME_TAGS ( id integer primary key, game_id integer, tag_id integer );"; 
    3646   rc = sqlite3_exec(db, sql1, 0, 0, 0); 
     3852  rc = sqlite3_exec(db, sql1.c_str(), 0, 0, 0); 
    36473853  if( rc!=SQLITE_OK ) throw DBError(); 
    36483854  rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 
     
    36593865  } 
    36603866  current = 0; 
    3661   for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->initialize_process(db); 
    3662 
    3663  
     3867  for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->initialize_process(db); 
     3868
    36643869 
    36653870void GameList::finalize_processing() throw(DBError) { 
    3666   for(int i=0; i<20; i++)  
    3667     if (algo_ps[i]) { 
    3668       algo_ps[i]->finalize_process(); 
    3669     } 
    3670   char* sql = "end transaction;"; 
    3671   int rc = sqlite3_exec(db, sql, 0, 0, 0); 
    3672   if (rc) { 
     3871  for(unsigned int a=0; a<20*boardsizes.size(); a++)  
     3872    if (algo_ps[a]) algo_ps[a]->finalize_process(); 
     3873  int rc = sqlite3_exec(db, "commit;", 0, 0, 0); 
     3874  if (rc != SQLITE_OK) { 
    36733875    sqlite3_close(db); 
    36743876    db = 0; 
    36753877    throw DBError(); 
    36763878  } 
     3879  string sql = "update db_info set info = '"; 
     3880  for(vector<int>::iterator it = boardsizes.begin(); it != boardsizes.end(); it++) { 
     3881    char buf[20]; 
     3882    sprintf(buf, "%d,", *it); 
     3883    sql += buf; 
     3884  }  
     3885  sql += "' WHERE rowid = 2;"; 
     3886  rc = sqlite3_exec(db, sql.c_str(), 0, 0, 0); 
     3887  if (rc != SQLITE_OK) throw DBError(); 
    36773888  sqlite3_close(db); 
    36783889  db = 0; 
    36793890  readDB(); 
    3680 
    3681  
     3891  delete tags; 
     3892
    36823893 
    36833894int GameList::process(const char* sgf, const char* path, const char* fn) throw(SGFError,DBError) { 
     
    37113922    //  } 
    37123923    // } 
    3713     char_p* rootNodeProperties = parseRootNode(root); 
    3714     string dt; 
    3715     if (rootNodeProperties[posDT]) dt = rootNodeProperties[posDT]; 
     3924    vector<string>* rootNodeProperties = parseRootNode(root, tags); 
     3925    // for(vector<string>::iterator rnp = rootNodeProperties->begin(); rnp != rootNodeProperties->end(); rnp++) 
     3926    // printf("rnp %s\n", rnp->c_str()); 
     3927 
     3928    // check board size 
     3929    string sz = (*rootNodeProperties)[posSZ]; 
     3930    // printf("sz %s\n", sz.c_str()); 
     3931    if (sz=="") sz = "19"; 
     3932    int bs = atoi(sz.c_str()); 
     3933    int algo_offset = -1; 
     3934    int bs_ctr = 0; 
     3935    for(vector<int>::iterator it = boardsizes.begin();  it != boardsizes.end(); it++) { 
     3936      if (*it == bs) { 
     3937        algo_offset = bs_ctr; 
     3938        break; 
     3939      } 
     3940      bs_ctr++; 
     3941    }   
     3942    if (algo_offset == -1) { // not found 
     3943      boardsizes.push_back(bs); 
     3944      addAlgos(bs); 
     3945      algo_offset = algo_ps.size()/20 - 1; 
     3946      // printf("algo_offset %d %d \n", algo_offset, algo_ps.size()); 
     3947      for(int a=20*algo_offset; a < 20*(algo_offset+1); a++) { 
     3948        // printf("a %d\n", a); 
     3949        // printf("%p\n", algo_ps[a]); 
     3950        if (algo_ps[a]) algo_ps[a]->initialize_process(db); 
     3951      } 
     3952    } 
     3953 
     3954    // parse DT tag 
     3955    string dt = (*rootNodeProperties)[posDT]; 
     3956    // printf("dt %s\n", dt.c_str()); 
    37163957    string date; 
    37173958 
     
    37764017    } 
    37774018 
    3778     char* sql = "insert into games (path, filename, pos, date, BR, CA, DT, EV, HC, KM, PB, PC, PW, RE, RO, RU, SZ, US, WR) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
     4019    // printf("sql %s\n", sql_ins_rnp.c_str())
    37794020    sqlite3_stmt *ppStmt=0; 
    3780     int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    3781     if (rc != SQLITE_OK || ppStmt==0) throw DBError(); // FIXME: catch busy error, (and/or throw DBError?) 
    3782  
    3783     rc = sqlite3_bind_text(ppStmt, 1, path, -1, SQLITE_TRANSIENT); 
     4021    int rc = sqlite3_prepare(db, sql_ins_rnp.c_str(), -1, &ppStmt, 0); 
     4022    if (rc != SQLITE_OK || ppStmt==0) { 
     4023      printf("db error %d\n", rc); 
     4024      throw DBError(); // FIXME: catch busy error, (and/or throw DBError?) 
     4025    } 
     4026 
     4027    int stmt_ctr = 1; 
     4028    rc = sqlite3_bind_text(ppStmt, stmt_ctr++, path, -1, SQLITE_TRANSIENT); 
    37844029    if (rc != SQLITE_OK) throw DBError(); 
    3785     rc = sqlite3_bind_text(ppStmt, 2, fn, -1, SQLITE_TRANSIENT);  
     4030    rc = sqlite3_bind_text(ppStmt, stmt_ctr++, fn, -1, SQLITE_TRANSIENT);  
    37864031    if (rc != SQLITE_OK) throw DBError(); 
    3787     rc = sqlite3_bind_int(ppStmt, 3, pos); 
     4032    rc = sqlite3_bind_int(ppStmt, stmt_ctr++, pos); 
    37884033    if (rc != SQLITE_OK) throw DBError(); 
    3789     rc = sqlite3_bind_text(ppStmt, 4, date.c_str(), -1, SQLITE_TRANSIENT);  
     4034    rc = sqlite3_bind_text(ppStmt, stmt_ctr++, date.c_str(), -1, SQLITE_TRANSIENT);  
    37904035    if (rc != SQLITE_OK) throw DBError(); 
    37914036 
    3792     for(int i=0; i<15; i++) { 
    3793       rc = sqlite3_bind_text(ppStmt, i+5, rootNodeProperties[i], -1, SQLITE_TRANSIENT);  
    3794       delete [] rootNodeProperties[i]; 
     4037    if (p_op->sgfInDB) { 
     4038      rc = sqlite3_bind_text(ppStmt, stmt_ctr++, sgf, -1, SQLITE_TRANSIENT);  
     4039      if (rc != SQLITE_OK) throw DBError(); 
     4040    } 
     4041 
     4042    for(vector<string>::iterator it = rootNodeProperties->begin(); it != rootNodeProperties->end(); it++) { 
     4043      rc = sqlite3_bind_text(ppStmt, stmt_ctr++, it->c_str(), -1, SQLITE_TRANSIENT);  
    37954044      if (rc != SQLITE_OK) throw DBError(); 
    37964045    } 
     
    38014050    if (rc != SQLITE_OK)  throw DBError(); 
    38024051 
    3803     delete [] rootNodeProperties; 
    3804    
     4052    delete rootNodeProperties; 
    38054053    int game_id = sqlite3_last_insert_rowid(db); 
    38064054 
    3807     // play through the game 
     4055    // printf("play through the game\n"); 
    38084056 
    38094057    Node* currentN = root; 
    3810     for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->newgame_process(game_id); 
    3811  
    3812     abstractBoard b = abstractBoard(boardsize); // BOARDSIZE?! 
     4058    for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4059      if (algo_ps[a]) algo_ps[a]->newgame_process(game_id); 
     4060 
     4061    abstractBoard b = abstractBoard(bs); 
    38134062    int whichVar = 0; 
    38144063    stack<VarInfo> branchpoints; 
    38154064 
    38164065    while (currentN) { 
     4066      // printf("nn\n"); 
    38174067      bool caughtSGFError = false; 
    38184068      try { 
     
    38654115                continue; 
    38664116              } 
    3867               if (97 <= s[i] && s[i] <= 96+boardsize) { // valid board coordinate? 
     4117              if (97 <= s[i] && s[i] <= 96+bs) { // valid board coordinate? 
    38684118                propValue[propValueIndex++] = s[i]; 
    38694119              } else if (s[i] == 't') { ; // allow passes, but do not record them (we handle them a little sloppily here) 
     
    38894139          if (!propValueIndex) { // in particular, this happens if !IDrelevant 
    38904140            if (!strcmp(ID, "B") || !strcmp(ID, "W")) { 
    3891               for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->pass_process(); 
     4141              for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4142                if (algo_ps[a]) algo_ps[a]->pass_process(); 
    38924143            } 
    38934144            delete [] propValue; 
     
    39024153            Move m = b.undostack.top(); 
    39034154 
    3904             for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->move_process(m); 
     4155            for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4156              if (algo_ps[a]) algo_ps[a]->move_process(m); 
    39054157          } else 
    39064158            if (!strcmp(ID, "AB")) { 
     
    39094161                char y = propValue[2*pp+1]-97; 
    39104162                if (!b.play(x, y, "B")) throw SGFError(); 
    3911                 for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AB_process(x, y); 
     4163                for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4164                  if (algo_ps[a]) algo_ps[a]->AB_process(x, y); 
    39124165              } 
    39134166            } else 
     
    39174170                  char y = propValue[2*pp+1]-97; 
    39184171                  if (!b.play(x, y, "W")) throw SGFError(); 
    3919                   for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AW_process(x, y); 
     4172                  for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4173                    if (algo_ps[a]) algo_ps[a]->AW_process(x, y); 
    39204174                } 
    39214175              } else { 
     
    39274181                    if (removed==' ') throw SGFError(); 
    39284182                    b.remove(x, y); 
    3929                     for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->AE_process(x, y, removed); 
     4183                    for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4184                      if (algo_ps[a]) algo_ps[a]->AE_process(x, y, removed); 
    39304185                  } 
    39314186                } 
     
    39344189        }  
    39354190      } catch (SGFError) { 
    3936         printf("SGF error\n"); 
    39374191        caughtSGFError = true; 
    39384192      } 
    39394193 
    3940       for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endOfNode_process(); 
     4194      for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4195        if (algo_ps[a]) algo_ps[a]->endOfNode_process(); 
    39414196 
    39424197      if (processVariations && currentN->numChildren > 1) { // several variations start from this node; 
    3943         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->branchpoint_process(); 
     4198        for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4199          if (algo_ps[a]) algo_ps[a]->branchpoint_process(); 
    39444200        branchpoints.push(VarInfo(currentN, new abstractBoard(b), 0)); 
    39454201      } 
     
    39534209        whichVar = branchpoints.top().i; 
    39544210        branchpoints.pop(); 
    3955         for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endOfVariation_process(); 
     4211        for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4212          if (algo_ps[a]) algo_ps[a]->endOfVariation_process(); 
    39564213        if (whichVar+2 < currentN->numChildren) { 
    3957           for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->branchpoint_process(); 
     4214          for(int a=20*algo_offset; a < 20*(algo_offset+1); a++)  
     4215            if (algo_ps[a]) algo_ps[a]->branchpoint_process(); 
    39584216          branchpoints.push(VarInfo(currentN, new abstractBoard(b), whichVar+1)); 
    39594217        } 
     
    39624220      }  
    39634221    } // while 
    3964     for(int a=0; a < 20; a++) if (algo_ps[a]) algo_ps[a]->endgame_process(); 
     4222    for(int a=20*algo_offset; a < 20*(algo_offset+1); a++) { 
     4223      // printf("endgame %d\n", a); 
     4224      if (algo_ps[a]) algo_ps[a]->endgame_process(); 
     4225    } 
    39654226    root = root->down; 
    39664227    pos++; 
  • 06/libkombilo/search.h

    r194 r195