Changeset 220

Show
Ignore:
Timestamp:
02/18/07 21:33:53 (1 year ago)
Author:
ug
Message:

Amended signature search. Small fix in GameList? destructor.

Files:

Legend:

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

    r219 r220  
    907907} 
    908908 
    909 void Algo_signature::endgame_process() throw(DBError) { 
     909char* symmetrize(char* signature, int boardsize) { 
    910910  // symmetrize signature 
    911911  char* min_signature = new char[12]; 
     
    915915    char* next = new char[12]; 
    916916    for(int i=0; i<6; i++) { 
    917       if (signature[2*i] == 't') next[2*i] = 't'; 
    918       else if (signature[2*i] == '?') next[2*i] = '?'; 
    919       else next[2*i] = Pattern::flipsX(f, signature[2*i]-'a', signature[2*i+1]-'a', boardsize-1, boardsize-1)+'a'
    920       if (signature[2*i+1] == 't') next[2*i+1] = 't'; 
    921       else if (signature[2*i+1] == '?') next[2*i+1] = '?'; 
    922       else next[2*i+1] = Pattern::flipsY(f, signature[2*i]-'a', signature[2*i+1]-'a', boardsize-1, boardsize-1)+'a'
     917      if ('a' <= signature[2*i] && signature[2*i] <= 's') 
     918        next[2*i] = Pattern::flipsX(f, signature[2*i]-'a', signature[2*i+1]-'a', boardsize-1, boardsize-1)+'a'; 
     919      else next[2*i] = signature[2*i]
     920      if ('a' <= signature[2*i+1] && signature[2*i+1] <= 's') 
     921        next[2*i+1] = Pattern::flipsY(f, signature[2*i]-'a', signature[2*i+1]-'a', boardsize-1, boardsize-1)+'a'; 
     922      else next[2*i+1] = signature[2*i+1]
    923923    } 
    924924    // if next < min_signature, then swap 
     
    934934    delete [] next; 
    935935  } 
     936  return min_signature; 
     937} 
     938 
     939void Algo_signature::endgame_process() throw(DBError) { 
     940  char* min_signature = symmetrize(signature, boardsize); 
    936941  delete [] signature; 
    937942  char sql[100]; 
     
    36123617  if (db) sqlite3_close(db); 
    36133618  db = 0; 
     3619  if (algo_db1) sqlite3_close(algo_db1); 
     3620  algo_db1 = 0; 
     3621  if (algo_db2) sqlite3_close(algo_db2); 
     3622  algo_db2 = 0; 
    36143623  // printf("leave ~GameList\n"); 
    36153624} 
     
    38023811} 
    38033812 
    3804 void GameList::sigsearch(char* sig) throw(DBError) { 
     3813void GameList::sigsearch(char* sig, int boardsize) throw(DBError) { 
    38053814  if (start_sorted() == 0) {  
     3815    char* symmetrized_sig = 0; 
     3816    if (boardsize) symmetrized_sig = symmetrize(sig, boardsize); 
     3817    // char ssig[13]; 
     3818    // for(int i=0; i<12; i++) ssig[i] = symmetrized_sig[i]; 
     3819    // ssig[12] = 0; 
     3820    // printf("ssig: %s\n", ssig); 
    38063821    string query = "select id from algo_signature_19 where signature like ? order by id"; 
    38073822    // int rc = sqlite3_exec(db, query.c_str(), sigs_callback, this, 0); 
     
    38093824    int rc = sqlite3_prepare(db, query.c_str(), -1, &ppStmt, 0); 
    38103825    if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 
    3811     rc = sqlite3_bind_blob(ppStmt, 1, sig, 12, SQLITE_TRANSIENT); 
     3826    if (boardsize) rc = sqlite3_bind_blob(ppStmt, 1, symmetrized_sig, 12, SQLITE_TRANSIENT); 
     3827    else rc = sqlite3_bind_blob(ppStmt, 1, sig, 12, SQLITE_TRANSIENT); 
    38123828    if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 
    38133829    do { 
     
    38193835    } while (rc == SQLITE_ROW); 
    38203836    rc = sqlite3_finalize(ppStmt); 
     3837    if (symmetrized_sig) delete [] symmetrized_sig; 
    38213838    if (rc != SQLITE_OK) throw DBError(); 
    38223839 
  • 06/libkombilo/search.h

    r218 r220  
    604604 
    605605    // ------- signature search --------------------------------------------------- 
    606     void sigsearch(char* sig) throw(DBError); 
     606    // if boardsize != 0 in sigsearch, then the signature is "symmetrized" with respect 
     607    // to boardsize 
     608    void sigsearch(char* sig, int boardsize) throw(DBError); 
    607609    std::string getSignature(int i) throw(DBError); 
    608610 
  • 06/libkombilo/testsearch.py

    r217 r220  
    6868#     print 'Player %d: %s' % (i, gl.plEntry(i)) 
    6969 
    70 # for sig in ['cfcgjbbeckjc', 'aaaaaaaaaaaa', 'dfcnfmepgkjo', 'dfcn________', 'dfcn%']: 
    71 #     # SQL-wildcards are allowed: _ for a single character, % for an arbitrary number of characters 
    72 #     gl.reset() 
    73 #     gl.sigsearch(sig
    74 #     print gl.size(), 'games with signature', sig 
     70for sig in ['cfcgjbbeckjc', 'qfqgjbreqkjc', '', 'aaaaaaaaaaaa', 'dfcnfmepgkjo', 'dfcn________', 'dfcn%']: 
     71    # SQL-wildcards are allowed: _ for a single character, % for an arbitrary number of characters 
     72    gl.reset() 
     73    gl.sigsearch(sig, 19
     74    print gl.size(), 'games with signature', sig 
    7575# gl.reset() 
    7676# print gl.currentEntryAsString(200) 
    7777# print 'signature of game 200: ', gl.getSignature(200) 
    7878 
    79