Changeset 244

Show
Ignore:
Timestamp:
03/24/07 03:21:42 (1 year ago)
Author:
ug
Message:

Fix bug about small board size.

Files:

Legend:

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

    r239 r244  
    8282 
    8383abstractBoard::abstractBoard(int bs) throw(BoardError) { 
    84   if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 0\n"); 
    8584  boardsize = bs; 
    86   if (boardsize < 3) throw BoardError(); // FIXME 
     85  if (boardsize < 1) throw BoardError(); 
    8786  status = new char[boardsize*boardsize+1]; 
    8887  for (int i = 0; i < boardsize*boardsize; i++) 
    8988      status[i] = ' '; 
    9089  status[boardsize*boardsize] = 0; 
    91   if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 100\n"); 
    9290} 
    9391 
    9492abstractBoard::abstractBoard(const abstractBoard& ab) { 
    95   if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 0\n"); 
    9693  boardsize = ab.boardsize; 
    9794  status = new char[boardsize*boardsize+1]; 
     
    10097  status[boardsize*boardsize] = 0; 
    10198  undostack = stack<Move>(ab.undostack); 
    102   if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n"); 
    10399} 
    104100 
    105101abstractBoard& abstractBoard::operator=(const abstractBoard& ab) { 
    106   if (DEBUG_ABSTRACTBOARD) printf("AB::operator= 0\n"); 
    107102  if (this != &ab) { 
    108103    boardsize = ab.boardsize; 
     
    113108    status[boardsize*boardsize] = 0; 
    114109    undostack = stack<Move>(ab.undostack); 
    115     if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n"); 
    116110  } 
    117111  return *this; 
     
    119113 
    120114abstractBoard::~abstractBoard() { 
    121   if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 0\n"); 
    122115  delete [] status; 
    123   if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 100\n"); 
    124116} 
    125117 
    126118// abstractBoard& abstractBoard::copy(const abstractBoard& ab) { 
    127 //   if (DEBUG_ABSTRACTBOARD) printf("AB::copy 0\n"); 
    128119//   printf("copy assignment operator\n"); 
    129120//   if (this != &ab) { 
     
    136127//     undostack = ab.undostack; 
    137128//   } 
    138 //   if (DEBUG_ABSTRACTBOARD) printf("AB::copy 100\n"); 
    139129//   return *this; 
    140130// } 
    141131 
    142132char abstractBoard::getStatus(int x, int y) { 
    143   if (DEBUG_ABSTRACTBOARD) printf("AB::getStatus 0\n"); 
    144133  return status[boardsize*x + y]; 
    145134} 
    146135 
    147136void abstractBoard::setStatus(int x, int y, char val) { 
    148   if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 0\n"); 
    149137  if (val=='b' || val=='B') status[boardsize*x + y] = 'B'; 
    150138  else if (val=='w' || val=='W') status[boardsize*x + y] = 'W'; 
    151139  else status[boardsize*x + y] = val; 
    152   if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 100\n"); 
    153140} 
    154141 
    155142int abstractBoard::len_cap_last() throw(BoardError) { 
    156   if (DEBUG_ABSTRACTBOARD) printf("AB::len_cap_last 0\n"); 
    157143  if (!undostack.size()) throw BoardError(); 
    158144  Move m = undostack.top(); 
     
    162148 
    163149void abstractBoard::undostack_append_pass() { 
    164   if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 0\n"); 
    165150  undostack.push(Move(19,19,'-')); 
    166   if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 100\n"); 
    167151} 
    168152 
     
    184168 
    185169int abstractBoard::play(int x, int y, char* color) throw (BoardError) { 
    186   if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) 0\n"); 
    187170  if (x<0 || x>=boardsize || y<0 || y>=boardsize) return 0; 
    188171  if (status[boardsize*x+y] != ' ') { 
     
    199182    else delete captures; 
    200183    undostack.push(m); 
    201     if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret1 100\n"); 
    202184    return 1; 
    203185  }  
    204   if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret0 200\n"); 
    205186  return 0; 
    206187} 
    207188 
    208189vector<p_cc>* abstractBoard::legal(int x, int y, char color) { 
    209   if (DEBUG_ABSTRACTBOARD) printf("AB::legal 0\n"); 
    210190  vector<p_cc>* c = new vector<p_cc>; 
    211191  int* nb = neighbors(x,y); 
     
    215195    if (status[boardsize*x1 + y1] == invert(color)) { 
    216196      vector<p_cc>* d = hasNoLibExcP(x1, y1, x*boardsize+y); 
    217       if (DEBUG_ABSTRACTBOARD) printf("AB::legal 39\n"); 
    218       if (DEBUG_ABSTRACTBOARD) printf("AB::legal 40, %d\n", d->size()); 
    219197      vector<p_cc>::iterator it; 
    220198      for(it = d->begin(); it != d->end(); it++) c->push_back(*it); 
    221       if (DEBUG_ABSTRACTBOARD) printf("AB::legal 41\n"); 
    222199      delete d; 
    223200    } 
    224201  } 
    225202  delete [] nb; 
    226   if (DEBUG_ABSTRACTBOARD) printf("AB::legal 42\n"); 
    227203  setStatus(x,y,color); 
    228204 
     
    243219    } 
    244220    delete c; 
    245     if (DEBUG_ABSTRACTBOARD) printf("AB::legal 98\n"); 
    246221    return captures; 
    247222  } 
    248223  delete c; 
    249224  vector<p_cc>* d = hasNoLibExcP(x, y); 
    250   if (DEBUG_ABSTRACTBOARD) printf("AB::legal 49\n"); 
    251   if (DEBUG_ABSTRACTBOARD) printf("AB::legal 50, %d\n", d->size()); 
    252225  if (d->size()) { 
    253226    delete d; 
    254227    status[boardsize*x + y] = ' '; 
    255     if (DEBUG_ABSTRACTBOARD) printf("AB::legal 99\n"); 
    256228    return 0; 
    257229  } 
     
    259231    delete d; 
    260232    vector<p_cc>* ret = new vector<p_cc>(); 
    261     if (DEBUG_ABSTRACTBOARD) printf("AB::legal 100\n"); 
    262233    return ret; 
    263234  } 
     
    265236 
    266237vector<p_cc>* abstractBoard::hasNoLibExcP(int x1, int y1, int exc) { 
    267   if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n"); 
    268238  vector<p_cc>* st = new vector<p_cc>; 
    269239  vector<p_cc>* newlyFound = new vector<p_cc>; 
     
    280250      int y = it1->second; 
    281251      int* nbs = neighbors(x,y); 
    282       if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 7 (%d,%d) %d\n",x, y,nbs[0]); 
    283252      for (int j=1; j <= nbs[0]; j++) { 
    284253        int yy1 = nbs[j]; 
    285         if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 99\n"); 
    286254        if (status[yy1] == ' ' && yy1 != exc) { 
    287255          delete [] nbs; 
     
    322290    vector<p_cc>::iterator it; 
    323291    for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 
    324       if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 10, (%d,%d)\n", it->first, it->second); 
    325292      st->push_back(*it); 
    326293    } 
     
    328295    newlyFound = n; 
    329296  } 
    330   if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n"); 
    331297  delete n; 
    332298  return st; 
     
    334300 
    335301void abstractBoard::undo(int n) { 
    336   if (DEBUG_ABSTRACTBOARD) printf("AB::undo 0\n"); 
    337302  for(int i=0; i<n; i++) { 
    338     if (DEBUG_ABSTRACTBOARD) printf("AB::undo 1 %d\n", i); 
    339303    if (undostack.size()) { 
    340304      Move tuple = undostack.top(); 
     
    355319    } 
    356320  }   
    357   if (DEBUG_ABSTRACTBOARD) printf("AB::undo 100\n"); 
    358321} 
    359322 
    360323void abstractBoard::remove(int x, int y) { 
    361   if (DEBUG_ABSTRACTBOARD) printf("AB::remove 0\n"); 
    362324  undostack.push(Move(-1, -1, invert(status[boardsize*x+y]))); 
    363325  status[boardsize*x+y] = ' '; 
    364   if (DEBUG_ABSTRACTBOARD) printf("AB::remove 100\n"); 
    365326} 
    366327 
  • 06/libkombilo/cpptest.cpp

    r239 r244  
    2929    gl.start_processing(); 
    3030    directory_iterator end_itr; 
    31     // string path = "/home/ug/go/kombilo/06/libkombilo"; 
     31    string path = "/home/ug/go/kombilo/06/tests1/libkombilo"; 
    3232    // string path = "/home/ug/go/gtl/reviews"; 
    33     string path = "/home/ug/go/gogod06/1998"; 
     33    // string path = "/home/ug/go/gogod06/1998"; 
    3434    int counter = 0; 
    3535    for(directory_iterator it(path); it != end_itr; ++it) { 
  • 06/libkombilo/search.cpp

    r239 r244  
    45544554    if (sz=="") sz = "19"; 
    45554555    int bs = atoi(sz.c_str()); 
    4556     if (bs < 3) {  
     4556    if (bs < 1) {  
    45574557      return_val |= UNACCEPTABLE_BOARDSIZE;  
    45584558      process_results_vector.push_back(return_val); 
    4559       delete [] rootNodeProperties; 
     4559      delete rootNodeProperties; 
    45604560      root = root->down; 
    45614561      pos++;