Changeset 191
- Timestamp:
- 10/01/06 00:04:05 (2 years ago)
- Files:
-
- 06/libkombilo/abstractboard.cc (modified) (1 diff)
- 06/libkombilo/abstractboard.h (modified) (5 diffs)
- 06/libkombilo/cpptest.cc (modified) (1 diff)
- 06/libkombilo/libkombilo.i (modified) (1 diff)
- 06/libkombilo/search.cc (modified) (28 diffs)
- 06/libkombilo/search.h (modified) (21 diffs)
- 06/libkombilo/sgfparser.cc (modified) (2 diffs)
- 06/libkombilo/sgfparser.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/abstractboard.cc
r188 r191 23 23 24 24 #include "abstractboard.h" 25 using std::stack; 26 using std::vector; 25 27 26 28 BoardError::BoardError() {} 06/libkombilo/abstractboard.h
r188 r191 28 28 #include <utility> 29 29 #include <stack> 30 using namespace std;31 30 32 31 const int DEBUG_ABSTRACTBOARD = 0; … … 37 36 }; 38 37 39 typedef pair<char,char> p_cc;38 typedef std::pair<char,char> p_cc; 40 39 41 40 … … 58 57 Move& operator=(const Move& m); 59 58 60 vector<pair<char,char>>* captures;59 std::vector<p_cc >* captures; 61 60 }; 62 61 … … 66 65 int boardsize; 67 66 char* status; 68 st ack<Move> undostack;67 std::stack<Move> undostack; 69 68 70 69 abstractBoard(int bs = 19) throw(BoardError); … … 84 83 private: 85 84 int* neighbors(int x, int y); 86 vector<pair<char,char>>* legal(int x, int y, char color);87 vector<pair<char,char>>* hasNoLibExcP(int x1, int y1, int exc=-1);85 std::vector<p_cc >* legal(int x, int y, char color); 86 std::vector<p_cc >* hasNoLibExcP(int x1, int y1, int exc=-1); 88 87 char invert(char); 89 88 }; 06/libkombilo/cpptest.cc
r188 r191 4 4 #include "search.h" 5 5 6 using namespace boost::filesystem; 6 using namespace std; 7 using boost::filesystem::directory_iterator; 7 8 8 9 int main(int argc, char** argv) { 06/libkombilo/libkombilo.i
r183 r191 16 16 %include "abstractboard.h" 17 17 %include "search.h" 18 %template(vectorMNC) vector<MoveNC>;18 %template(vectorMNC) std::vector<MoveNC>; 19 19 20 20 06/libkombilo/search.cc
r190 r191 28 28 #include <string> 29 29 #include <cstring> 30 31 using std::min; 32 using std::max; 33 using std::string; 34 using std::vector; 35 using std::pair; 36 using std::make_pair; 37 using std::stack; 30 38 31 39 PatternError::PatternError() {} … … 93 101 } 94 102 95 void Symmetries::set(char i, char j, char k, char l, char cs) {103 void Symmetries::set(char i, char j, char k, char l, char cs) throw(PatternError) { 96 104 if (0 <= i && i < sizeX && 0 <= j && j < sizeY) { 97 105 dataX[i + j*sizeX] = k; … … 99 107 dataCS[i + j*sizeX] = cs; 100 108 } 101 // else printf("Error Symmetries1\n"); // FIXME102 } 103 104 char Symmetries::getX(char i, char j) {109 else throw PatternError(); 110 } 111 112 char Symmetries::getX(char i, char j) throw(PatternError) { 105 113 if (0 <= i && i < sizeX && 0 <= j && j < sizeY) return dataX[i + j*sizeX]; 106 else printf("Error Symmetries2\n"); // FIXME114 else throw PatternError(); 107 115 return -1; 108 116 } 109 117 110 char Symmetries::getY(char i, char j) {118 char Symmetries::getY(char i, char j) throw(PatternError) { 111 119 if (0 <= i && i < sizeX && 0 <= j && j < sizeY) return dataY[i + j*sizeX]; 112 else printf("Error Symmetries3\n"); // FIXME120 else throw PatternError(); 113 121 return -1; 114 122 } 115 123 116 char Symmetries::getCS(char i, char j) {124 char Symmetries::getCS(char i, char j) throw(PatternError) { 117 125 if (0 <= i && i < sizeX && 0 <= j && j < sizeY) return dataCS[i + j*sizeX]; 118 else printf("Error Symmetries4\n"); // FIXME126 else throw PatternError(); 119 127 return -1; 120 128 } 121 129 122 char Symmetries::has_key(char i, char j) {130 char Symmetries::has_key(char i, char j) throw(PatternError) { 123 131 if (0 <= i && i < sizeX && 0 <= j && j < sizeY) { 124 132 if (dataX[i + j*sizeX] == -1) return 0; 125 133 else return 1; 126 134 } 127 else printf("Error Symmetries5\n"); // FIXME135 else throw PatternError(); 128 136 return 0; 129 137 } … … 363 371 } 364 372 365 void Pattern::printPattern() { 366 printf("%d, %d, %d, %d\n", left, right, top, bottom); 367 printf("%d, %d\n", sizeX, sizeY); 373 string Pattern::printPattern() { 374 string result; 375 char buf[40]; 376 sprintf(buf, "area: %d, %d, %d, %d\nsize: %d, %d\n", left, right, top, bottom, sizeX, sizeY); 377 result += buf; 368 378 for(int i=0; i<sizeY; i++) { 369 379 for(int j=0; j<sizeX; j++) { 370 if (initialPos[i*sizeX + j] == 'X' ) printf("X");371 else if (initialPos[i*sizeX + j] == 'O') printf("O");372 else printf(".");373 }374 printf("\n");375 }376 printf("\n");380 if (initialPos[i*sizeX + j] == 'X' || initialPos[i*sizeX + j] == 'O' || initialPos[i*sizeX + j] == 'x' || initialPos[i*sizeX + j] == 'x' || initialPos[i*sizeX+j] == '*') result += initialPos[i*sizeX+j]; 381 else result += '.'; 382 } 383 result += "\n"; 384 } 385 result += "\n"; 386 return result; 377 387 } 378 388 … … 424 434 } 425 435 426 PatternList::PatternList(const PatternList& pl) {427 printf("OUCH. Copy constructor for PatternList needed.\n"); // FIXME428 }429 430 PatternList& PatternList::operator=(const PatternList& pl) {431 printf("OUCH. operator= for PatternList needed.\n"); // FIXME432 return *this;433 }434 435 436 char PatternList::invertColor(char co) { 436 437 if (co == 'X') return 'O'; … … 631 632 632 633 char* PatternList::updateContinuations(int index, int x, int y, char co, bool tenuki, char winner) { 633 // char* re = new char[3];634 // re[0] = 0;635 // re[1] = 0;636 // re[2] = 0;637 // return re;638 639 634 char xx; 640 635 char yy; … … 719 714 sqlite3_stmt *ppStmt=0; 720 715 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 721 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?)716 if (rc != SQLITE_OK || ppStmt==0) return rc; 722 717 rc = sqlite3_bind_int(ppStmt, 1, id); 723 718 if (rc != SQLITE_OK) return rc; … … 734 729 sqlite3_stmt *ppStmt=0; 735 730 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 736 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?)731 if (rc != SQLITE_OK || ppStmt==0) return rc; 737 732 rc = sqlite3_bind_int(ppStmt, 1, id); 738 733 if (rc != SQLITE_OK) return rc; … … 849 844 } 850 845 851 void Algo_signature::endgame_process() {846 void Algo_signature::endgame_process() throw(DBError) { 852 847 // symmetrize signature 853 848 char* min_signature = new char[12]; … … 875 870 } 876 871 delete [] signature; 877 dbinsert1blob(db, "insert into algo_signature (id, signature) values (?,?);", gid, min_signature, 12);872 if (dbinsert1blob(db, "insert into algo_signature (id, signature) values (?,?);", gid, min_signature, 12)) throw DBError(); 878 873 // for(int i=0; i<12; i++) printf("%c", min_signature[i]); printf("\n"); 879 874 delete [] min_signature; … … 940 935 } 941 936 942 void Algo_finalpos::endgame_process() {943 dbinsert1blob(db, "insert into algo_finalpos (id, data) values (?,?);", gid, fp, 100);937 void Algo_finalpos::endgame_process() throw(DBError) { 938 if (dbinsert1blob(db, "insert into algo_finalpos (id, data) values (?,?);", gid, fp, 100)) throw DBError(); 944 939 delete [] fp; 945 940 } … … 1213 1208 } 1214 1209 1215 void Algo_movelist::endgame_process() {1210 void Algo_movelist::endgame_process() throw(DBError) { 1216 1211 char* ml = new char[movelist.size()]; 1217 1212 int mlIndex = 0; … … 1219 1214 ml[mlIndex++] = *it; 1220 1215 } 1221 dbinsert2blobs(db, "insert into algo_movelist (id, movelist, fpC) values (?, ?, ?);", gid, ml, mlIndex, fpC, 50);1216 if (dbinsert2blobs(db, "insert into algo_movelist (id, movelist, fpC) values (?, ?, ?);", gid, ml, mlIndex, fpC, 50)) throw DBError(); 1222 1217 delete [] ml; 1223 1218 delete [] fpC; … … 1672 1667 } 1673 1668 1674 1675 const long long Algo_hash::hashCodes[] = { 1669 #ifdef __BORLANDC__ 1670 const hashtype Algo_hash::hashCodes[] = { 1671 1448047776469843i64 , 23745670021858756i64 , 2503503679898819i64 , 1672 20893061577159209i64 , 10807838381971450i64 , 2362252468869198i64 , 1673 24259008893265414i64 , 12770534669822463i64 , 6243872632612083i64 , 1674 9878602848666731i64 , 15403460661141300i64 , 23328125617276831i64 , 1675 24399618481479321i64 , 6553504962910284i64 , 1670313139184804i64 , 1676 12980312942597170i64 , 20479559860862969i64 , 9622188310955879i64 , 1677 240315181816498i64 , 15806748501866401i64 , 11025185739521454i64 , 1678 9892014082139049i64 , 24468178939325513i64 , 18336761931886570i64 , 1679 17607110247268341i64 , 1659968630984898i64 , 15644176636883129i64 , 1680 21288430710467667i64 , 21718647773405600i64 , 8449573198599383i64 , 1681 12949198458251018i64 , 13260609204816340i64 , 15942818511406502i64 , 1682 19422389391992560i64 , 2306873372585698i64 , 13245768415868578i64 , 1683 3527685889767840i64 , 16821792770065498i64 , 14659578113224043i64 , 1684 8882299950073676i64 , 7855747638699870i64 , 11443553816792995i64 , 1685 10278034782711378i64 , 9888977721917330i64 , 8622555585025384i64 , 1686 20622776792089008i64 , 6447699412562541i64 , 21593237574254863i64 , 1687 4100056509197325i64 , 8358405560798101i64 , 24120904895822569i64 , 1688 21004758159739407i64 , 4380824971205155i64 , 23810250238005035i64 , 1689 11573868012372637i64 , 21740007761325076i64 , 20569500166060069i64 , 1690 23367084743140030i64 , 832128940274250i64 , 3863567854976796i64 , 1691 8401188629788306i64 , 20293444021869434i64 , 12476938100997420i64 , 1692 5997141871489394i64 , 777596196611050i64 , 8407423122275781i64 , 1693 23742268390341663i64 , 6606677504119583i64 , 17099083579458611i64 , 1694 128040681345920i64 , 7441253945309846i64 , 17672412151152227i64 , 1695 14657002484427869i64 , 3764334613856311i64 , 7399928989161192i64 , 1696 24730167942169592i64 , 13814924480574978i64 , 5810810907567287i64 , 1697 7008927747711241i64 , 3714629224790215i64 , 9946435535599731i64 , 1698 20057491299504334i64 , 15866852457019228i64 , 123155262761331i64 , 1699 1315783062254243i64 , 24497766846727950i64 , 12902532251391440i64 , 1700 16788431106050494i64 , 15993209359043506i64 , 6163570598235227i64 , 1701 23479274902645580i64 , 12086295521073246i64 , 14074331278381816i64 , 1702 1049820141442769i64 , 5160957003350972i64 , 24302799572195320i64 , 1703 23881606652035662i64 , 23969818184919245i64 , 19374430422494128i64 , 1704 9346353622623467i64 , 13646698673919768i64 , 20787456987251805i64 , 1705 19834903548127921i64 , 8194151691638546i64 , 7687885124853709i64 , 1706 4843137186034754i64 , 23141719256229263i64 , 5528755394284040i64 , 1707 22362536622784133i64 , 7624654257445620i64 , 8792845080211956i64 , 1708 24991012676161170i64 , 5382030845010972i64 , 1942150054817210i64 , 1709 1024267612932772i64 , 14257279792025309i64 , 11127353401828247i64 , 1710 4123063511789286i64 , 363215666444395i64 , 15523634951795520i64 , 1711 21114031740764324i64 , 12549698630972549i64 , 7906682572409157i64 , 1712 9682658163949194i64 , 14445831019902887i64 , 19796086007848283i64 , 1713 25041651202294181i64 , 434144873391024i64 , 24468825775827696i64 , 1714 16436890395501393i64 , 16373785289815135i64 , 16626551488832360i64 , 1715 7748715007439309i64 , 22731617567631698i64 , 14232800365889972i64 , 1716 10951727445457549i64 , 8041373240290953i64 , 24930514145406896i64 , 1717 9591184974667554i64 , 24880672410562956i64 , 23221721160805093i64 , 1718 20593543181655919i64 , 23599230930155014i64 , 15520097083998302i64 , 1719 14424914931817466i64 , 7073972177203460i64 , 16674214483955582i64 , 1720 4557916889838393i64 , 14520120252661131i64 , 2948253205366287i64 , 1721 18549806070390636i64 , 10409566723123418i64 , 18398906015238963i64 , 1722 21169009649313417i64 , 18391044531337716i64 , 2911838512392375i64 , 1723 13771057876708721i64 , 11955633853535396i64 , 18911960208175147i64 , 1724 1483143365895487i64 , 5864164841327281i64 , 16798674080914657i64 , 1725 21169543712647072i64 , 2554895121282201i64 , 12465286616181485i64 , 1726 5756888636558955i64 , 2597276631190750i64 , 2560624395830604i64 , 1727 20296901708171088i64 , 14642976680682096i64 , 12194169777111940i64 , 1728 938262584370639i64 , 7206443811292574i64 , 501111636607822i64 , 1729 5705951146039127i64 , 19098237626875269i64 , 5726006303511723i64 , 1730 5717532750720198i64 , 4848344546021481i64 , 7407311808156422i64 , 1731 2061821731974308i64 , 8556380079387133i64 , 13575103943220600i64 , 1732 10594365938844562i64 , 19966653780019989i64 , 24412404083453688i64 , 1733 8019373982039936i64 , 7753495706295280i64 , 838015840877266i64 , 1734 5235642127051968i64 , 10225916255867901i64 , 14975561937408701i64 , 1735 4914762527221109i64 , 16273933213731410i64 , 25240707945233645i64 , 1736 6477894775523777i64 , 16128190602024745i64 , 12452291569329611i64 , 1737 51030855211419i64 , 1848783942303739i64 , 2537297571305471i64 , 1738 24811709277564335i64 , 23354767332363093i64 , 11338712562024830i64 , 1739 10845782284945582i64 , 20710115514013598i64 , 19611282767915684i64 , 1740 11160258605900113i64 , 17875966449141620i64 , 8400967803093668i64 , 1741 6871997953834029i64 , 13914235659320051i64 , 8949576634650339i64 , 1742 2143755776666584i64 , 13309009078638265i64 , 17871461210902733i64 , 1743 11987276750060947i64 , 19212042799964345i64 , 9684310155516547i64 , 1744 1307858104678668i64 , 8369225045337652i64 , 11470364009363081i64 , 1745 10726698770860164i64 , 22857364846703600i64 , 25284735055035435i64 , 1746 19224377054148393i64 , 16403807100295998i64 , 4653376186522389i64 , 1747 15242640882406966i64 , 15315275662931969i64 , 11642086728644568i64 , 1748 12158439227609947i64 , 5366950703441186i64 , 21989897136444615i64 , 1749 21241101455718813i64 , 1591417368086590i64 , 14579493634035095i64 , 1750 23329624772309429i64 , 4022767503269837i64 , 12858990365780377i64 , 1751 1546772101519453i64 , 23839228242060485i64 , 3152020333001361i64 , 1752 7700997223270546i64 , 7886359803633970i64 , 18794372628879385i64 , 1753 22159114735365084i64 , 7999390508114986i64 , 17413096555746886i64 , 1754 9385231705999634i64 , 15875377080359488i64 , 4319895571584052i64 , 1755 15831501864738265i64 , 23927036136254152i64 , 9023165779396619i64 , 1756 6131245054225200i64 , 20314359892927215i64 , 1896686091879468i64 , 1757 14130616725563771i64 , 22653904323575475i64 , 9831497463521490i64 , 1758 13110057076369419i64 , 5902087517632052i64 , 23714067728868348i64 , 1759 10422641883492326i64 , 10327276345146850i64 , 795518417987648i64 , 1760 25452954487907785i64 , 3500196309207718i64 , 14513995844064906i64 , 1761 7844549909962914i64 , 9407804562184273i64 , 15229768031797498i64 , 1762 14111656085687927i64 , 16834184600349678i64 , 7291182384885469i64 , 1763 17771577974633552i64 , 21586473553657942i64 , 18166326806718423i64 , 1764 10928317030329388i64 , 13135712137024532i64 , 12947681282864548i64 , 1765 21220312239923983i64 , 9606249244876101i64 , 4653965165819933i64 , 1766 5039148287631156i64 , 3987726544496362i64 , 11235885894214833i64 , 1767 3549024987193191i64 , 6369560450327424i64 , 5296536600431238i64 , 1768 10833371878822587i64 , 5746338282416722i64 , 20335144029844343i64 , 1769 14857534135172842i64 , 13933887642921338i64 , 3610489245941154i64 , 1770 7780064458218242i64 , 18217608762631328i64 , 4861734558486078i64 , 1771 19138089389909524i64 , 162404484845663i64 , 6326150309736266i64 , 1772 5691634479075905i64 , 14377989390160001i64 , 7788436404648140i64 , 1773 20312143630017606i64 , 6781467023516504i64 , 7265384191721189i64 , 1774 13990392558924592i64 , 4811546322556989i64 , 3891404257596968i64 , 1775 19222546653408634i64 , 9733466771346453i64 , 20011679489309705i64 , 1776 11556921572925005i64 , 13429005557512149i64 , 16680841455593148i64 , 1777 394589115298971i64 , 22224576785554448i64 , 18262625753524808i64 , 1778 20893780129453860i64 , 25064972830160559i64 , 241970110039610i64 , 1779 7452533933839720i64 , 10726026396546933i64 , 17312051917081899i64 , 1780 17281553837379637i64 , 24008819488103387i64 , 5193878516496164i64 , 1781 21529615734706496i64 , 22844915602846365i64 , 17118246686087168i64 , 1782 6560869056902581i64 , 10553021967047717i64 , 3729950813036887i64 , 1783 14459986099519295i64 , 15808907290234758i64 , 6234512969275540i64 , 1784 18690008075805909i64 , 492531108753402i64 , 7721002928884704i64 , 1785 4886156035126456i64 , 21716374046066558i64 , 11035311630511661i64 , 1786 16837692753538891i64 , 20172053977953882i64 , 15488511700491202i64 , 1787 17477921115358343i64 , 24726937211646877i64 , 22480504880004621i64 , 1788 18521326635500559i64 , 8076560603417178i64 , 22382516625473209i64 , 1789 21696842111535623i64 , 12559160944089288i64 , 1661142873895453i64 , 1790 18379772814447567i64 , 10295321430586466i64 , 12378145201769592i64 , 1791 11815752235866582i64 }; 1792 #else 1793 const hashtype Algo_hash::hashCodes[] = { 1676 1794 1448047776469843LL , 23745670021858756LL , 2503503679898819LL , 1677 1795 20893061577159209LL , 10807838381971450LL , 2362252468869198LL , … … 1795 1913 18379772814447567LL , 10295321430586466LL , 12378145201769592LL , 1796 1914 11815752235866582LL }; 1797 1798 HashVarInfo::HashVarInfo(long long CHC, vector<pair<long long, ExtendedMoveNumber>* > * LFC, 1915 #endif 1916 1917 HashVarInfo::HashVarInfo(hashtype CHC, vector<pair<hashtype, ExtendedMoveNumber>* > * LFC, 1799 1918 ExtendedMoveNumber* MOVENUMBER) { 1800 1919 chc = CHC; 1801 1920 moveNumber = new ExtendedMoveNumber(*MOVENUMBER); 1802 lfc = new vector<pair< long long, ExtendedMoveNumber>* >;1803 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = LFC->begin(); it != LFC->end(); it++) {1804 lfc->push_back(new pair< long long, ExtendedMoveNumber>((*it)->first, (*it)->second));1921 lfc = new vector<pair<hashtype, ExtendedMoveNumber>* >; 1922 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = LFC->begin(); it != LFC->end(); it++) { 1923 lfc->push_back(new pair<hashtype, ExtendedMoveNumber>((*it)->first, (*it)->second)); 1805 1924 } 1806 1925 } … … 1814 1933 } 1815 1934 1816 int Algo_hash::insert_hash( long longhashCode, ExtendedMoveNumber& mn, Move* continuation) {1935 int Algo_hash::insert_hash(hashtype hashCode, ExtendedMoveNumber& mn, Move* continuation) { 1817 1936 // printf("insert %lld\n", hashCode); 1818 1937 char* buf = new char[30 + mn.length*2]; … … 1835 1954 sqlite3_stmt *ppStmt=0; 1836 1955 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1837 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?)1956 if (rc != SQLITE_OK || ppStmt==0) return rc; 1838 1957 rc = sqlite3_bind_int64(ppStmt, 1, currentHashCode); 1839 1958 if (rc != SQLITE_OK) return rc; … … 1862 1981 moveNumber = new ExtendedMoveNumber(0); 1863 1982 currentHashCode = 0; // start with empty board 1864 lfc = new vector<pair< long long, ExtendedMoveNumber>* >;1983 lfc = new vector<pair<hashtype, ExtendedMoveNumber>* >; 1865 1984 branchpoints = new stack<HashVarInfo>; 1866 1985 } 1867 1986 1868 1987 void Algo_hash::AB_process(int x, int y) { 1869 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) {1988 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) { 1870 1989 Move* continuation = new Move(x,y,'B'); 1871 1990 if (insert_hash((*it)->first, (*it)->second, continuation) != 0) throw DBError(); … … 1874 1993 } 1875 1994 delete lfc; 1876 lfc = new vector<pair< long long, ExtendedMoveNumber>* >;1995 lfc = new vector<pair<hashtype, ExtendedMoveNumber>* >; 1877 1996 currentHashCode += hashCodes[x + boardsize*y]; 1878 1997 } 1879 1998 1880 1999 void Algo_hash::AW_process(int x, int y) { 1881 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) {2000 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) { 1882 2001 Move* continuation = new Move(x,y,'W'); 1883 2002 if (insert_hash((*it)->first, (*it)->second, continuation) != 0) throw DBError(); … … 1886 2005 } 1887 2006 delete lfc; 1888 lfc = new vector<pair< long long, ExtendedMoveNumber>* >;2007 lfc = new vector<pair<hashtype, ExtendedMoveNumber>* >; 1889 2008 currentHashCode -= hashCodes[x + boardsize*y]; 1890 2009 } … … 1896 2015 1897 2016 void Algo_hash::endOfNode_process() { 1898 lfc->push_back(new pair< long long, ExtendedMoveNumber>(currentHashCode, *moveNumber));2017 lfc->push_back(new pair<hashtype, ExtendedMoveNumber>(currentHashCode, *moveNumber)); 1899 2018 moveNumber->next(); 1900 2019 } … … 1905 2024 1906 2025 void Algo_hash::move_process(Move m) throw(DBError) { 1907 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) {2026 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) { 1908 2027 Move* continuation = new Move(m); 1909 2028 int rc = insert_hash((*it)->first, (*it)->second, continuation); … … 1913 2032 } 1914 2033 delete lfc; 1915 lfc = new vector<pair< long long, ExtendedMoveNumber>* >;2034 lfc = new vector<pair<hashtype, ExtendedMoveNumber>* >; 1916 2035 int epsilon = (m.color == 'B' || m.color == 'X' ? 1 : -1); 1917 2036 currentHashCode += epsilon * hashCodes[m.x + boardsize*m.y]; … … 1934 2053 1935 2054 void Algo_hash::endOfVariation_process() { 1936 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) {2055 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) { 1937 2056 int rc = insert_hash((*it)->first, (*it)->second, 0); 1938 2057 if (rc != 0) printf("ouch %d\n", rc); // FIXME … … 1949 2068 1950 2069 void Algo_hash::endgame_process() { 1951 for(vector<pair< long long, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) {2070 for(vector<pair<hashtype, ExtendedMoveNumber>* >::iterator it = lfc->begin(); it != lfc->end(); it++) { 1952 2071 Move* continuation = 0; 1953 2072 int rc = insert_hash((*it)->first, (*it)->second, continuation); … … 1964 2083 1965 2084 1966 long longAlgo_hash::compute_hashkey(Pattern& pattern) {2085 hashtype Algo_hash::compute_hashkey(Pattern& pattern) { 1967 2086 if (pattern.sizeX != boardsize || pattern.sizeY != boardsize) 1968 2087 return NOT_HASHABLE; 1969 long longhashkey = 0;2088 hashtype hashkey = 0; 1970 2089 1971 2090 for(int i=0; i<boardsize; i++) { … … 2028 2147 // printf("enter algo_hash.search %d\n", plS); 2029 2148 for(int N=0; N<plS; N++) { 2030 long longhashCode = compute_hashkey(patternList.data[N]);2149 hashtype hashCode = compute_hashkey(patternList.data[N]); 2031 2150 if (hashCode == NOT_HASHABLE) return -1; // failure 2032 2151 … … 2700 2819 throw DBError(); 2701 2820 } 2821 rc = sqlite3_busy_timeout(db, 200); 2822 if (rc) throw DBError(); 2702 2823 rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 2703 2824 if (rc) throw DBError(); 06/libkombilo/search.h
r188 r191 31 31 #include "abstractboard.h" 32 32 #include "sgfparser.h" 33 using namespace std;34 33 typedef char* char_p; 34 35 #ifdef __BORLANDC__ 36 typedef __int64 hashtype; 37 #else 38 typedef long long hashtype; 39 #endif 35 40 36 41 const char NO_CONT = 255; … … 57 62 Symmetries(const Symmetries& s); 58 63 Symmetries& operator=(const Symmetries& s); 59 void set(char i, char j, char k, char l, char cs) ;60 char getX(char i, char j) ;61 char getY(char i, char j) ;62 char getCS(char i, char j) ;63 char has_key(char i, char j) ;64 void set(char i, char j, char k, char l, char cs) throw(PatternError); 65 char getX(char i, char j) throw(PatternError); 66 char getY(char i, char j) throw(PatternError); 67 char getCS(char i, char j) throw(PatternError); 68 char has_key(char i, char j) throw(PatternError); 64 69 }; 65 70 … … 89 94 char* initialPos; 90 95 char* finalPos; 91 vector<MoveNC> contList;96 std::vector<MoveNC> contList; 92 97 93 98 Pattern(); 94 Pattern(int le, int ri, int to, int bo, int sX, int sY, char* iPos, const vector<MoveNC>& CONTLIST);95 Pattern(int type, int boardsize, int sX, int sY, char* iPos, vector<MoveNC> CONTLIST);99 Pattern(int le, int ri, int to, int bo, int sX, int sY, char* iPos, const std::vector<MoveNC>& CONTLIST); 100 Pattern(int type, int boardsize, int sX, int sY, char* iPos, std::vector<MoveNC> CONTLIST); 96 101 Pattern(int type, int boardsize, int sX, int sY, char* iPos); 97 102 Pattern(const Pattern& p); … … 105 110 char BW2XO(char c); 106 111 int operator==(const Pattern& p); 107 voidprintPattern();112 std::string printPattern(); 108 113 109 114 static int flipsX(int i, int x, int y, int XX, int YY); … … 131 136 int fixedColor; // allow switching colors 132 137 int nextMove; // 1: next must be black, 2: next must be white 133 vector<Pattern> data;134 vector<Symmetries> symmetries;138 std::vector<Pattern> data; 139 std::vector<Symmetries> symmetries; 135 140 Continuation* continuations; 136 141 int special; … … 138 143 PatternList(Pattern& p, int fColor, int nMove, int bsize); 139 144 ~PatternList(); 140 PatternList(const PatternList& pl);141 PatternList& operator=(const PatternList& pl);142 145 143 146 char invertColor(char co); … … 210 213 void branchpoint_process(); 211 214 void endOfVariation_process(); 212 void endgame_process() ;215 void endgame_process() throw(DBError); 213 216 void finalize_process(); 214 217 215 218 int counter; 216 219 char* signature; 217 vector<char* > *datasig;220 std::vector<char* > *datasig; 218 221 private: 219 222 bool main_variation; … … 234 237 void branchpoint_process(); 235 238 void endOfVariation_process(); 236 void endgame_process() ;239 void endgame_process() throw(DBError); 237 240 void finalize_process(); 238 241 239 242 char* fp; 240 243 int fpIndex; 241 vector<char* > *data;244 std::vector<char* > *data; 242 245 int readDB(sqlite3* DB); 243 246 int search(PatternList& patternList, GameList& gl, SearchOptions& options); … … 266 269 bool dictsDR; 267 270 int dictsNO; 268 vector<MoveNC> contList;271 std::vector<MoveNC> contList; 269 272 int contListIndex; 270 p air<char,char>Xinterv;271 p air<char,char>Yinterv;273 p_cc Xinterv; 274 p_cc Yinterv; 272 275 char mx; 273 276 char my; … … 280 283 }; 281 284 282 class VecMC : public vector<MovelistCand* > {285 class VecMC : public std::vector<MovelistCand* > { 283 286 public: 284 287 VecMC(); … … 303 306 void branchpoint_process(); 304 307 void endOfVariation_process(); 305 void endgame_process() ;308 void endgame_process() throw(DBError); 306 309 void finalize_process(); 307 310 int readDB(sqlite3* DB); 308 311 int search(PatternList& patternList, GameList& gl, SearchOptions& options); 309 312 310 vector<char> movelist;313 std::vector<char> movelist; 311 314 char* fpC; 312 vector<char* > *data1;313 vector<char* > *data2;314 vector<int> *data1l;315 }; 316 317 const long longNOT_HASHABLE = 9223372036854775807LL;315 std::vector<char* > *data1; 316 std::vector<char* > *data2; 317 std::vector<int> *data1l; 318 }; 319 320 const hashtype NOT_HASHABLE = 9223372036854775807LL; 318 321 319 322 … … 332 335 class HashVarInfo { 333 336 public: 334 long longchc;335 vector<pair<long long, ExtendedMoveNumber>* > * lfc;337 hashtype chc; 338 std::vector<std::pair<hashtype, ExtendedMoveNumber>* > * lfc; 336 339 ExtendedMoveNumber* moveNumber; 337 340 338 HashVarInfo( long long CHC, vector<pair<long long, ExtendedMoveNumber>* > * LFC, ExtendedMoveNumber* MOVENUMBER);341 HashVarInfo(hashtype CHC, std::vector<std::pair<hashtype, ExtendedMoveNumber>* > * LFC, ExtendedMoveNumber* MOVENUMBER); 339 342 }; 340 343 … … 357 360 int search(PatternList& patternList, GameList& gl, SearchOptions& options, sqlite3* db); 358 361 359 int insert_hash( long longhashCode, ExtendedMoveNumber& mn, Move* continuation);360 long longcompute_hashkey(Pattern& pattern);361 362 long longcurrentHashCode;362 int insert_hash(hashtype hashCode, ExtendedMoveNumber& mn, Move* continuation); 363 hashtype compute_hashkey(Pattern& pattern); 364 365 hashtype currentHashCode; 363 366 ExtendedMoveNumber* moveNumber; 364 vector<pair<long long, ExtendedMoveNumber>* > *lfc; // hash code + move number, still looking for continuation365 st ack<HashVarInfo>* branchpoints;366 367 static const long longhashCodes[];367 std::vector<std::pair<hashtype, ExtendedMoveNumber>* > *lfc; // hash code + move number, still looking for continuation 368 std::stack<HashVarInfo>* branchpoints; 369 370 static const hashtype hashCodes[]; 368 371 }; 369 372 … … 378 381 // int isEmpty(); 379 382 // 380 // vector<pair<int,int>> data;383 // std::vector<pair<int,int>> data; 381 384 // 382 385 // }; … … 388 391 // ~Algo_intervals(); 389 392 // 390 // vector<long> movesArr;391 // vector<long> moveIntsArr;392 // 393 // vector<vector<int>*> moves;393 // std::vector<long> movesArr; 394 // std::vector<long> moveIntsArr; 395 // 396 // std::vector<vector<int>*> moves; 394 397 // 395 398 // int counter; … … 435 438 public: 436 439 int id; // id within the concerning database 437 st ring gameInfoStr;440 std::string gameInfoStr; 438 441 char winner; 439 vector<Hit* > * hits; // used for hits440 vector<Candidate* > * candidates; // used for candidates441 442 GameListEntry(int ID, char WINNER, st ring GAMEINFOSTR);442 std::vector<Hit* > * hits; // used for hits 443 std::vector<Candidate* > * candidates; // used for candidates 444 445 GameListEntry(int ID, char WINNER, std::string GAMEINFOSTR); 443 446 ~GameListEntry(); 444 447 }; … … 458 461 public: 459 462 char* dbname; 460 st ring orderby;463 std::string orderby; 461 464 // constructor receives a FORMAT string; see trac wiki for the syntax to be used 462 st ring format1; // extracted from FORMAT; the column list of the sql query to retrieve the games463 st ring format2; // extracted from FORMAT, used as template when inserting the query results into the game list465 std::string format1; // extracted from FORMAT; the column list of the sql query to retrieve the games 466 std::string format2; // extracted from FORMAT, used as template when inserting the query results into the game list 464 467 int numColumns; 465 468 int algos; … … 467 470 int processVariations; 468 471 algo_p* algo_ps; 469 vector<GameListEntry* > * all;470 vector<pair<int,int> > * currentList; // pair of game id and position within all472 std::vector<GameListEntry* > * all; 473 std::vector<std::pair<int,int> > * currentList; // pair of game id and position within all 471 474 // (usually sorted w.r.t. second 472 475 // component) 473 vector<pair<int,int> > * oldList;476 std::vector<std::pair<int,int> > * oldList; 474 477 int current; 475 478 sqlite3* db; … … 479 482 480 483 // the following methods provide the user interface 481 GameList(char* DBNAME, st ring ORDERBY,string FORMAT, int ALGOS, int BOARDSIZE) throw(DBError);484 GameList(char* DBNAME, std::string ORDERBY, std::string FORMAT, int ALGOS, int BOARDSIZE) throw(DBError); 482 485 483 486 void search(Pattern& pattern, SearchOptions& options) throw(DBError); … … 486 489 void gisearch(char* sql) throw(DBError); 487 490 int size(); 488 vector<string> currentEntriesAsStrings(int start=0, int end=0);491 std::vector<std::string> currentEntriesAsStrings(int start=0, int end=0); 489 492 int numHits(); 490 493 … … 500 503 int end_sorted(); 501 504 char getCurrentWinner(); 502 vector<Candidate* > *getCurrentCandidateList();503 void makeCurrentCandidate( vector<Candidate* > *candidates);504 void makeCurrentHit( vector<Hit* > *hits);505 void makeIndexCandidate(int index, vector<Candidate* > *candidates);506 void makeIndexHit(int index, vector<Hit* > *hits);505 std::vector<Candidate* > *getCurrentCandidateList(); 506 void makeCurrentCandidate(std::vector<Candidate* > *candidates); 507 void makeCurrentHit(std::vector<Hit* > *hits); 508 void makeIndexCandidate(int index, std::vector<Candidate* > *candidates); 509 void makeIndexHit(int index, std::vector<Hit* > *hits); 507 510 508 511 private: 509 st ring resultsStr(GameListEntry* gle);512 std::string resultsStr(GameListEntry* gle); 510 513 char lookupLabel(char x, char y); 511 514 void readDB(); 06/libkombilo/sgfparser.cc
r190 r191 23 23 24 24 #include "sgfparser.h" 25 26 using std::vector; 27 using std::stack; 28 using std::pair; 29 using std::map; 30 using std::string; 25 31 26 32 SGFError::SGFError() {} … … 400 406 else i++; 401 407 } 402 data.insert(make_pair( ID, propValueList));408 data.insert(make_pair(string(ID), propValueList)); 403 409 } 404 410 parsed = 1; 06/libkombilo/sgfparser.h
r188 r191 30 30 #include <stack> 31 31 #include <map> 32 using namespace std;33 32 34 typedef pair<char,char> p_cc;33 typedef std::pair<char,char> p_cc; 35 34 36 35 class SGFError { … … 68 67 int numChildren; 69 68 int level; 70 st ring SGFstring;69 std::string SGFstring; 71 70 int parsed; 72 vector<string> gpv(conststring& prop);73 vector<string>* get_property_value(conststring& prop);74 void set_property_value(st ring& ID, vector<string>* propValue) throw(SGFError);71 std::vector<std::string> gpv(const std::string& prop); 72 std::vector<std::string>* get_property_value(const std::string& prop); 73 void set_property_value(std::string& ID, std::vector<std::string>* propValue) throw(SGFError); 75 74 76 75 int posyD; // used when displaying SGF structure graphically as a tree … … 82 81 static int sloppy; 83 82 private: 84 map<string, vector<string>* > data; // use get_property_value to access this83 std::map<std::string, std::vector<std::string>* > data; // use get_property_value to access this 85 84 }; 86 85 … … 139 138 }; 140 139 141 st ring nodeToString(map<string, vector<string>* >& data) throw(SGFError);140 std::string nodeToString(std::map<std::string, std::vector<std::string>* >& data) throw(SGFError); 142 141 // char* rootNodeToString(PyObject* data); 143 142
