Changeset 153 for 06/devel/pattern.cc
- Timestamp:
- 04/15/04 16:23:16 (5 years ago)
- Files:
-
- 1 modified
-
06/devel/pattern.cc (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
06/devel/pattern.cc
r138 r153 36 36 dataCS[i] = -1; 37 37 } 38 } 38 special = -1; 39 } 40 39 41 40 42 Symmetries::~Symmetries() { … … 47 49 sizeX = s.sizeX; 48 50 sizeY = s.sizeY; 49 data X = new int[sizeX*sizeY];51 dataX = new int[sizeX*sizeY]; 50 52 dataY = new int[sizeX*sizeY]; 51 53 dataCS = new int[sizeX*sizeY]; … … 55 57 dataCS[i] = s.dataCS[i]; 56 58 } 59 special = s.special; 57 60 } 58 61 … … 64 67 delete [] dataY; 65 68 delete [] dataCS; 66 data X = new int[sizeX*sizeY];69 dataX = new int[sizeX*sizeY]; 67 70 dataY = new int[sizeX*sizeY]; 68 71 dataCS = new int[sizeX*sizeY]; … … 72 75 dataCS[i] = s.dataCS[i]; 73 76 } 77 special = s.special; 74 78 } 75 79 return *this; … … 116 120 // ----------- class Pattern ----------------------------------------------- 117 121 118 int Pattern::operator==(const &Patternp) {122 int Pattern::operator==(const Pattern& p) { 119 123 if (sizeX != p.sizeX || sizeY != p.sizeY) return 0; 120 124 if (left != p.left || right != p.right || top != p.top || bottom != p.bottom) return 0; 121 125 if (moveOne != p.moveOne) return 0; 122 126 for(int i=0; i < sizeX*sizeY; i++) 123 if (initial Data[i] != p.initialData[i]) return 0;127 if (initialPos[i] != p.initialPos[i]) return 0; 124 128 for(int i=0; i < 4*lenContList; i++) 125 129 if (contList[i] != p.contList[i]) return 0; … … 142 146 } 143 147 144 char getBits(int b, int i) {148 char Pattern::getBits(int b, int i) { 145 149 return bits[b][i]; 150 } 151 152 153 Pattern::Pattern() { 154 // FIXME?! 146 155 } 147 156 … … 151 160 flip = 0; 152 161 colorSwitch = 0; 153 if (mOne=='B' || mOne=='X') moveOne = 'X' 162 if (mOne=='B' || mOne=='X') moveOne = 'X'; 154 163 else moveOne = 'O'; 155 164 if (moveOne == 'X') moveTwo = 'O'; … … 176 185 if (lenCList) { 177 186 contList = new char[lenCList*4]; 178 for(int i=0; i<4*lenC list; i++) contList[i] = cList[i];187 for(int i=0; i<4*lenCList; i++) contList[i] = cList[i]; 179 188 for(int i=0; i<lenContList; i++) { 180 189 finalPos[contList[4*i] + sizeX * contList[4*i+1]] = BW2XO(contList[4*i+2]); … … 195 204 for(int k1=0; k1 < yBlocks; k1++) { 196 205 char nlist[400]; 197 nlistIndex = 0;206 int nlistIndex = 0; 198 207 199 208 for(int k2; k2 < xBlocks; k2++) { … … 226 235 } 227 236 char* nB = new char[nextBlockIndex]; 228 for(int i =0; i<nextBlockIndex; i++) nB[i] = nextBlock[i];237 for(int ii=0; ii<nextBlockIndex; ii++) nB[ii] = nextBlock[ii]; 229 238 bits[2*i + j] = nB; 230 239 delete [] nextBlock; … … 266 275 } 267 276 268 Pattern& Pattern:: operator=(const Pattern& p) {277 Pattern& Pattern::copy(const Pattern& p) { 269 278 if (&p != this) { 270 279 left = p.left; … … 297 306 else contList = 0; 298 307 308 printf("OUCH problem with copying bits ...\n"); // FIXME 299 309 for(int i=0; i<4; i++) { 300 bits[i] = ...; // FIXME310 bits[i] = 0; // FIXME 301 311 } 302 312 } … … 305 315 306 316 307 staticint Pattern::flipsX(int i, int x, int y, int XX, int YY) {317 int Pattern::flipsX(int i, int x, int y, int XX, int YY) { 308 318 if (i==0) return x; 309 319 if (i==1) return XX-x; … … 317 327 } 318 328 319 staticint Pattern::flipsY(int i, int x, int y, int XX, int YY) {329 int Pattern::flipsY(int i, int x, int y, int XX, int YY) { 320 330 if (i==0) return y; 321 331 if (i==1) return y; … … 330 340 331 341 332 static int Pattern::PatternInvFlip(i) {342 int Pattern::PatternInvFlip(int i) { 333 343 if (i == 5) return 6; 334 344 if (i == 6) return 5; … … 336 346 } 337 347 338 PatternList::PatternList(Pattern& p, int fColor, int n extMove, int bsize) {339 pattern = p;348 PatternList::PatternList(Pattern& p, int fColor, int nMove, int bsize) { 349 pattern.copy(p); 340 350 fixedColor = fColor; 341 351 nextMove = nMove; … … 368 378 vector<Pattern> PatternList::patternList() { 369 379 370 vector<Pattern> l ();371 vector<Pattern> lCS ();372 vector<pair<int,int> > sy;380 vector<Pattern> l; 381 vector<Pattern> lCS; 382 vector<pair<int,int> > sy; 373 383 374 384 int special = -1; 375 385 376 386 for(int f=0; f < 8; f++) { 377 int finv = PatternInvFlip(f); 387 int newSizeX = max(Pattern::flipsX(f,0,0,pattern.sizeX,pattern.sizeY), 388 Pattern::flipsX(f,pattern.sizeX,pattern.sizeY,pattern.sizeX,pattern.sizeY)); 389 int newSizeY = max(Pattern::flipsY(f,0,0,pattern.sizeX,pattern.sizeY), 390 Pattern::flipsY(f,pattern.sizeX,pattern.sizeY,pattern.sizeX,pattern.sizeY)); 378 391 379 int newLeft = min(flipsX(f,left,top,boardsize-1,boardsize-1), flipsX(f,right,bottom,boardsize-1,boardsize-1)); 380 int newRight = max(flipsX(f,left,top,boardsize-1,boardsize-1), flipsX(f,right,bottom,boardsize-1,boardsize-1)); 381 int newTop = min(flipsY(f,left,top,boardsize-1,boardsize-1), flipsY(f,right,bottom,boardsize-1,boardsize-1)); 382 int newBottom = max(flipsY(f,left,top,boardsize-1,boardsize-1), flipsY(f,right,bottom,boardsize-1,boardsize-1)); 383 384 int newSizeX = max(flipsX(f,0,0,sizeX,sizeY), flipsX(f,sizeX,sizeY,sizeX,sizeY)); 385 int newSizeY = max(flipsX(f,0,0,sizeX,sizeY), flipsX(f,sizeX,sizeY,sizeX,sizeY)); 392 int newLeft = min(Pattern::flipsX(f,pattern.left,pattern.top,boardsize-1,boardsize-1), 393 Pattern::flipsX(f,pattern.right+pattern.sizeX-1,pattern.bottom+pattern.sizeY-1, 394 boardsize-1,boardsize-1)); 395 int newRight = max(Pattern::flipsX(f,pattern.left,pattern.top,boardsize-1,boardsize-1), 396 Pattern::flipsX(f,pattern.right+pattern.sizeX-1,pattern.bottom+pattern.sizeY-1, 397 boardsize-1,boardsize-1)) - (newSizeX-1); 398 int newTop = min(Pattern::flipsY(f,pattern.left,pattern.top,boardsize-1,boardsize-1), 399 Pattern::flipsY(f,pattern.right+pattern.sizeX-1,pattern.bottom+pattern.sizeY-1, 400 boardsize-1,boardsize-1)); 401 int newBottom = max(Pattern::flipsY(f,pattern.left,pattern.top,boardsize-1,boardsize-1), 402 Pattern::flipsY(f,pattern.right+pattern.sizeX-1,pattern.bottom+pattern.sizeY-1, 403 boardsize-1,boardsize-1)) - (newSizeY - 1); 386 404 387 405 char* newInitialPos = new char[pattern.sizeX*pattern.sizeY]; 388 406 for(int i=0; i<pattern.sizeX; i++) { 389 407 for(int j=0; j<pattern.sizeY; j++) { 390 newInitialPos[flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1) + pattern.sizeX*flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1)] = pattern.getInitial(i, j); 408 newInitialPos[Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1) + \ 409 pattern.sizeX*Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1)] = pattern.getInitial(i, j); 391 410 } 392 411 } … … 394 413 char* newContList = new char[pattern.lenContList*4]; 395 414 for(int i=0; i<pattern.lenContList; i++) { 396 newContList[4*i] = flipsX(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1); 397 newContList[4*i+1] = flipsY(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1); 415 newContList[4*i] = Pattern::flipsX(f, pattern.contList[4*i], pattern.contList[4*i+1], 416 pattern.sizeX-1,pattern.sizeY-1); 417 newContList[4*i+1] = Pattern::flipsY(f, pattern.contList[4*i], pattern.contList[4*i+1], 418 pattern.sizeX-1,pattern.sizeY-1); 398 419 newContList[4*i+2] = pattern.contList[4*i+2]; 399 420 newContList[4*i+3] = '/'; … … 419 440 if (foundNewPattern) l.push_back(pNew); 420 441 421 if (pNew == pattern) sy.push_back(pair<int,int>( ii,0));442 if (pNew == pattern) sy.push_back(pair<int,int>(f,0)); 422 443 423 444 if (nextMove || !fixedColor) { … … 427 448 for(int i=0; i<pattern.sizeX; i++) { 428 449 for(int j=0; j<pattern.sizeY; j++) { 429 newInitialPos[ flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1) + pattern.sizeX*flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1)] =430 invert (pattern.getInitial(i, j));450 newInitialPos[Pattern::flipsX(f,i,j,pattern.sizeX-1,pattern.sizeY-1) + pattern.sizeX*Pattern::flipsY(f,i,j,pattern.sizeX-1,pattern.sizeY-1)] = 451 invertColor(pattern.getInitial(i, j)); 431 452 } 432 453 } … … 434 455 char* newContList = new char[pattern.lenContList*4]; 435 456 for(int i=0; i<pattern.lenContList; i++) { 436 newContList[4*i] = flipsX(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1);437 newContList[4*i+1] = flipsY(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1);438 newContList[4*i+2] = invert (pattern.contList[4*i+2]);457 newContList[4*i] = Pattern::flipsX(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1); 458 newContList[4*i+1] = Pattern::flipsY(f, pattern.contList[4*i], pattern.contList[4*i+1], pattern.sizeX-1,pattern.sizeY-1); 459 newContList[4*i+2] = invertColor(pattern.contList[4*i+2]); 439 460 newContList[4*i+3] = '/'; 440 461 } … … 485 506 symm.set(i,j,i,j,0); 486 507 487 vector<pair<int,int> >::iterator it;488 for(it =sy.begin(); it!=sy.end(); it++) {489 int s = it ->first;490 int c = it ->second;508 vector<pair<int,int> >::iterator it_s; 509 for(it_s=sy.begin(); it_s!=sy.end(); it_s++) { 510 int s = it_s->first; 511 int c = it_s->second; 491 512 Symmetries symm1; 492 513 493 514 for(int i=0; i < pattern.sizeX; i++) { 494 515 for(int j=0; j < pattern.sizeY; j++) { 495 int fX = flipsX(s, i, j, pattern.sizeX-1, pattern.sizeY-1);496 int fY = flipsY(s, i, j, pattern.sizeX-1, pattern.sizeY-1);497 if (( (i != fX || j != fY) && !symm1.has_key(fX, fY))516 int fX = Pattern::flipsX(s, i, j, pattern.sizeX-1, pattern.sizeY-1); 517 int fY = Pattern::flipsY(s, i, j, pattern.sizeX-1, pattern.sizeY-1); 518 if ((i != fX || j != fY) && !symm1.has_key(fX, fY)) 498 519 symm1.set(i,j, fX, fY, c); 499 520 } 500 521 } 501 522 502 int cs 523 int cs; 503 524 for(int i=0; i<symm.sizeX; i++) 504 525 for(int j=0; j<symm.sizeY; j++) 505 526 if (symm1.has_key(symm.getX(i,j), symm.getY(i,j))) { 506 if ((symm1.getC (symm.getX(i,j),symm.getY(i,j)) || symm.getC(i,j)) &&507 !(symm1.getC (symm.getX(i,j),symm.getY(i,j)) && symm.getC(i,j)))527 if ((symm1.getCS(symm.getX(i,j),symm.getY(i,j)) || symm.getCS(i,j)) && 528 !(symm1.getCS(symm.getX(i,j),symm.getY(i,j)) && symm.getCS(i,j))) 508 529 cs = 1; 509 530 else cs = 0; … … 511 532 symm1.getY(symm.getX(i,j),symm.getY(i,j)), cs); 512 533 } 513 514 if (special == -1) 515 symm.special = -1; 516 else 517 symm.special = PatternInvFlip(special); 518 519 symmetries = symm; 520 return l; 521 } 522 523 524 Pattern PatternList::get(int i) { 534 } 535 536 if (special == -1) 537 symm.special = -1; 538 else 539 symm.special = Pattern::PatternInvFlip(special); 540 541 symmetries = symm; 542 return l; 543 } 544 545 546 Pattern& PatternList::get(int i) { 525 547 return data[i]; 526 548 } … … 532 554 533 555 534 P atternList::updateContinuations(int index, int x, int y, char co, int Xint0, int Xint1,556 PyObject* PatternList::updateContinuations(int index, int x, int y, char co, int Xint0, int Xint1, 535 557 int Yint0, int Yint1, 536 558 int foundWhere, int counter, … … 538 560 char winner) { 539 561 540 //541 //542 // fuer die PythonAPI sachen vgl. altes matchC.cc !!!543 //544 // FIXME545 546 547 562 int xx = Pattern::flipsX(Pattern::PatternInvFlip(data[index].flip), x, y, boardsize-1, boardsize-1); 548 int yy = Pat ern::flipsY(Pattern::PatternInvFlip(data[index].flip), x, y, boardsize-1, boardsize-1);549 550 int XX1 = Pattern::flipsX(Pattern:: patternInvFlip(data[index].flip, Xint0, Yint0, boardsize-1, boardsize-1));551 int YY1 = Pattern::flipsY(Pattern:: patternInvFlip(data[index].flip, Xint0, Yint0, boardsize-1, boardsize-1));552 int XX2 = Pattern::flipsX(Pattern:: patternInvFlip(data[index].flip, Xint1-1, Yint1-1, boardsize-1, boardsize-1));553 int YY2 = Pattern::flipsY(Pattern:: patternInvFlip(data[index].flip, Xint1-1, Yint1-1, boardsize-1, boardsize-1));563 int yy = Pattern::flipsY(Pattern::PatternInvFlip(data[index].flip), x, y, boardsize-1, boardsize-1); 564 565 int XX1 = Pattern::flipsX(Pattern::PatternInvFlip(data[index].flip), Xint0, Yint0, boardsize-1, boardsize-1); 566 int YY1 = Pattern::flipsY(Pattern::PatternInvFlip(data[index].flip), Xint0, Yint0, boardsize-1, boardsize-1); 567 int XX2 = Pattern::flipsX(Pattern::PatternInvFlip(data[index].flip), Xint1-1, Yint1-1, boardsize-1, boardsize-1); 568 int YY2 = Pattern::flipsY(Pattern::PatternInvFlip(data[index].flip), Xint1-1, Yint1-1, boardsize-1, boardsize-1); 554 569 555 570 int XX = XX1 < XX2 ? XX1 : XX2; … … 598 613 YY1 = YY1N; 599 614 600 int XX2N = Pattern::flipsX(symmetries.special, XX2, YY2, boardsize-1 );601 int YY2N = Pattern::flipsY(symmetries.special, XX2, YY2, boardsize-1 );615 int XX2N = Pattern::flipsX(symmetries.special, XX2, YY2, boardsize-1, boardsize-1); 616 int YY2N = Pattern::flipsY(symmetries.special, XX2, YY2, boardsize-1, boardsize-1); 602 617 XX2 = XX2N; 603 618 YY2 = YY2N; … … 619 634 620 635 colorSwitch = 1-cSymm; 621 if (colorSwitch) numOfSwitched++;636 // if (colorSwitch) numOfSwitched++; FIXME?! 622 637 } 623 638 else … … 626 641 else { 627 642 colorSwitch = cSymm; 628 if (colorSwitch) numOfSwitched++;643 // if (colorSwitch) numOfSwitched++; 629 644 } 630 645 } … … 634 649 PyObject* scxy; 635 650 636 if ((scxy = PyDict_GetItem(continuations, xxyy))) { 637 PyObject *temp = PyInt_FromLong(PyInt_AsLong(PyDict_GetItemString(scxy, cc))+1); 638 PyDict_SetItemString(scxy, cc, temp); 651 char text; 652 char ccStr[2]; 653 ccStr[0] = cc; 654 ccStr[1] = 0; 655 if ((scxy = PyDict_GetItem(continuations, xxyyPY))) { 656 PyObject *temp = PyInt_FromLong(PyInt_AsLong(PyDict_GetItemString(scxy, ccStr))+1); 657 PyDict_SetItemString(scxy, ccStr, temp); 639 658 Py_DECREF(temp); 640 659 text = PyString_AsString(PyDict_GetItemString(scxy, "N"))[0]; 641 660 } 642 661 else { 643 if (contLabelsIndex >= len(contLabels)) text = '?';662 if (contLabelsIndex >= strlen(contLabels)) text = '?'; // FIXME strlen(contLabels) OK? 644 663 else { 645 664 text = contLabels[contLabelsIndex]; … … 647 666 } 648 667 649 if ( strcmp(cc, "B")==0) {668 if (cc=='B') { 650 669 scxy = PyDict_New(); 651 670 PyObject* Py0 = PyInt_FromLong(0); … … 719 738 } 720 739 } 721 return Py_BuildValue("icii", 1, continuations[(xx,yy)]['N'], contLabelsIndex,722 ( self.data[index].colorSwitch or colorSwitch));723 } 724 740 return Py_BuildValue("icii", 1, text, contLabelsIndex, 741 (data[index].colorSwitch or colorSwitch)); 742 } 743
