Changeset 188

Show
Ignore:
Timestamp:
09/29/06 23:09:01 (2 years ago)
Author:
ug
Message:

Fixed tabwidth, expanded tabs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/abstractboard.cc

    r186 r188  
    2727 
    2828MoveNC::MoveNC() { 
    29        x = -1; 
    30        y = -1; 
    31        color = ' '; 
     29  x = -1; 
     30  y = -1; 
     31  color = ' '; 
    3232} 
    3333 
    3434// coordinates used here: (1,1)-(19,19) FIXME what? 
    3535MoveNC::MoveNC(char X, char Y, char COLOR) { 
    36        x = X; 
    37        y = Y; 
    38        color = COLOR; 
     36  x = X; 
     37  y = Y; 
     38  color = COLOR; 
    3939} 
    4040 
    4141bool MoveNC::operator==(const MoveNC& mnc) const { 
    42        if (x == mnc.x && y == mnc.y && color == mnc.color) return true; 
    43        else return false; 
     42  if (x == mnc.x && y == mnc.y && color == mnc.color) return true; 
     43  else return false; 
    4444} 
    4545 
     
    7272      vector<p_cc>::iterator it; 
    7373      for(it = m.captures->begin(); it != m.captures->end(); it++)  
    74                                captures->push_back(*it); 
     74        captures->push_back(*it); 
    7575    } 
    7676    else captures = 0; 
     
    104104  if (DEBUG_ABSTRACTBOARD) printf("AB::operator= 0\n"); 
    105105  if (this != &ab) { 
    106                boardsize = ab.boardsize; 
    107                delete [] status; 
    108                status = new char[boardsize*boardsize+1]; 
    109                for (int i = 0; i < boardsize*boardsize; i++) 
    110                        status[i] = ab.status[i]; 
    111                status[boardsize*boardsize] = 0; 
    112                undostack = stack<Move>(ab.undostack); 
    113                if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n"); 
    114        
    115        return *this; 
     106    boardsize = ab.boardsize; 
     107    delete [] status; 
     108    status = new char[boardsize*boardsize+1]; 
     109    for (int i = 0; i < boardsize*boardsize; i++) 
     110      status[i] = ab.status[i]; 
     111    status[boardsize*boardsize] = 0; 
     112    undostack = stack<Move>(ab.undostack); 
     113    if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n"); 
     114 
     115  return *this; 
    116116} 
    117117 
     
    205205 
    206206vector<p_cc>* abstractBoard::legal(int x, int y, char color) { 
    207        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 0\n"); 
    208        vector<p_cc>* c = new vector<p_cc>; 
    209        int* nb = neighbors(x,y); 
    210        for(int i=1; i<=nb[0]; i++) { 
    211                int x1 = nb[i] / boardsize; 
    212                int y1 = nb[i] % boardsize; 
    213                if (status[boardsize*x1 + y1] == invert(color)) { 
    214                        vector<p_cc>* d = hasNoLibExcP(x1, y1, x*boardsize+y); 
    215                        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 39\n"); 
    216                        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 40, %d\n", d->size()); 
    217                        vector<p_cc>::iterator it; 
    218                        for(it = d->begin(); it != d->end(); it++) c->push_back(*it); 
    219                        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 41\n"); 
    220                        delete d; 
    221                
    222        
    223        delete [] nb; 
    224        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 42\n"); 
    225        setStatus(x,y,color); 
    226  
    227        if (c->size()) { 
    228                vector<p_cc>* captures = new vector<p_cc>(); 
    229                while (c->size()) { 
    230                        p_cc ctop = (*c)[0]; 
    231                        bool contained = false; 
    232                        vector<p_cc>::iterator it; 
    233                        for(it = captures->begin(); it != captures->end(); it++) { 
    234                                if (ctop.first == it->first && ctop.second == it->second) { 
    235                                        contained = true; 
    236                                        break; 
    237                                
    238                        
    239                        if (!contained) captures->push_back(ctop); 
    240                        c->erase(c->begin()); 
    241                
    242                delete c; 
    243                if (DEBUG_ABSTRACTBOARD) printf("AB::legal 98\n"); 
    244                return captures; 
    245        
    246        delete c; 
    247        vector<p_cc>* d = hasNoLibExcP(x, y); 
    248        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 49\n"); 
    249        if (DEBUG_ABSTRACTBOARD) printf("AB::legal 50, %d\n", d->size()); 
    250        if (d->size()) { 
    251                delete d; 
    252                status[boardsize*x + y] = ' '; 
    253                if (DEBUG_ABSTRACTBOARD) printf("AB::legal 99\n"); 
    254                return 0; 
    255        
    256        else { 
    257                delete d; 
    258                vector<p_cc>* ret = new vector<p_cc>(); 
    259                if (DEBUG_ABSTRACTBOARD) printf("AB::legal 100\n"); 
    260                return ret; 
    261        
     207  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 0\n"); 
     208  vector<p_cc>* c = new vector<p_cc>; 
     209  int* nb = neighbors(x,y); 
     210  for(int i=1; i<=nb[0]; i++) { 
     211    int x1 = nb[i] / boardsize; 
     212    int y1 = nb[i] % boardsize; 
     213    if (status[boardsize*x1 + y1] == invert(color)) { 
     214      vector<p_cc>* d = hasNoLibExcP(x1, y1, x*boardsize+y); 
     215      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 39\n"); 
     216      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 40, %d\n", d->size()); 
     217      vector<p_cc>::iterator it; 
     218      for(it = d->begin(); it != d->end(); it++) c->push_back(*it); 
     219      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 41\n"); 
     220      delete d; 
     221   
     222 
     223  delete [] nb; 
     224  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 42\n"); 
     225  setStatus(x,y,color); 
     226 
     227  if (c->size()) { 
     228    vector<p_cc>* captures = new vector<p_cc>(); 
     229    while (c->size()) { 
     230      p_cc ctop = (*c)[0]; 
     231      bool contained = false; 
     232      vector<p_cc>::iterator it; 
     233      for(it = captures->begin(); it != captures->end(); it++) { 
     234        if (ctop.first == it->first && ctop.second == it->second) { 
     235          contained = true; 
     236          break; 
     237       
     238     
     239      if (!contained) captures->push_back(ctop); 
     240      c->erase(c->begin()); 
     241   
     242    delete c; 
     243    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 98\n"); 
     244    return captures; 
     245 
     246  delete c; 
     247  vector<p_cc>* d = hasNoLibExcP(x, y); 
     248  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 49\n"); 
     249  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 50, %d\n", d->size()); 
     250  if (d->size()) { 
     251    delete d; 
     252    status[boardsize*x + y] = ' '; 
     253    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 99\n"); 
     254    return 0; 
     255 
     256  else { 
     257    delete d; 
     258    vector<p_cc>* ret = new vector<p_cc>(); 
     259    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 100\n"); 
     260    return ret; 
     261 
    262262} 
    263263 
    264264vector<p_cc>* abstractBoard::hasNoLibExcP(int x1, int y1, int exc) { 
    265        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n"); 
    266        vector<p_cc>* st = new vector<p_cc>; 
    267        vector<p_cc>* newlyFound = new vector<p_cc>; 
    268        newlyFound->push_back(p_cc(x1, y1)); 
    269        vector<p_cc>* n; 
    270        int foundNew = 1; 
    271  
    272        while (foundNew) { 
    273                foundNew = 0; 
    274                n = new vector<p_cc>; 
    275                vector<p_cc>::iterator it1; 
    276                for(it1=newlyFound->begin(); it1!=newlyFound->end(); it1++) { 
    277                        int x = it1->first; 
    278                        int y = it1->second; 
    279                        int* nbs = neighbors(x,y); 
    280                        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 7 (%d,%d) %d\n",x, y,nbs[0]); 
    281                        for (int j=1; j <= nbs[0]; j++) { 
    282                                int yy1 = nbs[j]; 
    283                                if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 99\n"); 
    284                                if (status[yy1] == ' ' && yy1 != exc) { 
    285                                        delete [] nbs; 
    286                                        delete st; 
    287                                        delete newlyFound; 
    288                                        delete n; 
    289                                        return new vector<p_cc>; 
    290                                
    291                                else { 
    292                                        if (status[yy1]==status[x*boardsize+y]) { 
    293                                                p_cc yy(yy1/boardsize, yy1%boardsize); 
    294                                                int foundNewHere = 1; 
    295                                                vector<p_cc>::iterator it; 
    296                                                for(it = st->begin(); it!=st->end(); it++) { 
    297                                                        if (it->first==yy.first && it->second==yy.second) { 
    298                                                                foundNewHere = 0; 
    299                                                                break; 
    300                                                        
    301                                                
    302                                                if (foundNewHere) { 
    303                                                        for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
    304                                                                if (it->first==yy.first && it->second==yy.second) { 
    305                                                                        foundNewHere = 0; 
    306                                                                        break; 
    307                                                                
    308                                                        
    309                                                
    310                                                if (foundNewHere) { 
    311                                                        n->push_back(yy); 
    312                                                        foundNew = 1; 
    313                                                
    314                                        
    315                                
    316                        
    317                        delete [] nbs; 
    318                
    319  
    320                vector<p_cc>::iterator it; 
    321                for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
    322                        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 10, (%d,%d)\n", it->first, it->second); 
    323                        st->push_back(*it); 
    324                
    325                delete newlyFound; 
    326                newlyFound = n; 
    327        
    328        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n"); 
    329        delete n; 
    330        return st; 
     265  if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n"); 
     266  vector<p_cc>* st = new vector<p_cc>; 
     267  vector<p_cc>* newlyFound = new vector<p_cc>; 
     268  newlyFound->push_back(p_cc(x1, y1)); 
     269  vector<p_cc>* n; 
     270  int foundNew = 1; 
     271 
     272  while (foundNew) { 
     273    foundNew = 0; 
     274    n = new vector<p_cc>; 
     275    vector<p_cc>::iterator it1; 
     276    for(it1=newlyFound->begin(); it1!=newlyFound->end(); it1++) { 
     277      int x = it1->first; 
     278      int y = it1->second; 
     279      int* nbs = neighbors(x,y); 
     280      if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 7 (%d,%d) %d\n",x, y,nbs[0]); 
     281      for (int j=1; j <= nbs[0]; j++) { 
     282        int yy1 = nbs[j]; 
     283        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 99\n"); 
     284        if (status[yy1] == ' ' && yy1 != exc) { 
     285          delete [] nbs; 
     286          delete st; 
     287          delete newlyFound; 
     288          delete n; 
     289          return new vector<p_cc>; 
     290       
     291        else { 
     292          if (status[yy1]==status[x*boardsize+y]) { 
     293            p_cc yy(yy1/boardsize, yy1%boardsize); 
     294            int foundNewHere = 1; 
     295            vector<p_cc>::iterator it; 
     296            for(it = st->begin(); it!=st->end(); it++) { 
     297              if (it->first==yy.first && it->second==yy.second) { 
     298                foundNewHere = 0; 
     299                break; 
     300             
     301           
     302            if (foundNewHere) { 
     303              for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
     304                if (it->first==yy.first && it->second==yy.second) { 
     305                  foundNewHere = 0; 
     306                  break; 
     307               
     308             
     309           
     310            if (foundNewHere) { 
     311              n->push_back(yy); 
     312              foundNew = 1; 
     313           
     314         
     315       
     316     
     317      delete [] nbs; 
     318   
     319 
     320    vector<p_cc>::iterator it; 
     321    for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
     322      if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 10, (%d,%d)\n", it->first, it->second); 
     323      st->push_back(*it); 
     324   
     325    delete newlyFound; 
     326    newlyFound = n; 
     327 
     328  if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n"); 
     329  delete n; 
     330  return st; 
    331331} 
    332332 
     
    346346      status[x*boardsize+y] = ' '; 
    347347      if (captures) { 
    348        for(unsigned int i=0; i < captures->size(); i++) { 
    349          p_cc t = (*captures)[i]; 
    350          setStatus(t.first, t.second, invert(color)); 
    351        
     348  for(unsigned int i=0; i < captures->size(); i++) { 
     349    p_cc t = (*captures)[i]; 
     350    setStatus(t.first, t.second, invert(color)); 
     351 
    352352      } 
    353353    } 
  • 06/libkombilo/abstractboard.h

    r186 r188  
    4141 
    4242class MoveNC { 
    43        public: 
    44                char x; 
    45                char y; 
    46                char color; 
     43  public: 
     44    char x; 
     45    char y; 
     46    char color; 
    4747 
    48                MoveNC(); 
    49          MoveNC(char X, char Y, char COLOR); 
    50                bool operator==(const MoveNC& mnc) const; 
     48    MoveNC(); 
     49    MoveNC(char X, char Y, char COLOR); 
     50    bool operator==(const MoveNC& mnc) const; 
    5151}; 
    5252 
    5353class Move : public MoveNC { 
    54        public: 
    55                Move(char xx, char yy, char cc); 
    56                Move(const Move& m); 
    57                ~Move(); 
    58                Move& operator=(const Move& m); 
     54  public: 
     55    Move(char xx, char yy, char cc); 
     56    Move(const Move& m); 
     57    ~Move(); 
     58    Move& operator=(const Move& m); 
    5959 
    60                vector<pair<char,char> >* captures; 
     60    vector<pair<char,char> >* captures; 
    6161}; 
    6262 
    6363 
    6464class abstractBoard { 
    65        public: 
    66                int boardsize; 
    67                char* status; 
    68                stack<Move> undostack; 
     65  public: 
     66    int boardsize; 
     67    char* status; 
     68    stack<Move> undostack; 
    6969 
    70                abstractBoard(int bs = 19) throw(BoardError); 
    71                abstractBoard(const abstractBoard& ab); 
    72                ~abstractBoard(); 
    73                abstractBoard& operator=(const abstractBoard& ab); 
    74                void clear(); 
    75                int play(int x, int y, char* color) throw(BoardError); 
    76                void undo(int n=1); 
    77                void remove(int x, int y); 
    78                char getStatus(int x, int y); 
    79                void setStatus(int x, int y, char val); 
    80                int len_cap_last() throw(BoardError); 
    81                void undostack_append_pass(); 
    82                // abstractBoard& copy(const abstractBoard& ab); 
     70    abstractBoard(int bs = 19) throw(BoardError); 
     71    abstractBoard(const abstractBoard& ab); 
     72    ~abstractBoard(); 
     73    abstractBoard& operator=(const abstractBoard& ab); 
     74    void clear(); 
     75    int play(int x, int y, char* color) throw(BoardError); 
     76    void undo(int n=1); 
     77    void remove(int x, int y); 
     78    char getStatus(int x, int y); 
     79    void setStatus(int x, int y, char val); 
     80    int len_cap_last() throw(BoardError); 
     81    void undostack_append_pass(); 
     82    // abstractBoard& copy(const abstractBoard& ab); 
    8383 
    84        private: 
    85                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); 
    88                char invert(char); 
     84  private: 
     85    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); 
     88    char invert(char); 
    8989}; 
    9090 
  • 06/libkombilo/cpptest.cc

    r186 r188  
    77 
    88int main(int argc, char** argv) { 
    9        GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]]", ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL, 19); 
     9  GameList gl("t1.db", "id", "[[PW]] - [[PB]] ([[winner]]), [[filename.]]", ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL, 19); 
    1010 
    11        if (argc>1 && !strcmp(argv[1], "-p")) { 
    12                gl.start_processing(); 
    13                directory_iterator end_itr; 
    14                // string path = "/home/ug/go/kombilo/06/libkombilo"; 
    15                string path = "/home/ug/go/gtl/reviews"; 
    16                // string path = "/home/ug/go/gogod06/1999"; 
    17                for(directory_iterator it(path); it != end_itr; ++it) { 
    18                        string n = it->string(); 
    19                        if (n.substr(n.size()-4) == ".sgf") { 
    20                                ifstream infile; 
    21                                printf("%s\n", n.c_str()); 
    22                                infile.open(it->native_file_string().c_str()); 
     11  if (argc>1 && !strcmp(argv[1], "-p")) { 
     12    gl.start_processing(); 
     13    directory_iterator end_itr; 
     14    // string path = "/home/ug/go/kombilo/06/libkombilo"; 
     15    string path = "/home/ug/go/gtl/reviews"; 
     16    // string path = "/home/ug/go/gogod06/1999"; 
     17    for(directory_iterator it(path); it != end_itr; ++it) { 
     18      string n = it->string(); 
     19      if (n.substr(n.size()-4) == ".sgf") { 
     20        ifstream infile; 
     21        printf("%s\n", n.c_str()); 
     22        infile.open(it->native_file_string().c_str()); 
    2323 
    24                                string sgf; 
    25                                string line; 
    26                                while (!infile.eof()) { 
    27                                        getline(infile, line); 
    28                                        sgf += line; 
    29                                
    30                                infile.close(); 
    31                                gl.process(sgf.c_str(), path.c_str(), n.c_str());    
    32                        
    33                
    34                gl.finalize_processing(); 
    35                printf("Processed %d games.\n", gl.size()); 
    36        
    37        printf("%d games.\n", gl.size()); 
     24        string sgf; 
     25        string line; 
     26        while (!infile.eof()) { 
     27          getline(infile, line); 
     28          sgf += line; 
     29       
     30        infile.close(); 
     31        gl.process(sgf.c_str(), path.c_str(), n.c_str());    
     32     
     33   
     34    gl.finalize_processing(); 
     35    printf("Processed %d games.\n", gl.size()); 
     36 
     37  printf("%d games.\n", gl.size()); 
    3838 
    39        // gl.gisearch("pw = 'Hane Naoki'"); 
    40        // Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO") ; 
    41        // vector<MoveNC> contList; 
    42        // contList.push_back(MoveNC(6,15,'X')); 
    43        // contList.push_back(MoveNC(6,13,'O')); 
    44        // contList.push_back(MoveNC(4,15,'X')); 
    45        // 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); 
    46        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............."); 
    47        SearchOptions so; 
    48        // so.searchInVariations = false; 
    49        gl.search(p, so); 
    50        printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits()); 
    51        // vector<string> res = gl.currentEntriesAsStrings(); 
    52        // for(vector<string>::iterator it = res.begin(); it != res.end(); it++) 
    53        //      printf("%s\n", it->c_str()); 
     39  // gl.gisearch("pw = 'Hane Naoki'"); 
     40 Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO") ; 
     41  // vector<MoveNC> contList; 
     42  // contList.push_back(MoveNC(6,15,'X')); 
     43  // contList.push_back(MoveNC(6,13,'O')); 
     44  // contList.push_back(MoveNC(4,15,'X')); 
     45  // 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); 
     46  // 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............."); 
     47  SearchOptions so; 
     48  // so.searchInVariations = false; 
     49  gl.search(p, so); 
     50  printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits()); 
     51 vector<string> res = gl.currentEntriesAsStrings(); 
     52 for(vector<string>::iterator it = res.begin(); it != res.end(); it++) 
     53    printf("%s\n", it->c_str()); 
    5454} 
  • 06/libkombilo/search.cc

    r187 r188  
    3232 
    3333Continuation::Continuation() { 
    34        B  = 0; 
    35        W  = 0; 
    36        tB = 0; 
    37        tW = 0; 
    38        wB = 0; 
    39        lB = 0; 
    40        wW = 0; 
    41        lW = 0; 
     34  B  = 0; 
     35  W  = 0; 
     36  tB = 0; 
     37  tW = 0; 
     38  wB = 0; 
     39  lB = 0; 
     40  wW = 0; 
     41  lW = 0; 
    4242} 
    4343 
     
    138138  for(int i=0; i < sizeX*sizeY; i++) 
    139139    if (initialPos[i] != p.initialPos[i]) return 0; 
    140        if (contList != p.contList) return 0; 
     140  if (contList != p.contList) return 0; 
    141141  return 1; 
    142142} 
     
    161161  initialPos = 0; 
    162162  finalPos = 0; 
    163        flip = 0; 
    164        colorSwitch = 0; 
    165        sizeX = 0; 
    166        sizeY = 0; 
     163  flip = 0; 
     164  colorSwitch = 0; 
     165  sizeX = 0; 
     166  sizeY = 0; 
    167167} 
    168168 
     
    174174  sizeY = sY; 
    175175 
    176        if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
     176  if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
    177177    left = right = top = bottom = 0; 
    178        } else if (type == CORNER_NE_PATTERN) { 
    179                top = bottom = 0; 
     178  } else if (type == CORNER_NE_PATTERN) { 
     179    top = bottom = 0; 
    180180    left = right = boardsize -1 - sizeX; 
    181        } else if (type == CORNER_SE_PATTERN) { 
    182                top = bottom = boardsize -1 - sizeY; 
     181  } else if (type == CORNER_SE_PATTERN) { 
     182    top = bottom = boardsize -1 - sizeY; 
    183183    left = right = boardsize -1 - sizeX; 
    184        } else if (type == CORNER_SW_PATTERN) { 
    185                top = bottom = boardsize -1 - sizeY; 
    186                left = right = 0; 
    187        } else if (type == SIDE_N_PATTERN) { 
    188                top = bottom = 0; 
    189                left = 1; 
    190                right = boardsize -1 - sizeX; 
    191        } else if (type == SIDE_E_PATTERN) { 
     184  } else if (type == CORNER_SW_PATTERN) { 
     185    top = bottom = boardsize -1 - sizeY; 
     186    left = right = 0; 
     187  } else if (type == SIDE_N_PATTERN) { 
     188    top = bottom = 0; 
     189    left = 1; 
     190    right = boardsize -1 - sizeX; 
     191  } else if (type == SIDE_E_PATTERN) { 
    192192    left = right = boardsize -1 - sizeX; 
    193                top = 1; 
    194                bottom = boardsize -1 - sizeY; 
    195        } else if (type == SIDE_W_PATTERN) { 
    196                left = right = 0; 
    197                top = 1; 
    198                bottom = boardsize -1 - sizeY; 
    199        } else if (type == SIDE_S_PATTERN) { 
    200                top = bottom = boardsize -1 - sizeY; 
    201                left = 1; 
    202                right = boardsize -1 - sizeX; 
    203        } else if (type == CENTER_PATTERN) { 
    204                left = top = 1; 
    205                right = boardsize -1 - sizeX; 
    206                bottom = boardsize -1 - sizeY; 
    207        
     193    top = 1; 
     194    bottom = boardsize -1 - sizeY; 
     195  } else if (type == SIDE_W_PATTERN) { 
     196    left = right = 0; 
     197    top = 1; 
     198    bottom = boardsize -1 - sizeY; 
     199  } else if (type == SIDE_S_PATTERN) { 
     200    top = bottom = boardsize -1 - sizeY; 
     201    left = 1; 
     202    right = boardsize -1 - sizeX; 
     203  } else if (type == CENTER_PATTERN) { 
     204    left = top = 1; 
     205    right = boardsize -1 - sizeX; 
     206    bottom = boardsize -1 - sizeY; 
     207 
    208208 
    209209  initialPos = new char[sizeX * sizeY]; 
     
    222222  sizeY = sY; 
    223223 
    224        if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
     224  if (type == CORNER_NW_PATTERN || type == FULLBOARD_PATTERN) { 
    225225    left = right = top = bottom = 0; 
    226        } else if (type == CORNER_NE_PATTERN) { 
    227                top = bottom = 0; 
     226  } else if (type == CORNER_NE_PATTERN) { 
     227    top = bottom = 0; 
    228228    left = right = boardsize -1 - sizeX; 
    229        } else if (type == CORNER_SE_PATTERN) { 
    230                top = bottom = boardsize -1 - sizeY; 
     229  } else if (type == CORNER_SE_PATTERN) { 
     230    top = bottom = boardsize -1 - sizeY; 
    231231    left = right = boardsize -1 - sizeX; 
    232        } else if (type == CORNER_SW_PATTERN) { 
    233                top = bottom = boardsize -1 - sizeY; 
    234                left = right = 0; 
    235        } else if (type == SIDE_N_PATTERN) { 
    236                top = bottom = 0; 
    237                left = 1; 
    238                right = boardsize -1 - sizeX; 
    239        } else if (type == SIDE_E_PATTERN) { 
     232  } else if (type == CORNER_SW_PATTERN) { 
     233    top = bottom = boardsize -1 - sizeY; 
     234    left = right = 0; 
     235  } else if (type == SIDE_N_PATTERN) { 
     236    top = bottom = 0; 
     237    left = 1; 
     238    right = boardsize -1 - sizeX; 
     239  } else if (type == SIDE_E_PATTERN) { 
    240240    left = right = boardsize -1 - sizeX; 
    241                top = 1; 
    242                bottom = boardsize -1 - sizeY; 
    243        } else if (type == SIDE_W_PATTERN) { 
    244                left = right = 0; 
    245                top = 1; 
    246                bottom = boardsize -1 - sizeY; 
    247        } else if (type == SIDE_S_PATTERN) { 
    248                top = bottom = boardsize -1 - sizeY; 
    249                left = 1; 
    250                right = boardsize -1 - sizeX; 
    251        } else if (type == CENTER_PATTERN) { 
    252                left = top = 1; 
    253                right = boardsize -1 - sizeX; 
    254                bottom = boardsize -1 - sizeY; 
    255        
     241    top = 1; 
     242    bottom = boardsize -1 - sizeY; 
     243  } else if (type == SIDE_W_PATTERN) { 
     244    left = right = 0; 
     245    top = 1; 
     246    bottom = boardsize -1 - sizeY; 
     247  } else if (type == SIDE_S_PATTERN) { 
     248    top = bottom = boardsize -1 - sizeY; 
     249    left = 1; 
     250    right = boardsize -1 - sizeX; 
     251  } else if (type == CENTER_PATTERN) { 
     252    left = top = 1; 
     253    right = boardsize -1 - sizeX; 
     254    bottom = boardsize -1 - sizeY; 
     255 
    256256 
    257257  initialPos = new char[sizeX * sizeY]; 
     
    285285  } 
    286286 
    287        contList = CONTLIST; 
     287  contList = CONTLIST; 
    288288} 
    289289 
     
    309309    finalPos[i] = p.finalPos[i]; 
    310310  } 
    311        contList = p.contList; 
     311  contList = p.contList; 
    312312} 
    313313 
     
    365365void Pattern::printPattern() { 
    366366  printf("%d, %d, %d, %d\n", left, right, top, bottom); 
    367        printf("%d, %d\n", sizeX, sizeY); 
    368        for(int i=0; i<sizeY; i++) { 
    369                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"); 
     367  printf("%d, %d\n", sizeX, sizeY); 
     368  for(int i=0; i<sizeY; i++) { 
     369    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"); 
    377377} 
    378378 
     
    417417 
    418418  patternList(); 
    419        continuations = new Continuation[pattern.sizeX * pattern.sizeY]; 
     419  continuations = new Continuation[pattern.sizeX * pattern.sizeY]; 
    420420} 
    421421 
    422422PatternList::~PatternList() { 
    423        delete [] continuations; 
     423  delete [] continuations; 
    424424} 
    425425 
     
    479479    for(int i=0; i<pattern.contList.size(); i++) { 
    480480      newContList.push_back(MoveNC(Pattern::flipsX(f, pattern.contList[i].x, pattern.contList[i].y,  
    481                                                                                                 pattern.sizeX-1,pattern.sizeY-1), 
    482                                                                                                                   Pattern::flipsY(f, pattern.contList[i].x, pattern.contList[i].y, 
    483481                                                      pattern.sizeX-1,pattern.sizeY-1), 
    484                                                                                                                                         pattern.contList[i].color)); 
     482                                  Pattern::flipsY(f, pattern.contList[i].x, pattern.contList[i].y, 
     483                                                      pattern.sizeX-1,pattern.sizeY-1), 
     484                                  pattern.contList[i].color)); 
    485485    } 
    486486 
     
    489489 
    490490    pNew.flip = f; 
    491                // printf("new size %d %d\n", pNew.sizeX, pNew.sizeY); 
     491    // printf("new size %d %d\n", pNew.sizeX, pNew.sizeY); 
    492492 
    493493    delete [] newInitialPos; 
     
    513513        } 
    514514      } 
    515                        vector<MoveNC> newContList; 
    516                        for(int i=0; i<pattern.contList.size(); i++) { 
    517                                newContList.push_back(MoveNC(Pattern::flipsX(f, pattern.contList[i].x, pattern.contList[i].y,  
    518                                                                                                                                                                                                                                pattern.sizeX-1,pattern.sizeY-1), 
    519                                                                                                                                                Pattern::flipsY(f, pattern.contList[i].x, pattern.contList[i].y, 
    520                                                                                                                                                                                                                                pattern.sizeX-1,pattern.sizeY-1), 
    521                                                                                                                                                invertColor(pattern.contList[i].color))); 
    522                        
    523  
    524  
    525                        // printf("new size %d %d", newSizeX, newSizeY); 
     515      vector<MoveNC> newContList; 
     516      for(int i=0; i<pattern.contList.size(); i++) { 
     517        newContList.push_back(MoveNC(Pattern::flipsX(f, pattern.contList[i].x, pattern.contList[i].y,  
     518                                                        pattern.sizeX-1,pattern.sizeY-1), 
     519                                    Pattern::flipsY(f, pattern.contList[i].x, pattern.contList[i].y, 
     520                                                        pattern.sizeX-1,pattern.sizeY-1), 
     521                                    invertColor(pattern.contList[i].color))); 
     522     
     523 
     524 
     525      // printf("new size %d %d", newSizeX, newSizeY); 
    526526      Pattern pNew1(newLeft, newRight, newTop, newBottom, newSizeX, newSizeY, 
    527527                    newInitialPos, newContList); 
     
    596596 
    597597  symmetries.push_back(symm); 
    598        vector<Pattern>::iterator it = data.begin(); 
    599        it++; 
    600        for(; it != data.end(); it++) { 
    601                // printf("ne %d, %d\n", it->sizeX, it->sizeY); 
    602                int f = it->flip; 
    603                Symmetries s(it->sizeX, it->sizeY); 
    604                for(int i=0; i<pattern.sizeX; i++) { 
    605                        for(int j=0; j<pattern.sizeY; j++) { 
    606                                if (!it->colorSwitch) { 
    607                                                s.set(Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
    608                                                                        Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
    609                                                                        symm.getX(i,j), symm.getY(i,j), symm.getCS(i,j)); 
    610                                } else { 
    611                                                s.set(Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
    612                                                                        Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
    613                                                                        symm.getX(i,j), symm.getY(i,j), 1-symm.getCS(i,j)); 
    614                                
    615                        
    616                
    617                symmetries.push_back(s); 
    618        
     598  vector<Pattern>::iterator it = data.begin(); 
     599  it++; 
     600  for(; it != data.end(); it++) { 
     601    // printf("ne %d, %d\n", it->sizeX, it->sizeY); 
     602    int f = it->flip; 
     603    Symmetries s(it->sizeX, it->sizeY); 
     604    for(int i=0; i<pattern.sizeX; i++) { 
     605      for(int j=0; j<pattern.sizeY; j++) { 
     606        if (!it->colorSwitch) { 
     607            s.set(Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
     608                  Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
     609                  symm.getX(i,j), symm.getY(i,j), symm.getCS(i,j)); 
     610        } else { 
     611            s.set(Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
     612                  Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1),  
     613                  symm.getX(i,j), symm.getY(i,j), 1-symm.getCS(i,j)); 
     614       
     615     
     616   
     617    symmetries.push_back(s); 
     618 
    619619} 
    620620 
     
    631631 
    632632char* 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          
     633  // char* re = new char[3]; 
     634  // re[0] = 0; 
     635  // re[1] = 0; 
     636  // re[2] = 0; 
     637  // return re; 
     638   
    639639  char xx; 
    640        char yy; 
    641        char cSymm; 
    642        char cc; 
    643        xx = symmetries[index].getX(x,y); 
    644        yy = symmetries[index].getY(x,y); 
    645        cSymm = symmetries[index].getCS(x,y); 
    646        if (co == 'X') { 
    647                if (cSymm) cc = 'W'; else cc = 'B'; 
    648        } else { 
    649                if (cSymm) cc = 'B'; else cc = 'W'; 
    650