Changeset 195
- Timestamp:
- 10/09/06 22:00:12 (2 years ago)
- Files:
-
- 06/libkombilo/Makefile (added)
- 06/libkombilo/cpptest.cc (modified) (3 diffs)
- 06/libkombilo/process.py (modified) (1 diff)
- 06/libkombilo/search.cc (modified) (59 diffs)
- 06/libkombilo/search.h (modified) (12 diffs)
- 06/libkombilo/sgfparser.cc (modified) (2 diffs)
- 06/libkombilo/sgfparser.h (modified) (1 diff)
- 06/libkombilo/testhash.py (modified) (2 diffs)
- 06/libkombilo/testsearch.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/cpptest.cc
r194 r195 16 16 } 17 17 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); 19 22 20 23 if (process) { // process sgf's. must be first argument … … 28 31 if (n.substr(n.size()-4) == ".sgf") { 29 32 ifstream infile; 30 printf("%s\n", n.c_str());33 // printf("%s\n", n.c_str()); 31 34 infile.open(it->native_file_string().c_str()); 32 35 … … 60 63 SearchOptions so; 61 64 // so.searchInVariations = false; 62 gl.search(p, so);65 gl.search(p, &so); 63 66 printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits()); 64 67 // vector<string> res = gl.currentEntriesAsStrings(); 06/libkombilo/process.py
r194 r195 19 19 20 20 starttime = time.time() 21 algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL | ALGO_HASH_CORNER22 21 try: 23 gl = GameList('t1.db', 'id', '' , algos, 19)22 gl = GameList('t1.db', 'id', '') 24 23 except DBError: 25 24 print 'Database error' 06/libkombilo/search.cc
r194 r195 143 143 144 144 int Pattern::operator==(const Pattern& p) { 145 if (boardsize != p.boardsize) return 0; 145 146 if (sizeX != p.sizeX || sizeY != p.sizeY) return 0; 146 147 if (left != p.left || right != p.right || top != p.top || bottom != p.bottom) return 0; … … 174 175 sizeX = 0; 175 176 sizeY = 0; 176 } 177 178 179 Pattern::Pattern(int type, int boardsize, int sX, int sY, char* iPos) { 177 boardsize = 0; 178 } 179 180 181 Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, char* iPos) { 180 182 flip = 0; 181 183 colorSwitch = 0; 182 184 sizeX = sX; 183 185 sizeY = sY; 186 boardsize = BOARDSIZE; 184 187 185 188 if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { … … 224 227 } 225 228 226 Pattern::Pattern(int type, int boardsize, int sX, int sY,229 Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, 227 230 char* iPos, vector<MoveNC> CONTLIST) { 228 231 flip = 0; … … 230 233 sizeX = sX; 231 234 sizeY = sY; 235 boardsize = BOARDSIZE; 232 236 233 237 if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { … … 274 278 } 275 279 276 Pattern::Pattern(int le, int ri, int to, int bo, int sX, int sY,280 Pattern::Pattern(int le, int ri, int to, int bo, int BOARDSIZE, int sX, int sY, 277 281 char* iPos, const vector<MoveNC>& CONTLIST) { 278 282 flip = 0; … … 283 287 top = to; 284 288 bottom = bo; 289 boardsize = BOARDSIZE; 285 290 286 291 sizeX = sX; … … 307 312 top = p.top; 308 313 bottom = p.bottom; 314 boardsize = p.boardsize; 309 315 sizeX = p.sizeX; 310 316 sizeY = p.sizeY; … … 327 333 top = p.top; 328 334 bottom = p.bottom; 335 boardsize = p.boardsize; 329 336 sizeX = p.sizeX; 330 337 sizeY = p.sizeY; … … 353 360 top = p.top; 354 361 bottom = p.bottom; 362 boardsize = p.boardsize; 355 363 sizeX = p.sizeX; 356 364 sizeY = p.sizeY; … … 374 382 string Pattern::printPattern() { 375 383 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); 378 386 result += buf; 379 387 for(int i=0; i<sizeY; i++) { … … 434 442 } 435 443 436 PatternList::PatternList(Pattern& p, int fColor, int nMove , int bsize) throw(PatternError) {444 PatternList::PatternList(Pattern& p, int fColor, int nMove) throw(PatternError) { 437 445 pattern.copy(p); 438 446 fixedColor = fColor; 439 447 nextMove = nMove; 440 boardsize = bsize;441 448 special = -1; 442 449 flipTable = new int[16]; … … 468 475 vector<Pattern> lCS; 469 476 vector<pair<int,int> > sy; 477 int boardsize = pattern.boardsize; 470 478 471 479 for(int f = 0; f < 8; f++) { … … 506 514 } 507 515 508 Pattern pNew(newLeft, newRight, newTop, newBottom, newSizeX, newSizeY,516 Pattern pNew(newLeft, newRight, newTop, newBottom, pattern.boardsize, newSizeX, newSizeY, 509 517 newInitialPos, newContList); 510 518 … … 549 557 550 558 // 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, 552 560 newInitialPos, newContList); 553 561 pNew1.flip = f; … … 801 809 int Algorithm::readDB(sqlite3* DB) { return 0; } 802 810 int Algorithm::search(PatternList& patternList, GameList& gl, SearchOptions& options) { 803 printf("enter Algorithm::search\n");804 811 return -1; 805 812 } … … 816 823 void Algo_signature::initialize_process(sqlite3* DB) throw(DBError) { 817 824 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); 820 828 if (rc != SQLITE_OK) throw DBError(); 821 829 // datasig = new vector<char* >; … … 910 918 } 911 919 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(); 913 923 // for(int i=0; i<12; i++) printf("%c", min_signature[i]); printf("\n"); 914 924 delete [] min_signature; … … 934 944 void Algo_finalpos::initialize_process(sqlite3* DB) throw(DBError) { 935 945 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); 937 949 if (rc != SQLITE_OK) throw DBError(); 938 950 } … … 976 988 977 989 void 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(); 979 993 delete [] fp; 980 994 } … … 991 1005 data = new vector<char* >; 992 1006 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); 994 1009 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 995 1010 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) … … 1165 1180 void Algo_movelist::initialize_process(sqlite3* DB) throw(DBError) { 1166 1181 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); 1170 1185 if (rc != SQLITE_OK) throw DBError(); 1171 1186 } … … 1254 1269 ml[mlIndex++] = *it; 1255 1270 } 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(); 1257 1274 delete [] ml; 1258 1275 delete [] fpC; … … 1278 1295 1279 1296 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); 1281 1299 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1282 1300 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) … … 2034 2052 buf[6+2*i] = mn.data[i]%256; 2035 2053 } 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); 2037 2056 sqlite3_stmt *ppStmt=0; 2038 2057 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); … … 2053 2072 2054 2073 void Algo_hash_full::initialize_process(sqlite3* DB) throw(DBError) { 2074 // printf("enter algo_hash_full::initialize_processing\n"); 2055 2075 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); 2057 2079 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); 2059 2082 if (rc != SQLITE_OK) throw DBError(); 2083 // printf("leave algo_hash_full::initialize_processing\n"); 2060 2084 } 2061 2085 … … 2214 2238 2215 2239 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); 2217 2241 // printf("hc %lld, %s\n", hashCode, sql); 2218 2242 pair<vpsip, int> rN(results, N); … … 2277 2301 // ----------------------------------------------------------------------------------- 2278 2302 2279 Algo_hash::Algo_hash(int bsize, const string& DBNAMEEXT ) : Algorithm(bsize) {2303 Algo_hash::Algo_hash(int bsize, const string& DBNAMEEXT, int MAXNUMSTONES) : Algorithm(bsize) { 2280 2304 dbnameext = DBNAMEEXT; 2281 maxNumStones = 20; // FIXME2282 2305 hi = 0; 2306 maxNumStones = MAXNUMSTONES; 2283 2307 } 2284 2308 … … 2290 2314 // printf("insert %lld\n", hashCode); 2291 2315 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()); 2293 2317 sqlite3_stmt *ppStmt=0; 2294 2318 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); … … 2308 2332 2309 2333 void Algo_hash::initialize_process(sqlite3* DB) throw(DBError) { 2334 // printf("enter algo_hash::initialize_processing\n"); 2310 2335 db = DB; 2311 2336 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()); 2313 2338 int rc = sqlite3_exec(db, buf, 0, 0, 0); 2314 2339 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()); 2316 2341 rc = sqlite3_exec(db, buf, 0, 0, 0); 2317 2342 if (rc != SQLITE_OK) throw DBError(); 2343 // printf("leave algo_hash::initialize_processing\n"); 2318 2344 } 2319 2345 … … 2429 2455 int fl2 = fl; 2430 2456 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); 2433 2459 string sql = buf; 2434 2460 … … 2500 2526 } 2501 2527 2502 Algo_hash_corner::Algo_hash_corner(int bsize, int SIZE ) : Algo_hash(bsize, "CORNER") {2528 Algo_hash_corner::Algo_hash_corner(int bsize, int SIZE, int MAXNUMSTONES) : Algo_hash(bsize, "CORNER", MAXNUMSTONES) { 2503 2529 size = SIZE; 2504 2530 char buf[5]; … … 3151 3177 moveLimit = 10000; 3152 3178 nextMove = 0; 3153 trustHashFull = 0;3179 trustHashFull = false; 3154 3180 searchInVariations = true; 3181 algos = (1<<30) - 1; // use all available algorithms 3155 3182 } 3156 3183 … … 3159 3186 moveLimit = MOVELIMIT; 3160 3187 nextMove = NEXTMOVE; 3161 trustHashFull = 0; 3188 trustHashFull = false; 3189 } 3190 3191 ProcessOptions::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 3200 ProcessOptions::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 3219 string 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 3229 void 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"; 3162 3235 } 3163 3236 … … 3218 3291 } 3219 3292 3220 GameList::GameList(char* DBNAME, string ORDERBY, string FORMAT, int ALGOS, int BOARDSIZE) throw(DBError) { 3293 int 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 3303 GameList::GameList(char* DBNAME, string ORDERBY, string FORMAT, ProcessOptions* p_options) throw(DBError) { 3221 3304 labels = 0; 3222 3305 continuations = 0; 3223 3306 dbname = new char[strlen(DBNAME)+1]; 3224 3307 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"); 3225 3362 if (FORMAT == "") { // use default format string 3226 3363 numColumns = 5; 3227 3364 format1 = "id,re,pw,pb,dt"; 3228 format2 = " %2 - %3 (%W), %4";3365 format2 = "[[2 - [[3 ([[W), [[4"; 3229 3366 } else { 3230 3367 char buf[10]; … … 3239 3376 if (p+2 < format2.size() && q != string::npos) { 3240 3377 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) { 3242 3380 sprintf(buf, "[[%d", numColumns++); 3243 3381 format2.replace(p,q+2-p, buf); … … 3251 3389 } 3252 3390 p++; 3253 } else p = string::npos;3391 } else break; 3254 3392 } 3255 3393 } 3256 3394 if (ORDERBY == "" || ORDERBY == "id" || ORDERBY == "ID" || ORDERBY == "Id" || ORDERBY == "iD") orderby = "id"; 3257 3395 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); 3273 3400 all = 0; 3274 3401 currentList = oldList = 0; … … 3276 3403 } 3277 3404 3278 void GameList::readDB() { 3405 void 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 3424 void GameList::readDB() throw(DBError) { 3425 // printf("read dbs\n"); 3279 3426 if (oldList) delete oldList; 3280 3427 if (currentList) delete currentList; … … 3312 3459 // printf("sql: %s\n", sql.c_str()); 3313 3460 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 3314 3467 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 } 3316 3472 readDBs = 1; 3317 } else readDBs = 0;3473 } 3318 3474 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(); 3322 3479 db = 0; 3323 3480 reset(); 3481 // printf("leave readDB\n"); 3324 3482 } 3325 3483 3326 3484 GameList::~GameList() { 3327 3485 // printf("enter ~GameList\n"); 3486 if (p_op) delete p_op; 3328 3487 if (labels) delete [] labels; 3329 3488 if (continuations) delete [] continuations; … … 3337 3496 if (oldList) delete oldList; 3338 3497 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]; 3343 3499 // printf("leave ~GameList\n"); 3344 3500 } … … 3490 3646 3491 3647 void 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; 3498 3657 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 } 3504 3664 string query = "select id from games where "; 3505 3665 query += sql; 3506 3666 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); 3508 3668 if( rc!=SQLITE_OK ) throw DBError(); 3509 3669 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 } 3513 3675 end_sorted(); 3514 3676 } … … 3571 3733 } 3572 3734 3573 void GameList::search(Pattern& pattern, SearchOptions& so) throw(DBError) { 3735 void GameList::search(Pattern& pattern, SearchOptions* so) throw(DBError) { 3736 SearchOptions* searchOptions; 3737 if (so) searchOptions = new SearchOptions(*so); 3738 else searchOptions = new SearchOptions(); 3574 3739 sizeX = pattern.sizeX; // need this in lookupLabel 3575 PatternList pl(pattern, s o.fixedColor, so.nextMove, boardsize);3740 PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 3576 3741 sqlite3* db; 3577 3742 int rc = sqlite3_open(dbname, &db); … … 3586 3751 if (rc) throw DBError(); 3587 3752 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 } 3588 3759 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); 3590 3761 readDBs = 1; 3591 3762 } … … 3593 3764 int hash_result = -1; 3594 3765 // 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); 3597 3768 if (hash_result == 1) { 3598 3769 } 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); 3600 3772 } 3601 3773 } … … 3603 3775 3604 3776 // CORNER PATTERN? 3605 if ( pl.pattern.sizeX >= 7 && pl.pattern.sizeY >= 7 && algo_ps[algo_hash_corner]) { // FIXME3606 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); 3607 3779 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); 3610 3782 } 3611 3783 } 3612 3784 3613 3785 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); 3616 3790 } 3617 3791 } … … 3623 3797 continuations = pl.continuations; 3624 3798 pl.continuations = new Continuation[pattern.sizeX*pattern.sizeY]; 3799 delete searchOptions; 3625 3800 } 3626 3801 3627 3802 3628 3803 void 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; 3630 3807 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 + ");"; 3631 3834 int rc = sqlite3_open(dbname, &db); 3632 3835 if (rc) { … … 3635 3838 throw DBError(); 3636 3839 } 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); 3639 3845 if( rc!=SQLITE_OK ) throw DBError(); 3640 3846 3641 3847 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); 3643 3849 if( rc!=SQLITE_OK ) throw DBError(); 3644 3850 3645 3851 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); 3647 3853 if( rc!=SQLITE_OK ) throw DBError(); 3648 3854 rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); … … 3659 3865 } 3660 3866 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 } 3664 3869 3665 3870 void 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) { 3673 3875 sqlite3_close(db); 3674 3876 db = 0; 3675 3877 throw DBError(); 3676 3878 } 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(); 3677 3888 sqlite3_close(db); 3678 3889 db = 0; 3679 3890 readDB(); 3680 } 3681 3891 delete tags; 3892 } 3682 3893 3683 3894 int GameList::process(const char* sgf, const char* path, const char* fn) throw(SGFError,DBError) { … … 3711 3922 // } 3712 3923 // } 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()); 3716 3957 string date; 3717 3958 … … 3776 4017 } 3777 4018 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()); 3779 4020 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); 3784 4029 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); 3786 4031 if (rc != SQLITE_OK) throw DBError(); 3787 rc = sqlite3_bind_int(ppStmt, 3, pos);4032 rc = sqlite3_bind_int(ppStmt, stmt_ctr++, pos); 3788 4033 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); 3790 4035 if (rc != SQLITE_OK) throw DBError(); 3791 4036 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); 3795 4044 if (rc != SQLITE_OK) throw DBError(); 3796 4045 } … … 3801 4050 if (rc != SQLITE_OK) throw DBError(); 3802 4051 3803 delete [] rootNodeProperties; 3804 4052 delete rootNodeProperties; 3805 4053 int game_id = sqlite3_last_insert_rowid(db); 3806 4054 3807 // p lay through the game4055 // printf("play through the game\n"); 3808 4056 3809 4057 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); 3813 4062 int whichVar = 0; 3814 4063 stack<VarInfo> branchpoints; 3815 4064 3816 4065 while (currentN) { 4066 // printf("nn\n"); 3817 4067 bool caughtSGFError = false; 3818 4068 try { … … 3865 4115 continue; 3866 4116 } 3867 if (97 <= s[i] && s[i] <= 96+b oardsize) { // valid board coordinate?4117 if (97 <= s[i] && s[i] <= 96+bs) { // valid board coordinate? 3868 4118 propValue[propValueIndex++] = s[i]; 3869 4119 } else if (s[i] == 't') { ; // allow passes, but do not record them (we handle them a little sloppily here) … … 3889 4139 if (!propValueIndex) { // in particular, this happens if !IDrelevant 3890 4140 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(); 3892 4143 } 3893 4144 delete [] propValue; … … 3902 4153 Move m = b.undostack.top(); 3903 4154 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); 3905 4157 } else 3906 4158 if (!strcmp(ID, "AB")) { … … 3909 4161 char y = propValue[2*pp+1]-97; 3910 4162 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); 3912 4165 } 3913 4166 } else … … 3917 4170 char y = propValue[2*pp+1]-97; 3918 4171 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); 3920 4174 } 3921 4175 } else { … … 3927 4181 if (removed==' ') throw SGFError(); 3928 4182 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); 3930 4185 } 3931 4186 } … … 3934 4189 } 3935 4190 } catch (SGFError) { 3936 printf("SGF error\n");3937 4191 caughtSGFError = true; 3938 4192 } 3939 4193 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(); 3941 4196 3942 4197 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(); 3944 4200 branchpoints.push(VarInfo(currentN, new abstractBoard(b), 0)); 3945 4201 } … … 3953 4209 whichVar = branchpoints.top().i; 3954 4210 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(); 3956 4213 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(); 3958 4216 branchpoints.push(VarInfo(currentN, new abstractBoard(b), whichVar+1)); 3959 4217 } … … 3962 4220 } 3963 4221 } // 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 } 3965 4226 root = root->down; 3966 4227 pos++; 06/libkombilo/search.h
r194 r195
