root/06/libkombilo-branches/hash_center_makedb/cpptest.cpp

Revision 233, 6.4 kB (checked in by ug, 1 year ago)

Basic functions for hashing of center patterns (no search capability yet).

Line 
1 #include <fstream>
2 #include <string>
3 #include "boost/filesystem/operations.hpp"
4 #include "search.h"
5
6 using namespace std;
7 using boost::filesystem::directory_iterator;
8
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;
17   }
18
19   // ----------------- set up processing options -----------------------------------
20   ProcessOptions* p_op = new ProcessOptions;
21   p_op->algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_CENTER;
22
23   // ----------------- create GameList instance -----------------------------------
24   GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]], ", p_op);
25   delete p_op;
26
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/center_hashes/libkombilo";
32     // string path = "/home/ug/go/gtl/reviews";
33     string path = "/home/ug/go/gogod06/2000";
34     for(directory_iterator it(path); it != end_itr; ++it) {
35       string n = it->string();
36       if (n.substr(n.size()-4) == ".sgf") {
37         ifstream infile;
38         // printf("%s\n", n.c_str());
39         infile.open(it->native_file_string().c_str());
40
41         string sgf;
42         string line;
43         while (!infile.eof()) {
44           getline(infile, line);
45           sgf += line + "\n";
46         }
47         infile.close();
48         gl.process(sgf.c_str(), path.c_str(), n.c_str());   
49       }
50     }
51     gl.finalize_processing();
52     printf("Processed %d games.\n", gl.size());
53   }
54   printf("%d games.\n", gl.size());
55
56   // ------------------- set up search pattern ----------------------------------------
57
58   // Pattern p(CENTER_PATTERN, 19, 2, 2, ".XXO", "D..F");
59
60   // Pattern p(CENTER_PATTERN, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>());
61   // Pattern p(2,2,4,4, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>()); // "fixed anchor"
62
63   // anchor varies only in small region of board: the first 4 entries
64   // (left, right, top, bottom) describe the rectangle which may contain the top left point of the pattern.
65   // The coordinates range from 0 to boardsize-1
66   // For example, CORNER_NW_PATTERN corresponds to (0,0,0,0)
67   // Pattern p(2,3,4,6, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>());
68  
69   // Pattern p(CORNER_NW_PATTERN,19,8,8,"...................X......X.......XO......OO....................");
70   // Pattern p(CORNER_NW_PATTERN,19,7,7,".................X.....X......XO.....OO..........");
71   // Pattern p(CORNER_NW_PATTERN,19,7,7,".......................X.........................");
72
73   // gl.gisearch("pw = 'Hane Naoki'");
74   Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO");
75   // vector<MoveNC> contList;
76   // contList.push_back(MoveNC(6,15,'X'));
77   // contList.push_back(MoveNC(6,13,'O'));
78   // contList.push_back(MoveNC(4,15,'X'));
79   // 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);
80   // 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.............");
81
82   // Pattern p(FULLBOARD_PATTERN,19,19,19,"........................................................................O......................................................................................................................................................................................................................X.........................................................................");
83
84   // -------------------- set up search options ----------------------------------
85   SearchOptions so;
86   // so.trustHashFull = true;
87   // SearchOptions so(0,0,50); // use move limit
88   // so.searchInVariations = false;
89   // so.nextMove = 2;
90  
91   // -------------------- do pattern search --------------------------------------
92   gl.search(p, &so);
93
94   // ------------------- print some information about current list of games ------------
95   printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits());
96   // vector<string> res = gl.currentEntriesAsStrings();
97   // for(vector<string>::iterator it = res.begin(); it != res.end(); it++)
98   //   printf("%s\n", it->c_str());
99   // for(int i=0; i<gl.size(); i++) printf("%s\n", gl.currentEntryAsString(i).c_str());
100
101   // ------------------- print some statistics ------------------------------------------
102   printf("Search pattern:\n");
103   printf("%s\n", p.printPattern().c_str());
104   printf("Continuations:\n");
105   for(int y=0; y<p.sizeY; y++) {
106     for(int x=0; x<p.sizeX; x++) {
107       printf("%c", gl.lookupLabel(x,y));
108     }
109     printf("\n");
110   }
111   printf("\n");
112   printf("Statistics:\n");
113   printf("num hits: %d, num switched: %d, B wins: %d, W wins: %d\n", gl.num_hits, gl.num_switched, gl.Bwins, gl.Wwins);
114
115   printf("Continuation | Black      ( B wins / W wins ) | White      (B wins / W wins) |\n");
116   for(int y=0; y<p.sizeY; y++) {
117     for(int x=0; x<p.sizeX; x++) {
118       if (gl.lookupLabel(x,y) != '.') {
119         Continuation cont = gl.lookupContinuation(x,y);
120         printf("      %c      |   %3d[%3d] (    %3d /    %3d ) |   %3d[%3d] (   %3d /    %3d) | %1.1f /  %1.1f \n",
121             gl.lookupLabel(x,y), cont.B, cont.tB, cont.wB, cont.lB, cont.W, cont.tW, cont.wW, cont.lW,
122             cont.wW*100.0/cont.W, cont.wB*100.0/cont.B);
123       }
124     }
125   }
126
127   // ------------------- resetFormat ------------------------------------------
128   // printf("reset db\n");
129   // gl.resetFormat("pb");
130   // vector<string> res = gl.currentEntriesAsStrings(0, 40);
131   // for(vector<string>::iterator it = res.begin(); it != res.end(); it++)
132   //   printf("%s\n", it->c_str());
133 }
Note: See TracBrowser for help on using the browser.