Changeset 152

Show
Ignore:
Timestamp:
04/14/04 22:27:13 (4 years ago)
Author:
ug
Message:

Fix abstractBoard.cc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/abstractBoard.cc

    r151 r152  
    254254    if (status[boardsize*x1 + y1] == invert(color)) { 
    255255      vector<p_cc>* d = hasNoLibExcP(x1, y1, x*boardsize+y); 
     256      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 39\n"); 
     257      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 40, %d\n", d->size()); 
    256258      vector<p_cc>::iterator it; 
    257       for(it = d->begin(); it != d->end(); d++) c->push_back(*it); 
     259      for(it = d->begin(); it != d->end(); it++) c->push_back(*it); 
     260      if (DEBUG_ABSTRACTBOARD) printf("AB::legal 41\n"); 
    258261      delete d; 
    259262    } 
    260263  } 
    261    
     264  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 42\n"); 
    262265  setStatus(x,y,color); 
    263266 
     
    278281    } 
    279282    delete c; 
     283    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 98\n"); 
    280284    return captures; 
    281285  } 
    282286  delete c; 
    283287  vector<p_cc>* d = hasNoLibExcP(x, y); 
     288  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 49\n"); 
     289  if (DEBUG_ABSTRACTBOARD) printf("AB::legal 50, %d\n", d->size()); 
    284290  if (d->size()) { 
    285291    delete d; 
    286292    status[boardsize*x + y] = ' '; 
     293    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 99\n"); 
    287294    return 0; 
    288295  } 
     
    290297    delete d; 
    291298    vector<p_cc>* ret = new vector<p_cc>(); 
     299    if (DEBUG_ABSTRACTBOARD) printf("AB::legal 100\n"); 
    292300    return ret; 
    293301  } 
     
    297305  if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n"); 
    298306  vector<p_cc>* st = new vector<p_cc>; 
    299   vector<p_cc> newlyFound
    300   newlyFound.push_back(p_cc(x1, y1)); 
    301  
     307  vector<p_cc>* newlyFound = new vector<p_cc>
     308  newlyFound->push_back(p_cc(x1, y1)); 
     309  vector<p_cc>* n; 
    302310  int foundNew = 1; 
    303311         
    304312  while (foundNew) { 
    305313    foundNew = 0; 
    306     vector<p_cc> n
    307     for(unsigned int i=0; i < newlyFound.size(); i++) { 
    308       p_cc tup = newlyFound[i]; 
    309       int x = tup.first; 
    310       int y = tup.second; 
     314    n = new vector<p_cc>
     315    vector<p_cc>::iterator it1; 
     316    for(it1=newlyFound->begin(); it1!=newlyFound->end(); it1++) { 
     317      int x = it1->first; 
     318      int y = it1->second; 
    311319      int* nbs = neighbors(x,y); 
     320      if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 7 (%d,%d) %d\n",x, y,nbs[0]); 
    312321      for (int j=1; j <= nbs[0]; j++) { 
    313322        int yy1 = nbs[j]; 
     323        if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 99\n"); 
    314324        if (status[yy1] == ' ' && yy1 != exc) { 
    315325          delete [] nbs; 
     
    317327        } 
    318328        else { 
    319           p_cc yy(yy1/boardsize, yy1%boardsize); 
    320329          if (status[yy1]==status[x*boardsize+y]) { 
    321             foundNew = 1; 
     330            p_cc yy(yy1/boardsize, yy1%boardsize); 
     331            int foundNewHere = 1; 
    322332            vector<p_cc>::iterator it; 
    323333            for(it = st->begin(); it!=st->end(); it++) { 
    324334              if (it->first==yy.first && it->second==yy.second) { 
    325                 foundNew = 0; 
     335                foundNewHere = 0; 
    326336                break; 
    327337              } 
    328338            } 
    329             if (foundNew) { 
    330               for(it=newlyFound.begin(); it!=newlyFound.end(); it++) { 
     339            if (foundNewHere) { 
     340              for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
    331341                if (it->first==yy.first && it->second==yy.second) { 
    332                   foundNew = 0; 
     342                  foundNewHere = 0; 
    333343                  break; 
    334344                } 
    335345              } 
    336346            } 
    337             if (foundNew) n.push_back(yy); 
     347            if (foundNewHere) { 
     348              n->push_back(yy); 
     349              foundNew = 1; 
     350            } 
    338351          } 
    339352        } 
     
    343356     
    344357    vector<p_cc>::iterator it; 
    345     for(it=newlyFound.begin(); it!=newlyFound.end(); it++) 
     358    for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
     359      if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 10, (%d,%d)\n", it->first, it->second); 
    346360      st->push_back(*it); 
     361    } 
     362    delete newlyFound; 
    347363    newlyFound = n; 
    348364  } 
    349365  if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n"); 
     366  delete n; 
    350367  return st; 
    351368} 
     
    355372  if (DEBUG_ABSTRACTBOARD) printf("AB::undo 0\n"); 
    356373  for(int i=0; i<n; i++) { 
     374    if (DEBUG_ABSTRACTBOARD) printf("AB::undo 1 %d\n", i); 
    357375    if (undostack.size()) { 
    358376      Move tuple = undostack.top(); 
     
    365383 
    366384      status[x*boardsize+y] = ' '; 
    367       for(unsigned int i=0; i < captures->size(); i++) { 
    368         p_cc t = (*captures)[i]; 
    369         setStatus(t.first, t.second, invert(color)); 
     385      if (captures) { 
     386        for(unsigned int i=0; i < captures->size(); i++) { 
     387          p_cc t = (*captures)[i]; 
     388          setStatus(t.first, t.second, invert(color)); 
     389        } 
    370390      } 
    371391    } 
  • 06/devel/abstractBoard.h

    r151 r152  
    3131#include <stack> 
    3232 
    33 const int DEBUG_ABSTRACTBOARD = 1
     33const int DEBUG_ABSTRACTBOARD = 0
    3434 
    3535 
  • 06/devel/abstractBoardPY.py

    r123 r152  
    171171            for x in newlyFound: 
    172172                for y in self.neighbors(x): 
    173                     if not self.getStatus(y[0], y[1]) != ' ' and y != exc:    # found a liberty 
     173                    if self.getStatus(y[0], y[1]) == ' ' and y != exc:    # found a liberty 
    174174                        return [] 
    175                     elif self.getStatus(y[0],y[1])!=' ' and self.getStatus(y[0],y[1])==self.getStatus(x[0],x[1]) \ 
     175                    elif self.getStatus(y[0],y[1])==self.getStatus(x[0],x[1]) \ 
    176176                         and not y in st and not y in newlyFound: # found another stone of same color 
    177177                        n.append(y) 
  • 06/devel/board.py

    r147 r152  
    3030import sys 
    3131import os 
    32 #try: 
    33 #    from abstractBoard import * 
    34 #except ImportError: 
    35 from abstractBoardPY import * 
     32try: 
     33    from abstractBoard import * 
     34except ImportError: 
     35    from abstractBoardPY import * 
    3636 
    3737 
  • 06/devel/kombilo.py

    r147 r152  
    5353import webbrowser 
    5454 
    55 #try: 
    56 #    from abstractBoard import * 
    57 #except ImportError: 
    58 #    print 'ouch' # FIXME 
    59 from abstractBoardPY import * 
     55try: 
     56    from abstractBoard import * 
     57except ImportError: 
     58    print 'ouch' # FIXME 
     59    from abstractBoardPY import * 
    6060from board import * 
    6161import v 
  • 06/devel/v.py

    r147 r152  
    4545    from sgfparser import Node, Cursor, SGFError, SGFescape 
    4646 
    47 # try: 
    48 #     from abstractBoard import * 
    49 # except ImportError: 
    50 #     # print 'ouch' # FIXME 
    51 from abstractBoardPY import * 
     47try: 
     48    from abstractBoard import * 
     49except ImportError: 
     50    # print 'ouch' # FIXME 
     51    from abstractBoardPY import * 
    5252from board import * 
    5353# from gtp import GTP