Changeset 223
- Timestamp:
- 02/23/07 22:21:27 (1 year ago)
- Files:
-
- 06/libkombilo/cpptest.cpp (modified) (4 diffs)
- 06/libkombilo/search.cpp (modified) (15 diffs)
- 06/libkombilo/search.h (modified) (2 diffs)
- 06/libkombilo/sgfparser.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/cpptest.cpp
r217 r223 29 29 gl.start_processing(); 30 30 directory_iterator end_itr; 31 //string path = "/home/ug/go/kombilo/06/libkombilo";31 string path = "/home/ug/go/kombilo/06/libkombilo"; 32 32 // string path = "/home/ug/go/gtl/reviews"; 33 string path = "/home/ug/go/gogod06/2000";33 // string path = "/home/ug/go/gogod06/2000"; 34 34 for(directory_iterator it(path); it != end_itr; ++it) { 35 35 string n = it->string(); … … 56 56 // ------------------- set up search pattern ---------------------------------------- 57 57 58 Pattern p(2,2,4,4, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>()); // "fixed anchor" 58 Pattern p(CENTER_PATTERN, 13, 2, 2, ".XXO"); 59 60 // Pattern p(2,2,4,4, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>()); // "fixed anchor" 59 61 60 62 // anchor varies only in small region of board: the first 4 entries … … 80 82 SearchOptions so; 81 83 // so.searchInVariations = false; 82 so.nextMove = 2;84 // so.nextMove = 2; 83 85 84 86 // -------------------- do pattern search -------------------------------------- … … 90 92 // for(vector<string>::iterator it = res.begin(); it != res.end(); it++) 91 93 // printf("%s\n", it->c_str()); 92 //for(int i=0; i<gl.size(); i++) printf("%s\n", gl.currentEntryAsString(i).c_str());94 for(int i=0; i<gl.size(); i++) printf("%s\n", gl.currentEntryAsString(i).c_str()); 93 95 94 96 // ------------------- print some statistics ------------------------------------------ 06/libkombilo/search.cpp
r221 r223 33 33 using std::string; 34 34 using std::vector; 35 using std::map; 35 36 using std::pair; 36 37 using std::make_pair; … … 962 963 Algo_finalpos::~Algo_finalpos() { 963 964 if (data) { 964 for( vector<char* >::iterator it = data->begin(); it != data->end(); it++) delete [] *it;965 for(map<int, char* >::iterator it = data->begin(); it != data->end(); it++) delete [] it->second; 965 966 delete data; 966 967 } … … 1030 1031 db = DB; 1031 1032 if (data) { 1032 for( vector<char* >::iterator it = data->begin(); it != data->end(); it++) delete [] *it;1033 for(map<int, char* >::iterator it = data->begin(); it != data->end(); it++) delete [] it->second; 1033 1034 delete data; 1034 1035 } 1035 data = new vector<char* >;1036 data = new map<int, char* >; 1036 1037 int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 1037 1038 if (rc) throw DBError(); 1038 1039 sqlite3_stmt *ppStmt=0; 1039 1040 char sql[100]; 1040 sprintf(sql, "select data from algo_finalpos_%d order by id", boardsize);1041 sprintf(sql, "select id, data from algo_finalpos_%d order by id", boardsize); 1041 1042 rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1042 1043 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 1043 1044 while (sqlite3_step(ppStmt) == SQLITE_ROW) { 1044 1045 // printf("step0\n"); 1045 char* d = (char*)sqlite3_column_blob(ppStmt, 0); 1046 int index = sqlite3_column_int(ppStmt, 0); 1047 char* d = (char*)sqlite3_column_blob(ppStmt, 1); 1046 1048 // printf("step1\n"); 1047 1049 char* d1 = new char[100]; … … 1049 1051 for(int i=0; i<100; i++) d1[i] = d[i]; 1050 1052 // printf("step3\n"); 1051 data->push_back(d1); 1053 // printf("insert %d %p\n", index, d1); 1054 data->insert(make_pair(index, d1)); 1052 1055 } 1053 1056 // printf("done\n"); … … 1133 1136 // if (progBar && !(counter % 100)) 1134 1137 // progBar.redraw((progEnd-progStart)*counter/len(gl.current) + progStart); 1135 // if (index > data->size()) { 1136 // printf("index error\n"); //FIXME 1137 // return; 1138 // } 1139 // printf("index %d %d\n", index, data->size()); 1140 1141 char* finalpos = (*data)[index-1]; 1138 1139 map<int, char* >::iterator it = data->find(index); 1140 if (it == data->end()) { 1141 // printf("skip\n"); 1142 index = gl.next(); 1143 continue; 1144 } 1145 char* finalpos = it->second; 1146 // printf("index %d, %p\n", index, finalpos); 1142 1147 vector<Candidate* > *matchList = new vector<Candidate* >;; 1143 1148 … … 1200 1205 Algo_movelist::~Algo_movelist() { 1201 1206 if (data1) { 1202 for( vector<char* >::iterator it = data1->begin(); it != data1->end(); it++) {1203 delete [] *it;1207 for(map<int, char* >::iterator it = data1->begin(); it != data1->end(); it++) { 1208 delete [] it->second; 1204 1209 } 1205 1210 delete data1; 1206 1211 } 1207 1212 if (data2) { 1208 for( vector<char* >::iterator it = data2->begin(); it != data2->end(); it++) {1209 delete [] *it;1213 for(map<int, char* >::iterator it = data2->begin(); it != data2->end(); it++) { 1214 delete [] it->second; 1210 1215 } 1211 1216 delete data2; … … 1319 1324 int Algo_movelist::readDB(sqlite3* DB) { 1320 1325 if (data1) { 1321 for( vector<char* >::iterator it = data1->begin(); it != data1->end(); it++) delete [] *it;1326 for(map<int, char* >::iterator it = data1->begin(); it != data1->end(); it++) delete [] it->second; 1322 1327 delete data1; 1323 1328 } 1324 data1 = new vector<char* >;1329 data1 = new map<int, char* >; 1325 1330 if (data1l) delete data1l; 1326 data1l = new vector<int >;1331 data1l = new map<int, int >; 1327 1332 if (data2) { 1328 for( vector<char* >::iterator it = data2->begin(); it != data2->end(); it++) delete [] *it;1333 for(map<int, char* >::iterator it = data2->begin(); it != data2->end(); it++) delete [] it->second; 1329 1334 delete data2; 1330 1335 } 1331 data2 = new vector<char* >;1336 data2 = new map<int, char* >; 1332 1337 db = DB; 1333 1338 … … 1337 1342 sqlite3_stmt *ppStmt=0; 1338 1343 char sql[100]; 1339 sprintf(sql, "select movelist,fpC from algo_movelist_%d order by id", boardsize);1344 sprintf(sql, "select movelist,fpC,id from algo_movelist_%d order by id", boardsize); 1340 1345 rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1341 1346 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) … … 1349 1354 // printf("%c", (d[i] & 31)+97); 1350 1355 } 1356 int index = sqlite3_column_int(ppStmt, 2); 1351 1357 // printf("\n"); 1352 data1-> push_back(d1);1353 data1l-> push_back(l);1358 data1->insert(make_pair(index, d1)); 1359 data1l->insert(make_pair(index, l)); 1354 1360 d = (char*)sqlite3_column_blob(ppStmt, 1); 1355 1361 d1 = new char[50]; … … 1357 1363 for(int i=0; i<50; i++) d1[i] = d[i]; 1358 1364 } 1359 data2-> push_back(d1);1365 data2->insert(make_pair(index, d1)); 1360 1366 } 1361 1367 rc = sqlite3_finalize(ppStmt); … … 1463 1469 stack<VecMC* > branchpoints; 1464 1470 1465 char* movel = (*data1)[index -1];1471 char* movel = (*data1)[index]; 1466 1472 int movelistIndex = 0; 1467 int endMovelist = (*data1l)[index -1];1468 // printf("len movelist: %d\n", (*data1l)[index -1]);1473 int endMovelist = (*data1l)[index]; 1474 // printf("len movelist: %d\n", (*data1l)[index]); 1469 1475 // int nodeCtr = 0; 1470 1476 // for(int i=0; i<endMovelist/2; i++) { … … 1480 1486 // printf("\n"); 1481 1487 1482 char* fpC = (*data2)[index -1];1488 char* fpC = (*data2)[index]; 1483 1489 1484 1490 vector<Candidate* > *currentMatchList = gl.getCurrentCandidateList(); … … 3980 3986 PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 3981 3987 3982 if (boardsizes.size() != 1 || boardsizes[0] != pattern.boardsize) { 3988 vector<int>::iterator it = boardsizes.begin(); 3989 int bs_index = 0; 3990 while (it != boardsizes.end() && *it != pattern.boardsize) { 3991 bs_index++; 3992 it++; 3993 } 3994 if (it == boardsizes.end()) { 3995 delete searchOptions; 3996 if (oldList) delete oldList; 3997 oldList = 0; 3998 if (currentList) delete currentList; 3999 currentList = 0; 4000 return; 4001 } 4002 4003 if (boardsizes.size() != 1) { 3983 4004 char buf[20]; 3984 4005 sprintf(buf, "sz = %d", pattern.boardsize); … … 3992 4013 int hash_result = -1; 3993 4014 // FULL BOARD PATTERN? 3994 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX == pattern.boardsize && pattern.sizeY == pattern.boardsize && algo_ps[algo_hash_full ]) {3995 hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full ])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_full]);4015 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX == pattern.boardsize && pattern.sizeY == pattern.boardsize && algo_ps[algo_hash_full+20*bs_index]) { 4016 hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_full+20*bs_index]); 3996 4017 if (hash_result == 1) { 3997 4018 } else if (hash_result == 0) { 3998 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist ])3999 algo_ps[algo_movelist ]->search(pl, *this, *searchOptions);4019 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4020 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 4000 4021 } 4001 4022 } … … 4003 4024 4004 4025 // CORNER PATTERN? 4005 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX >= 7 && pattern.sizeY >= 7 && algo_ps[algo_hash_corner ]) {4006 hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner ])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner]);4026 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX >= 7 && pattern.sizeY >= 7 && algo_ps[algo_hash_corner+20*bs_index]) { 4027 hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner+20*bs_index]); 4007 4028 if (hash_result == 0) { 4008 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist ])4009 algo_ps[algo_movelist ]->search(pl, *this, *searchOptions);4029 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4030 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 4010 4031 } 4011 4032 } 4012 4033 4013 4034 if (hash_result == -1) { 4014 if (searchOptions->algos & ALGO_FINALPOS && algo_ps[algo_finalpos ])4015 algo_ps[algo_finalpos ]->search(pl, *this, *searchOptions);4016 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist ])4017 algo_ps[algo_movelist ]->search(pl, *this, *searchOptions);4035 if (searchOptions->algos & ALGO_FINALPOS && algo_ps[algo_finalpos+20*bs_index]) 4036 algo_ps[algo_finalpos+20*bs_index]->search(pl, *this, *searchOptions); 4037 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 4038 algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 4018 4039 } 4019 4040 } 06/libkombilo/search.h
r221 r223 245 245 char* fp; 246 246 int fpIndex; 247 std:: vector<char* > *data;247 std::map<int, char* > *data; 248 248 int readDB(sqlite3* DB); 249 249 int search(PatternList& patternList, GameList& gl, SearchOptions& options); … … 316 316 std::vector<char> movelist; 317 317 char* fpC; 318 std:: vector<char* > *data1;319 std:: vector<char* > *data2;320 std:: vector<int> *data1l;318 std::map<int, char* > *data1; 319 std::map<int, char* > *data2; 320 std::map<int, int> *data1l; 321 321 }; 322 322 06/libkombilo/sgfparser.cpp
r222 r223 1006 1006 strcpy(t, result); 1007 1007 1008 delete result;1008 delete [] result; 1009 1009 return t; 1010 1010 }
