Changeset 223

Show
Ignore:
Timestamp:
02/23/07 22:21:27 (1 year ago)
Author:
ug
Message:

Fixed bugs concerning databases with different board sizes.

Files:

Legend:

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

    r217 r223  
    2929    gl.start_processing(); 
    3030    directory_iterator end_itr; 
    31     // string path = "/home/ug/go/kombilo/06/libkombilo"; 
     31    string path = "/home/ug/go/kombilo/06/libkombilo"; 
    3232    // string path = "/home/ug/go/gtl/reviews"; 
    33     string path = "/home/ug/go/gogod06/2000"; 
     33    // string path = "/home/ug/go/gogod06/2000"; 
    3434    for(directory_iterator it(path); it != end_itr; ++it) { 
    3535      string n = it->string(); 
     
    5656  // ------------------- set up search pattern ---------------------------------------- 
    5757 
    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" 
    5961 
    6062  // anchor varies only in small region of board: the first 4 entries  
     
    8082  SearchOptions so; 
    8183  // so.searchInVariations = false; 
    82   so.nextMove = 2; 
     84  // so.nextMove = 2; 
    8385   
    8486  // -------------------- do pattern search -------------------------------------- 
     
    9092  // for(vector<string>::iterator it = res.begin(); it != res.end(); it++) 
    9193  //   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()); 
    9395 
    9496  // ------------------- print some statistics ------------------------------------------ 
  • 06/libkombilo/search.cpp

    r221 r223  
    3333using std::string; 
    3434using std::vector; 
     35using std::map; 
    3536using std::pair; 
    3637using std::make_pair; 
     
    962963Algo_finalpos::~Algo_finalpos() { 
    963964  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
    965966    delete data; 
    966967  } 
     
    10301031  db = DB; 
    10311032  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
    10331034    delete data; 
    10341035  } 
    1035   data = new vector<char* >; 
     1036  data = new map<int, char* >; 
    10361037  int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 
    10371038  if (rc) throw DBError(); 
    10381039  sqlite3_stmt *ppStmt=0; 
    10391040  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); 
    10411042  rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    10421043  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
    10431044  while (sqlite3_step(ppStmt) == SQLITE_ROW) { 
    10441045    // 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); 
    10461048    // printf("step1\n"); 
    10471049    char* d1 = new char[100]; 
     
    10491051    for(int i=0; i<100; i++) d1[i] = d[i]; 
    10501052    // printf("step3\n"); 
    1051     data->push_back(d1); 
     1053    // printf("insert %d %p\n", index, d1); 
     1054    data->insert(make_pair(index, d1)); 
    10521055  } 
    10531056  // printf("done\n"); 
     
    11331136    // if (progBar && !(counter % 100)) 
    11341137    //   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); 
    11421147    vector<Candidate* > *matchList = new vector<Candidate* >;; 
    11431148 
     
    12001205Algo_movelist::~Algo_movelist() { 
    12011206  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
    12041209    } 
    12051210    delete data1; 
    12061211  } 
    12071212  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
    12101215    } 
    12111216    delete data2; 
     
    13191324int Algo_movelist::readDB(sqlite3* DB) { 
    13201325  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
    13221327    delete data1; 
    13231328  } 
    1324   data1 = new vector<char* >; 
     1329  data1 = new map<int, char* >; 
    13251330  if (data1l) delete data1l; 
    1326   data1l = new vector<int >; 
     1331  data1l = new map<int, int >; 
    13271332  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
    13291334    delete data2; 
    13301335  } 
    1331   data2 = new vector<char* >; 
     1336  data2 = new map<int, char* >; 
    13321337  db = DB; 
    13331338 
     
    13371342  sqlite3_stmt *ppStmt=0; 
    13381343  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); 
    13401345  rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 
    13411346  if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 
     
    13491354      // printf("%c", (d[i] & 31)+97); 
    13501355    } 
     1356    int index = sqlite3_column_int(ppStmt, 2); 
    13511357    // 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)); 
    13541360    d = (char*)sqlite3_column_blob(ppStmt, 1); 
    13551361    d1 = new char[50]; 
     
    13571363      for(int i=0; i<50; i++) d1[i] = d[i]; 
    13581364    } 
    1359     data2->push_back(d1); 
     1365    data2->insert(make_pair(index, d1)); 
    13601366  } 
    13611367  rc = sqlite3_finalize(ppStmt); 
     
    14631469    stack<VecMC* > branchpoints; 
    14641470 
    1465     char* movel = (*data1)[index-1]; 
     1471    char* movel = (*data1)[index]; 
    14661472    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]); 
    14691475    // int nodeCtr = 0; 
    14701476    // for(int i=0; i<endMovelist/2; i++) { 
     
    14801486    // printf("\n"); 
    14811487 
    1482     char* fpC = (*data2)[index-1]; 
     1488    char* fpC = (*data2)[index]; 
    14831489 
    14841490    vector<Candidate* > *currentMatchList = gl.getCurrentCandidateList(); 
     
    39803986  PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 
    39813987 
    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) { 
    39834004    char buf[20]; 
    39844005    sprintf(buf, "sz = %d", pattern.boardsize); 
     
    39924013  int hash_result = -1; 
    39934014  // 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]); 
    39964017    if (hash_result == 1) { 
    39974018    } 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); 
    40004021    } 
    40014022  } 
     
    40034024 
    40044025    // 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]); 
    40074028      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); 
    40104031      } 
    40114032    } 
    40124033 
    40134034    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); 
    40184039    } 
    40194040  } 
  • 06/libkombilo/search.h

    r221 r223  
    245245    char* fp; 
    246246    int fpIndex; 
    247     std::vector<char* > *data; 
     247    std::map<int, char* > *data; 
    248248    int readDB(sqlite3* DB); 
    249249    int search(PatternList& patternList, GameList& gl, SearchOptions& options); 
     
    316316    std::vector<char> movelist; 
    317317    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; 
    321321}; 
    322322 
  • 06/libkombilo/sgfparser.cpp

    r222 r223  
    10061006  strcpy(t, result); 
    10071007 
    1008   delete result; 
     1008  delete [] result; 
    10091009  return t; 
    10101010}