Changeset 244 for 06/libkombilo/abstractboard.cpp
- Timestamp:
- 03/24/07 03:21:42 (1 year ago)
- Files:
-
- 06/libkombilo/abstractboard.cpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/abstractboard.cpp
r239 r244 82 82 83 83 abstractBoard::abstractBoard(int bs) throw(BoardError) { 84 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 0\n");85 84 boardsize = bs; 86 if (boardsize < 3) throw BoardError(); // FIXME85 if (boardsize < 1) throw BoardError(); 87 86 status = new char[boardsize*boardsize+1]; 88 87 for (int i = 0; i < boardsize*boardsize; i++) 89 88 status[i] = ' '; 90 89 status[boardsize*boardsize] = 0; 91 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 100\n");92 90 } 93 91 94 92 abstractBoard::abstractBoard(const abstractBoard& ab) { 95 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 0\n");96 93 boardsize = ab.boardsize; 97 94 status = new char[boardsize*boardsize+1]; … … 100 97 status[boardsize*boardsize] = 0; 101 98 undostack = stack<Move>(ab.undostack); 102 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n");103 99 } 104 100 105 101 abstractBoard& abstractBoard::operator=(const abstractBoard& ab) { 106 if (DEBUG_ABSTRACTBOARD) printf("AB::operator= 0\n");107 102 if (this != &ab) { 108 103 boardsize = ab.boardsize; … … 113 108 status[boardsize*boardsize] = 0; 114 109 undostack = stack<Move>(ab.undostack); 115 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n");116 110 } 117 111 return *this; … … 119 113 120 114 abstractBoard::~abstractBoard() { 121 if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 0\n");122 115 delete [] status; 123 if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 100\n");124 116 } 125 117 126 118 // abstractBoard& abstractBoard::copy(const abstractBoard& ab) { 127 // if (DEBUG_ABSTRACTBOARD) printf("AB::copy 0\n");128 119 // printf("copy assignment operator\n"); 129 120 // if (this != &ab) { … … 136 127 // undostack = ab.undostack; 137 128 // } 138 // if (DEBUG_ABSTRACTBOARD) printf("AB::copy 100\n");139 129 // return *this; 140 130 // } 141 131 142 132 char abstractBoard::getStatus(int x, int y) { 143 if (DEBUG_ABSTRACTBOARD) printf("AB::getStatus 0\n");144 133 return status[boardsize*x + y]; 145 134 } 146 135 147 136 void abstractBoard::setStatus(int x, int y, char val) { 148 if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 0\n");149 137 if (val=='b' || val=='B') status[boardsize*x + y] = 'B'; 150 138 else if (val=='w' || val=='W') status[boardsize*x + y] = 'W'; 151 139 else status[boardsize*x + y] = val; 152 if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 100\n");153 140 } 154 141 155 142 int abstractBoard::len_cap_last() throw(BoardError) { 156 if (DEBUG_ABSTRACTBOARD) printf("AB::len_cap_last 0\n");157 143 if (!undostack.size()) throw BoardError(); 158 144 Move m = undostack.top(); … … 162 148 163 149 void abstractBoard::undostack_append_pass() { 164 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 0\n");165 150 undostack.push(Move(19,19,'-')); 166 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 100\n");167 151 } 168 152 … … 184 168 185 169 int abstractBoard::play(int x, int y, char* color) throw (BoardError) { 186 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) 0\n");187 170 if (x<0 || x>=boardsize || y<0 || y>=boardsize) return 0; 188 171 if (status[boardsize*x+y] != ' ') { … … 199 182 else delete captures; 200 183 undostack.push(m); 201 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret1 100\n");202 184 return 1; 203 185 } 204 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret0 200\n");205 186 return 0; 206 187 } 207 188 208 189 vector<p_cc>* abstractBoard::legal(int x, int y, char color) { 209 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 0\n");210 190 vector<p_cc>* c = new vector<p_cc>; 211 191 int* nb = neighbors(x,y); … … 215 195 if (status[boardsize*x1 + y1] == invert(color)) { 216 196 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());219 197 vector<p_cc>::iterator it; 220 198 for(it = d->begin(); it != d->end(); it++) c->push_back(*it); 221 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 41\n");222 199 delete d; 223 200 } 224 201 } 225 202 delete [] nb; 226 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 42\n");227 203 setStatus(x,y,color); 228 204 … … 243 219 } 244 220 delete c; 245 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 98\n");246 221 return captures; 247 222 } 248 223 delete c; 249 224 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());252 225 if (d->size()) { 253 226 delete d; 254 227 status[boardsize*x + y] = ' '; 255 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 99\n");256 228 return 0; 257 229 } … … 259 231 delete d; 260 232 vector<p_cc>* ret = new vector<p_cc>(); 261 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 100\n");262 233 return ret; 263 234 } … … 265 236 266 237 vector<p_cc>* abstractBoard::hasNoLibExcP(int x1, int y1, int exc) { 267 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n");268 238 vector<p_cc>* st = new vector<p_cc>; 269 239 vector<p_cc>* newlyFound = new vector<p_cc>; … … 280 250 int y = it1->second; 281 251 int* nbs = neighbors(x,y); 282 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 7 (%d,%d) %d\n",x, y,nbs[0]);283 252 for (int j=1; j <= nbs[0]; j++) { 284 253 int yy1 = nbs[j]; 285 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 99\n");286 254 if (status[yy1] == ' ' && yy1 != exc) { 287 255 delete [] nbs; … … 322 290 vector<p_cc>::iterator it; 323 291 for(it=newlyFound->begin(); it!=newlyFound->end(); it++) { 324 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 10, (%d,%d)\n", it->first, it->second);325 292 st->push_back(*it); 326 293 } … … 328 295 newlyFound = n; 329 296 } 330 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n");331 297 delete n; 332 298 return st; … … 334 300 335 301 void abstractBoard::undo(int n) { 336 if (DEBUG_ABSTRACTBOARD) printf("AB::undo 0\n");337 302 for(int i=0; i<n; i++) { 338 if (DEBUG_ABSTRACTBOARD) printf("AB::undo 1 %d\n", i);339 303 if (undostack.size()) { 340 304 Move tuple = undostack.top(); … … 355 319 } 356 320 } 357 if (DEBUG_ABSTRACTBOARD) printf("AB::undo 100\n");358 321 } 359 322 360 323 void abstractBoard::remove(int x, int y) { 361 if (DEBUG_ABSTRACTBOARD) printf("AB::remove 0\n");362 324 undostack.push(Move(-1, -1, invert(status[boardsize*x+y]))); 363 325 status[boardsize*x+y] = ' '; 364 if (DEBUG_ABSTRACTBOARD) printf("AB::remove 100\n");365 326 } 366 327
