| 116 | | |
| 117 | | if (strcmp(currentDatap,datap)) { |
| 118 | | delete [] currentDatap; |
| 119 | | currentDatap = new char[strlen(datap)+1]; |
| 120 | | strcpy(currentDatap, datap); |
| 121 | | |
| 122 | | char* currentFP = new char[]; |
| 123 | | |
| 124 | | try { |
| 125 | | file = open(os.path.join(datap[0], 'finalpos'+datap[1]+'.db'), 'rb'); |
| 126 | | while (1) { |
| 127 | | try self.currentFP.fromfile(file, 1000000); |
| 128 | | except EOFError break; |
| 129 | | } |
| 130 | | file.close(); |
| 131 | | } |
| 132 | | except return 0; |
| 133 | | } |
| 134 | | |
| 135 | | for(int i=0; i<100; i++) |
| 136 | | if (currentFP[sli*100+i] != fp[i]) |
| 137 | | return 0; |
| 138 | | return 1; |
| 139 | | } |
| 140 | | |
| 141 | | int Algo_finalpos::retrieve_db(datap) { |
| 142 | | String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| 143 | | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| 144 | | if (file.is_open()) { |
| 145 | | ifstream::pos_type size = file.tellg(); |
| 146 | | delete [] finalpos; |
| 147 | | finalpos = new char[size]; |
| 148 | | file.seekg (0, ios::beg); |
| 149 | | file.read (memblock, size); |
| 150 | | file.close(); |
| | 116 | return 0; // FIXME |
| | 117 | |
| | 118 | // if (strcmp(currentDatap,datap)) { |
| | 119 | // delete [] currentDatap; |
| | 120 | // currentDatap = new char[strlen(datap)+1]; |
| | 121 | // strcpy(currentDatap, datap); |
| | 122 | // |
| | 123 | // char* currentFP = new char[]; |
| | 124 | // |
| | 125 | // try { |
| | 126 | // file = open(os.path.join(datap[0], 'finalpos'+datap[1]+'.db'), 'rb'); |
| | 127 | // while (1) { |
| | 128 | // try self.currentFP.fromfile(file, 1000000); |
| | 129 | // except EOFError break; |
| | 130 | // } |
| | 131 | // file.close(); |
| | 132 | // } |
| | 133 | // except return 0; |
| | 134 | // } |
| | 135 | // |
| | 136 | // for(int i=0; i<100; i++) |
| | 137 | // if (currentFP[sli*100+i] != fp[i]) |
| | 138 | // return 0; |
| | 139 | // return 1; |
| | 140 | } |
| | 141 | |
| | 142 | int Algo_finalpos::retrieve_db(PyObject* datap) { |
| | 143 | String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| | 144 | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| | 145 | if (file.is_open()) { |
| | 146 | ifstream::pos_type size = file.tellg(); |
| | 147 | delete [] finalpos; |
| | 148 | finalpos = new char[size]; |
| | 149 | file.seekg (0, ios::beg); |
| | 150 | file.read (memblock, size); |
| | 151 | file.close(); |
| 353 | | String fn = retrieve_datap0(datap) + "/finalposC" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| 354 | | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| 355 | | if (file.is_open()) { |
| 356 | | ifstream::pos_type size = file.tellg(); |
| 357 | | delete [] finalposC; |
| 358 | | finalposC = new char[size]; |
| 359 | | file.seekg (0, ios::beg); |
| 360 | | file.read (memblock, size); |
| 361 | | file.close(); |
| 362 | | } |
| | 354 | String fn = retrieve_datap0(datap) + "/finalposC" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| | 355 | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| | 356 | if (file.is_open()) { |
| | 357 | ifstream::pos_type size = file.tellg(); |
| | 358 | delete [] finalposC; |
| | 359 | finalposC = new char[size]; |
| | 360 | file.seekg (0, ios::beg); |
| | 361 | file.read (memblock, size); |
| | 362 | file.close(); |
| | 363 | } |
| 364 | | cout << "Unable to open file"; |
| 365 | | return 0; |
| 366 | | } |
| 367 | | fn = retrieve_datap0(datap) + "/lists" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| 368 | | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| 369 | | if (file.is_open()) { |
| 370 | | ifstream::pos_type size = file.tellg(); |
| 371 | | delete [] mainlistArr; |
| 372 | | mainlistArr = new char[size]; |
| 373 | | file.seekg (0, ios::beg); |
| 374 | | file.read (memblock, size); |
| 375 | | file.close(); |
| 376 | | } |
| | 365 | cout << "Unable to open file"; |
| | 366 | return 0; |
| | 367 | } |
| | 368 | fn = retrieve_datap0(datap) + "/lists" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| | 369 | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| | 370 | if (file.is_open()) { |
| | 371 | ifstream::pos_type size = file.tellg(); |
| | 372 | delete [] mainlistArr; |
| | 373 | mainlistArr = new char[size]; |
| | 374 | file.seekg (0, ios::beg); |
| | 375 | file.read (memblock, size); |
| | 376 | file.close(); |
| | 377 | } |
| 378 | | cout << "Unable to open file"; |
| 379 | | return 0; |
| 380 | | } |
| 381 | | fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| 382 | | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| 383 | | if (file.is_open()) { |
| 384 | | ifstream::pos_type size = file.tellg(); |
| 385 | | delete [] posTable; |
| 386 | | posTable = new char[size]; // FIXME: not a char array??? |
| 387 | | file.seekg (0, ios::beg); |
| 388 | | file.read (memblock, size); |
| 389 | | file.close(); |
| | 379 | cout << "Unable to open file"; |
| | 380 | return 0; |
| | 381 | } |
| | 382 | fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? |
| | 383 | ifstream file (fn, ios::in|ios::binary|ios::ate); |
| | 384 | if (file.is_open()) { |
| | 385 | ifstream::pos_type size = file.tellg(); |
| | 386 | delete [] posTable; |
| | 387 | posTable = new char[size]; // FIXME: not a char array??? |
| | 388 | file.seekg (0, ios::beg); |
| | 389 | file.read (memblock, size); |
| | 390 | file.close(); |
| 483 | | if (!patternList.nextMove) { |
| 484 | | for(m in dicts.keys()) |
| 485 | | if (dicts[m].has_key('found')) { |
| 486 | | Pattern p = patternList.get(m[0]); // FIXME: besser pointer uebergeben? |
| 487 | | if (p.colorSwitch) numOfSwitched++; |
| 488 | | if (p.colorSwitch && showColorSwap) |
| 489 | | result.append((dicts[m]['found'], '-')); |
| 490 | | else result.append((dicts[m]['found'], '')); |
| 491 | | } |
| 492 | | } |
| 493 | | dicts, dictsNO, contList, contListIndex, counter = self.branchpoints.pop(); |
| 494 | | movelistIndex += 2; |
| 495 | | continue; |
| | 484 | if (!patternList.nextMove) { |
| | 485 | for(m in dicts.keys()) |
| | 486 | if (dicts[m].has_key('found')) { |
| | 487 | Pattern p = patternList.get(m[0]); // FIXME: besser pointer uebergeben? |
| | 488 | if (p.colorSwitch) numOfSwitched++; |
| | 489 | if (p.colorSwitch && showColorSwap) |
| | 490 | result.append((dicts[m]['found'], '-')); |
| | 491 | else result.append((dicts[m]['found'], '')); |
| | 492 | } |
| | 493 | } |
| | 494 | dicts, dictsNO, contList, contListIndex, counter = self.branchpoints.pop(); |
| | 495 | movelistIndex += 2; |
| | 496 | continue; |
| 507 | | if (mainlistArr[movelistIndex+1] & BLACK) { |
| 508 | | co = 'X'; |
| 509 | | invco = 'O'; |
| 510 | | } |
| 511 | | else { |
| 512 | | co = 'O'; |
| 513 | | invco = 'X'; |
| 514 | | } |
| 515 | | |
| 516 | | for(m in dicts.keys()) { |
| 517 | | if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { |
| 518 | | if (dicts[m].has_key('found')) { |
| 519 | | hit, label, contLabelsIndex, switched = patternList.updateContinuations(m[0], x, y, invco, |
| 520 | | Xinterv[m], Yinterv[m], |
| 521 | | dicts[m]['found'], counter, |
| 522 | | continuations, contLabels, |
| 523 | | contLabelsIndex, |
| 524 | | db.getCurrentWinner()); |
| 525 | | if (!hit) { |
| 526 | | del dicts[m]; |
| 527 | | del dictsNO[m]; |
| 528 | | continue; |
| 529 | | } |
| 530 | | |
| 531 | | numOfSwitched += switched; // FIXME: CHECK, was: patternList[m[0]].colorSwitch |
| 532 | | |
| 533 | | if (switched && showColorSwap) |
| 534 | | // FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: |
| 535 | | result.append((dicts[m]['found'], label + '-')); |
| 536 | | else result.append((dicts[m]['found'], label)); |
| 537 | | del dicts[m]; |
| 538 | | del dictsNO[m]; |
| 539 | | continue; // with for m in dicts.keys() |
| 540 | | } |
| 541 | | else if (dicts[m].has_key('foundInitial')) { |
| 542 | | if ((x, y, co) == contList[m][contListIndex[m]]) { |
| 543 | | contListIndex[m]++; |
| 544 | | if (contListIndex[m] == len(contList[m])) { |
| 545 | | dicts[m]['found'] = counter; |
| 546 | | del dicts[m]['foundInitial']; |
| 547 | | } |
| 548 | | } |
| 549 | | else { |
| 550 | | if (dicts[m].has_key('dontRestore')) { |
| 551 | | del dicts[m]; |
| 552 | | continue; |
| 553 | | } |
| 554 | | else { |
| 555 | | contListIndex[m] = 0; |
| 556 | | del dicts[m]['foundInitial']; |
| 557 | | } |
| 558 | | } |
| 559 | | } |
| | 508 | if (mainlistArr[movelistIndex+1] & BLACK) { |
| | 509 | co = 'X'; |
| | 510 | invco = 'O'; |
| | 511 | } |
| | 512 | else { |
| | 513 | co = 'O'; |
| | 514 | invco = 'X'; |
| | 515 | } |
| | 516 | |
| | 517 | for(m in dicts.keys()) { |
| | 518 | if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { |
| | 519 | if (dicts[m].has_key('found')) { |
| | 520 | hit, label, contLabelsIndex, switched = patternList.updateContinuations(m[0], x, y, invco, |
| | 521 | Xinterv[m], Yinterv[m], |
| | 522 | dicts[m]['found'], counter, |
| | 523 | continuations, contLabels, |
| | 524 | contLabelsIndex, |
| | 525 | db.getCurrentWinner()); |
| | 526 | if (!hit) { |
| | 527 | del dicts[m]; |
| | 528 | del dictsNO[m]; |
| | 529 | continue; |
| | 530 | } |
| | 531 | |
| | 532 | numOfSwitched += switched; // FIXME: CHECK, was: patternList[m[0]].colorSwitch |
| | 533 | |
| | 534 | if (switched && showColorSwap) |
| | 535 | // FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: |
| | 536 | result.append((dicts[m]['found'], label + '-')); |
| | 537 | else result.append((dicts[m]['found'], label)); |
| | 538 | del dicts[m]; |
| | 539 | del dictsNO[m]; |
| | 540 | continue; // with for m in dicts.keys() |
| | 541 | } |
| | 542 | else if (dicts[m].has_key('foundInitial')) { |
| | 543 | if ((x, y, co) == contList[m][contListIndex[m]]) { |
| | 544 | contListIndex[m]++; |
| | 545 | if (contListIndex[m] == len(contList[m])) { |
| | 546 | dicts[m]['found'] = counter; |
| | 547 | del dicts[m]['foundInitial']; |
| | 548 | } |
| | 549 | } |
| | 550 | else { |
| | 551 | if (dicts[m].has_key('dontRestore')) { |
| | 552 | del dicts[m]; |
| | 553 | continue; |
| | 554 | } |
| | 555 | else { |
| | 556 | contListIndex[m] = 0; |
| | 557 | del dicts[m]['foundInitial']; |
| | 558 | } |
| | 559 | } |
| | 560 | } |
| 593 | | if (mainlistArr[movelistIndex+1] & BLACK) { |
| 594 | | co = 'X'; |
| 595 | | invco = 'O'; |
| 596 | | } |
| 597 | | else if mainlistArr[movelistIndex+1] & WHITE { |
| 598 | | co = 'O'; |
| 599 | | invco = 'X'; |
| 600 | | } |
| 601 | | else printf("oops\n"); // FIXME |
| 602 | | |
| 603 | | for (m in dicts.keys()) { |
| 604 | | if (!dicts[m].has_key('found')) { |
| 605 | | if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { |
| 606 | | if (dicts[m].has_key('foundInitial')) { |
| 607 | | int ii = contListIndex[m]; |
| 608 | | while (ii < len(contList[m]) && contList[m][ii][2] == '-' && |
| 609 | | (x != contList[m][ii][0] || y != contList[m][ii][1])) |
| 610 | | ii++; |
| 611 | | if (ii < len(contList[m]) && contList[m][ii][2] == '-') { |
| 612 | | help = contList[m][ii]; |
| 613 | | contList[m][ii] = contList[m][contListIndex[m]]; |
| 614 | | contlist[contListIndex[m]] = help; |
| 615 | | |
| 616 | | contListIndex[m]++; |
| 617 | | } |
| 618 | | else { |
| 619 | | if (dicts[m].has_key('dontRestore')) { |
| 620 | | del dicts[m]; |
| 621 | | continue; |
| 622 | | } |
| 623 | | else { |
| 624 | | contListIndex[m] = 0; |
| 625 | | del dicts[m]['foundInitial']; |
| 626 | | } |
| 627 | | } |
| 628 | | } |
| 629 | | if (!dicts[m].has_key((x,y))) { |
| 630 | | dicts[m][(x,y)] = co; |
| 631 | | dictsNO[m]++; |
| 632 | | } |
| 633 | | else if (dicts[m][(x,y)] == lower(invco)) { |
| 634 | | dictsNO[m]--; |
| 635 | | } |
| 636 | | else if (dicts[m][(x,y)] == '.') { |
| 637 | | del dicts[m][(x,y)]; |
| 638 | | dictsNO[m]--; |
| 639 | | } |
| 640 | | } |
| 641 | | } |
| 642 | | } |
| | 594 | if (mainlistArr[movelistIndex+1] & BLACK) { |
| | 595 | co = 'X'; |
| | 596 | invco = 'O'; |
| | 597 | } |
| | 598 | else if mainlistArr[movelistIndex+1] & WHITE { |
| | 599 | co = 'O'; |
| | 600 | invco = 'X'; |
| | 601 | } |
| | 602 | else printf("oops\n"); // FIXME |
| | 603 | |
| | 604 | for (m in dicts.keys()) { |
| | 605 | if (!dicts[m].has_key('found')) { |
| | 606 | if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { |
| | 607 | if (dicts[m].has_key('foundInitial')) { |
| | 608 | int ii = contListIndex[m]; |
| | 609 | while (ii < len(contList[m]) && contList[m][ii][2] == '-' && |
| | 610 | (x != contList[m][ii][0] || y != contList[m][ii][1])) |
| | 611 | ii++; |
| | 612 | if (ii < len(contList[m]) && contList[m][ii][2] == '-') { |
| | 613 | help = contList[m][ii]; |
| | 614 | contList[m][ii] = contList[m][contListIndex[m]]; |
| | 615 | contlist[contListIndex[m]] = help; |
| | 616 | |
| | 617 | contListIndex[m]++; |
| | 618 | } |
| | 619 | else { |
| | 620 | if (dicts[m].has_key('dontRestore')) { |
| | 621 | del dicts[m]; |
| | 622 | continue; |
| | 623 | } |
| | 624 | else { |
| | 625 | contListIndex[m] = 0; |
| | 626 | del dicts[m]['foundInitial']; |
| | 627 | } |
| | 628 | } |
| | 629 | } |
| | 630 | if (!dicts[m].has_key((x,y))) { |
| | 631 | dicts[m][(x,y)] = co; |
| | 632 | dictsNO[m]++; |
| | 633 | } |
| | 634 | else if (dicts[m][(x,y)] == lower(invco)) { |
| | 635 | dictsNO[m]--; |
| | 636 | } |
| | 637 | else if (dicts[m][(x,y)] == '.') { |
| | 638 | del dicts[m][(x,y)]; |
| | 639 | dictsNO[m]--; |
| | 640 | } |
| | 641 | } |
| | 642 | } |
| | 643 | } |
| 661 | | Pattern p = patternList.get(m[0]); |
| 662 | | if (dicts[m].has_key('found')) { |
| 663 | | if (p.colorSwitch) numOfSwitched++; |
| 664 | | if (p.colorSwitch && showColorSwap) result.append((dicts[m]['found'], '-')); |
| 665 | | else result.append((dicts[m]['found'], '')); |
| 666 | | } |
| | 662 | Pattern p = patternList.get(m[0]); |
| | 663 | if (dicts[m].has_key('found')) { |
| | 664 | if (p.colorSwitch) numOfSwitched++; |
| | 665 | if (p.colorSwitch && showColorSwap) result.append((dicts[m]['found'], '-')); |
| | 666 | else result.append((dicts[m]['found'], '')); |
| | 667 | } |