first-draft of crop feature and problem theme
[eidogo-ojd.git] / kombilo / cpptest.cpp
blob1ce1a225fa80be426443794446fb3278432bfce6
1 #include <fstream>
2 #include <string>
3 #include "boost/filesystem/operations.hpp"
4 #include "search.h"
6 using namespace std;
7 using boost::filesystem::directory_iterator;
9 int main(int argc, char** argv) {
10 // ----------------- parse command line arguments ---------------------------------
11 int algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL | ALGO_HASH_CORNER;
12 bool process = false;
13 for(int i=1; i<argc; i++) {
14 if (!strcmp(argv[i], "-nh")) // disable hashing
15 algos = ALGO_FINALPOS | ALGO_MOVELIST;
16 if (!strcmp(argv[i], "-p")) process = true;
19 // ----------------- set up processing options -----------------------------------
20 ProcessOptions* p_op = new ProcessOptions;
21 p_op->algos = ALGO_FINALPOS | ALGO_MOVELIST;
23 // ----------------- create GameList instance -----------------------------------
24 GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]], ", 0);
25 delete p_op;
27 // ---------------- process SGF games ---------------------------------------------
28 if (process) { // process sgf's. must be first argument
29 gl.start_processing();
30 directory_iterator end_itr;
31 // string path = "/home/ug/go/kombilo/06/tests1/libkombilo";
32 // string path = "/home/ug/go/gtl/reviews";
33 string path = "/home/ug/go/gogod06/1998";
34 int counter = 0;
35 for(directory_iterator it(path); it != end_itr; ++it) {
36 string n = it->string();
37 if (n.substr(n.size()-4) == ".sgf") {
38 ifstream infile;
39 // printf("%s\n", n.c_str());
40 infile.open(it->native_file_string().c_str());
42 string sgf;
43 string line;
44 while (!infile.eof()) {
45 getline(infile, line);
46 sgf += line + "\n";
48 infile.close();
49 int flags = CHECK_FOR_DUPLICATES; // |OMIT_DUPLICATES;
50 if (gl.process(sgf.c_str(), path.c_str(), n.c_str(), "", flags))
51 if (gl.process_results() & IS_DUPLICATE) printf("is duplicate: %d\n", counter);
52 counter++;
55 gl.finalize_processing();
56 printf("Now %d games in db.\n", gl.size());
58 printf("%d games.\n", gl.size());
60 // ------------------- set up search pattern ----------------------------------------
62 // Pattern p(CENTER_PATTERN, 19, 2, 2, ".XXO", "D..F");
64 // Pattern p(CENTER_PATTERN, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>());
65 // Pattern p(2,2,4,4, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>()); // "fixed anchor"
67 // anchor varies only in small region of board: the first 4 entries
68 // (left, right, top, bottom) describe the rectangle which may contain the top left point of the pattern.
69 // The coordinates range from 0 to boardsize-1
70 // For example, CORNER_NW_PATTERN corresponds to (0,0,0,0)
71 // Pattern p(2,3,4,6, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>());
73 // Pattern p(CORNER_NW_PATTERN,19,8,8,"...................X......X.......XO......OO....................");
74 // Pattern p(CORNER_NW_PATTERN,19,7,7,".................X.....X......XO.....OO..........");
75 // Pattern p(CORNER_NW_PATTERN,19,7,7,".......................X.........................");
77 // gl.gisearch("pw = 'Hane Naoki'");
78 Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO");
79 // vector<MoveNC> contList;
80 // contList.push_back(MoveNC(6,15,'X'));
81 // contList.push_back(MoveNC(6,13,'O'));
82 // contList.push_back(MoveNC(4,15,'X'));
83 // Pattern p(FULLBOARD_PATTERN, 19, 19, 19, ".....................O.O........OX......XO......X.OXX.XX...X,.OOXXX..OOOX.O....X.OXOOXOO..OX.......XOXXOXXOOXXOO....OX.XXXOOOXO.O.O...OXX..XOX..XO.X.XO...O.......X.....XO..O.,X....,.....XOO................X......X............X....O...........................................O.O...........O.....,.....X...........X.O.X............................................", contList);
84 // Pattern p(FULLBOARD_PATTERN, 19, 19, 19, "..O.O....X...XXXXX.OOXO....OXO.XXOOOXOXXXXOO.OOXO.OXO..O..X.X..OOX,X.XO.O.....XOOOXOXX..XO......X.XOXXX..XXXO........XOX..XXOOXO.OOO.....OOXOXOO.O...XX...X..OXXOO.XOX........O..OX.,..X..X.....X...OX...X..........O....XXXO...XO...X...OOOXOOXX...X....O..OX.O..OX..........OXX....OX..OO..O.OOOOX..O.OX..XX..OOXXXOX.XOOX..X....XXXXXOX...OX.......X.O.XO.............");
86 // Pattern p(FULLBOARD_PATTERN,19,19,19,"........................................................................O......................................................................................................................................................................................................................X.........................................................................");
88 // -------------------- set up search options ----------------------------------
89 SearchOptions so;
90 // so.trustHashFull = true;
91 // SearchOptions so(0,0,50); // use move limit
92 // so.searchInVariations = false;
93 // so.nextMove = 2;
95 // -------------------- do pattern search --------------------------------------
96 gl.search(p, &so);
98 // ------------------- print some information about current list of games ------------
99 printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits());
100 // vector<string> res = gl.currentEntriesAsStrings();
101 // for(vector<string>::iterator it = res.begin(); it != res.end(); it++)
102 // printf("%s\n", it->c_str());
103 // for(int i=0; i<gl.size(); i++) printf("%s\n", gl.currentEntryAsString(i).c_str());
105 // ------------------- print some statistics ------------------------------------------
106 // printf("Search pattern:\n");
107 // printf("%s\n", p.printPattern().c_str());
108 // printf("Continuations:\n");
109 // for(int y=0; y<p.sizeY; y++) {
110 // for(int x=0; x<p.sizeX; x++) {
111 // printf("%c", gl.lookupLabel(x,y));
112 // }
113 // printf("\n");
114 // }
115 // printf("\n");
116 // printf("Statistics:\n");
117 // printf("num hits: %d, num switched: %d, B wins: %d, W wins: %d\n", gl.num_hits, gl.num_switched, gl.Bwins, gl.Wwins);
119 // printf("Continuation | Black ( B wins / W wins ) | White (B wins / W wins) |\n");
120 // for(int y=0; y<p.sizeY; y++) {
121 // for(int x=0; x<p.sizeX; x++) {
122 // if (gl.lookupLabel(x,y) != '.') {
123 // Continuation cont = gl.lookupContinuation(x,y);
124 // printf(" %c | %3d[%3d] ( %3d / %3d ) | %3d[%3d] ( %3d / %3d) | %1.1f / %1.1f \n",
125 // gl.lookupLabel(x,y), cont.B, cont.tB, cont.wB, cont.lB, cont.W, cont.tW, cont.wW, cont.lW,
126 // cont.wW*100.0/cont.W, cont.wB*100.0/cont.B);
127 // }
128 // }
129 // }
131 // ------------------- check for duplicates ---------------------------------
132 // gl.reset();
133 // int nd = gl.find_duplicates(19);
134 // printf("duplicates:\n");
135 // for(int i=0; i<nd; i++) {
136 // // 1st method: retrieve_duplicates_VI
137 // // vector<int> dupl_vector = gl.retrieve_duplicates_VI(i);
138 // // for(vector<int>::iterator it = dupl_vector.begin(); it != dupl_vector.end(); it++) {
139 // // printf("%s%s\n", gl.currentEntryAsString(*it).c_str(), gl.getSignature(*it).c_str());
140 // // }
142 // // 2nd method: retrieve_duplicates_PI
143 // int * dupl_vector = gl.retrieve_duplicates_PI(i);
144 // int j = 0;
145 // while(dupl_vector[j] != -1) {
146 // printf("%s%s\n", gl.currentEntryAsString(dupl_vector[j]).c_str(), gl.getSignature(dupl_vector[j]).c_str());
147 // j++;
148 // }
149 // delete [] dupl_vector;
151 // printf("--------------------------------------------------- \n");
152 // }
154 // ------------------- snapshot ---------------------------------------------
156 gl.delete_all_snapshots();
157 int handle = gl.snapshot();
158 printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits());
160 gl.reset();
161 printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits());
163 gl.restore(handle, true);
164 printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits());
166 // ------------------- resetFormat ------------------------------------------
167 // printf("reset db\n");
168 // gl.resetFormat("pb");
169 // vector<string> res = gl.currentEntriesAsStrings(0, 40);
170 // for(vector<string>::iterator it = res.begin(); it != res.end(); it++)
171 // printf("%s\n", it->c_str());