Changeset 220
- Timestamp:
- 02/18/07 21:33:53 (1 year ago)
- Files:
-
- 06/libkombilo/search.cpp (modified) (7 diffs)
- 06/libkombilo/search.h (modified) (1 diff)
- 06/libkombilo/testsearch.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/search.cpp
r219 r220 907 907 } 908 908 909 void Algo_signature::endgame_process() throw(DBError) {909 char* symmetrize(char* signature, int boardsize) { 910 910 // symmetrize signature 911 911 char* min_signature = new char[12]; … … 915 915 char* next = new char[12]; 916 916 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]; 923 923 } 924 924 // if next < min_signature, then swap … … 934 934 delete [] next; 935 935 } 936 return min_signature; 937 } 938 939 void Algo_signature::endgame_process() throw(DBError) { 940 char* min_signature = symmetrize(signature, boardsize); 936 941 delete [] signature; 937 942 char sql[100]; … … 3612 3617 if (db) sqlite3_close(db); 3613 3618 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; 3614 3623 // printf("leave ~GameList\n"); 3615 3624 } … … 3802 3811 } 3803 3812 3804 void GameList::sigsearch(char* sig ) throw(DBError) {3813 void GameList::sigsearch(char* sig, int boardsize) throw(DBError) { 3805 3814 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); 3806 3821 string query = "select id from algo_signature_19 where signature like ? order by id"; 3807 3822 // int rc = sqlite3_exec(db, query.c_str(), sigs_callback, this, 0); … … 3809 3824 int rc = sqlite3_prepare(db, query.c_str(), -1, &ppStmt, 0); 3810 3825 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); 3812 3828 if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 3813 3829 do { … … 3819 3835 } while (rc == SQLITE_ROW); 3820 3836 rc = sqlite3_finalize(ppStmt); 3837 if (symmetrized_sig) delete [] symmetrized_sig; 3821 3838 if (rc != SQLITE_OK) throw DBError(); 3822 3839 06/libkombilo/search.h
r218 r220 604 604 605 605 // ------- 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); 607 609 std::string getSignature(int i) throw(DBError); 608 610 06/libkombilo/testsearch.py
r217 r220 68 68 # print 'Player %d: %s' % (i, gl.plEntry(i)) 69 69 70 # for sig in ['cfcgjbbeckjc', 'aaaaaaaaaaaa', 'dfcnfmepgkjo', 'dfcn________', 'dfcn%']:71 ## SQL-wildcards are allowed: _ for a single character, % for an arbitrary number of characters72 #gl.reset()73 # gl.sigsearch(sig)74 #print gl.size(), 'games with signature', sig70 for 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 75 75 # gl.reset() 76 76 # print gl.currentEntryAsString(200) 77 77 # print 'signature of game 200: ', gl.getSignature(200) 78 78 79
