Changeset 151
- Timestamp:
- 04/14/04 20:25:18 (5 years ago)
- Files:
-
- 06/devel/abstractBoard.cc (modified) (16 diffs)
- 06/devel/abstractBoard.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/devel/abstractBoard.cc
r140 r151 74 74 75 75 abstractBoard::abstractBoard(int bs) throw(BoardError) { 76 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 0\n"); 76 77 boardsize = bs; 77 78 if (boardsize < 3) throw BoardError(); … … 80 81 status[i] = ' '; 81 82 status[boardsize*boardsize] = 0; 83 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(int) 100\n"); 82 84 } 83 85 84 86 85 87 abstractBoard::abstractBoard(const abstractBoard& ab) { 88 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 0\n"); 86 89 printf("copy constructor\n"); 87 90 boardsize = ab.boardsize; … … 91 94 status[boardsize*boardsize] = 0; 92 95 undostack = stack<Move>(ab.undostack); 96 if (DEBUG_ABSTRACTBOARD) printf("AB::abstractBoard(abstractBoard) 100\n"); 93 97 } 94 98 95 99 96 100 abstractBoard::~abstractBoard() { 101 if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 0\n"); 97 102 delete []status; 103 if (DEBUG_ABSTRACTBOARD) printf("AB::~abstractBoard 100\n"); 98 104 } 99 105 100 106 abstractBoard& abstractBoard::copy(const abstractBoard& ab) { 107 if (DEBUG_ABSTRACTBOARD) printf("AB::copy 0\n"); 101 108 printf("copy assignment operator\n"); 102 109 if (this != &ab) { … … 109 116 undostack = ab.undostack; 110 117 } 118 if (DEBUG_ABSTRACTBOARD) printf("AB::copy 100\n"); 111 119 return *this; 112 120 } 113 121 114 122 char abstractBoard::getStatus(int x, int y) { 123 if (DEBUG_ABSTRACTBOARD) printf("AB::getStatus 0\n"); 115 124 return status[boardsize*x + y]; 116 125 } … … 118 127 119 128 void abstractBoard::setStatus(int x, int y, char val) { 129 if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 0\n"); 120 130 if (val=='b' || val=='B') status[boardsize*x + y] = 'B'; 121 131 else if (val=='w' || val=='W') status[boardsize*x + y] = 'W'; 122 132 else status[boardsize*x + y] = val; 133 if (DEBUG_ABSTRACTBOARD) printf("AB::setStatus 100\n"); 123 134 } 124 135 125 136 126 137 int abstractBoard::len_cap_last() { 138 if (DEBUG_ABSTRACTBOARD) printf("AB::len_cap_last 0\n"); 127 139 if (!undostack.size()) { 128 140 return -1; … … 135 147 136 148 PyObject* abstractBoard::get_cap_last() { 149 if (DEBUG_ABSTRACTBOARD) printf("AB::get_cap_last 0\n"); 137 150 if (!undostack.size()) { 138 151 Py_INCREF(Py_None); … … 145 158 for(it = m.captures->begin(); it != m.captures->end(); it++) 146 159 PyList_Append(cap, Py_BuildValue("(ii)", it->first, it->second)); 160 if (DEBUG_ABSTRACTBOARD) printf("AB::get_cap_last 100\n"); 147 161 return cap; 148 162 } 149 163 150 164 PyObject* abstractBoard::undostack_pop() { 165 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_pop 0\n"); 151 166 if (!undostack.size()) { 152 167 Py_INCREF(Py_None); … … 161 176 PyList_Append(cap, Py_BuildValue("(ii)", it->first, it->second)); 162 177 } 178 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_pop 100\n"); 163 179 return Py_BuildValue("(ii)cO", m.x, m.y, m.c, cap); 164 180 } 165 181 166 182 void abstractBoard::undostack_append_pass() { 183 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 0\n"); 167 184 undostack.push(Move(20,20,'-')); 185 if (DEBUG_ABSTRACTBOARD) printf("AB::undostack_append_pass 100\n"); 168 186 } 169 187 170 188 int abstractBoard::len_undostack() { 189 if (DEBUG_ABSTRACTBOARD) printf("AB::len_undostack 0\n"); 171 190 return undostack.size(); 172 191 } … … 193 212 194 213 int abstractBoard::play(PyObject* pos, char* color) throw(BoardError) { 214 if (DEBUG_ABSTRACTBOARD) printf("AB::play(PyObject*,char*) 0\n"); 195 215 int x = PyInt_AsLong(PyTuple_GetItem(pos,0)); 196 216 int y = PyInt_AsLong(PyTuple_GetItem(pos,1)); … … 200 220 201 221 int abstractBoard::play(int x, int y, char* color) throw (BoardError) { 222 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) 0\n"); 202 223 if (x<0 || x>=boardsize || y<0 || y>=boardsize) return 0; 203 224 if (status[boardsize*x+y] != ' ') { … … 216 237 else delete captures; 217 238 undostack.push(m); 239 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret1 100\n"); 218 240 return 1; 219 241 } 242 if (DEBUG_ABSTRACTBOARD) printf("AB::play(int,int,char*) ret0 200\n"); 220 243 return 0; 221 244 } … … 223 246 224 247 vector<p_cc>* abstractBoard::legal(int x, int y, char color) { 248 if (DEBUG_ABSTRACTBOARD) printf("AB::legal 0\n"); 225 249 vector<p_cc>* c = new vector<p_cc>; 226 250 int* nb = neighbors(x,y); … … 270 294 } 271 295 272 273 274 296 vector<p_cc>* abstractBoard::hasNoLibExcP(int x1, int y1, int exc) { 297 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 0\n"); 275 298 vector<p_cc>* st = new vector<p_cc>; 276 299 vector<p_cc> newlyFound; … … 324 347 newlyFound = n; 325 348 } 349 if (DEBUG_ABSTRACTBOARD) printf("AB::hasNoLibExcP 100\n"); 326 350 return st; 327 351 } … … 329 353 330 354 void abstractBoard::undo(int n) { 355 if (DEBUG_ABSTRACTBOARD) printf("AB::undo 0\n"); 331 356 for(int i=0; i<n; i++) { 332 357 if (undostack.size()) { … … 346 371 } 347 372 } 373 if (DEBUG_ABSTRACTBOARD) printf("AB::undo 100\n"); 348 374 } 349 375 350 376 351 377 void abstractBoard::remove(int x, int y) { 378 if (DEBUG_ABSTRACTBOARD) printf("AB::remove 0\n"); 352 379 PyObject* l = PyList_New(0); 353 380 PyList_Append(l, Py_BuildValue("(ii)", x, y)); 354 381 undostack.push(Move(-1, -1, invert(status[boardsize*x+y]))); 355 382 status[boardsize*x+y] = ' '; 383 if (DEBUG_ABSTRACTBOARD) printf("AB::remove 100\n"); 356 384 } 357 385 06/devel/abstractBoard.h
r140 r151 30 30 #include <utility> 31 31 #include <stack> 32 33 const int DEBUG_ABSTRACTBOARD = 1; 34 32 35 33 36 class BoardError {
