author | erik <erik> | 2007-01-19 01:10:09 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-19 01:10:09 (UTC) |
commit | 2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (patch) (unidiff) | |
tree | 5f1b129bf6864ad8c47054471a0c4a34badeeebe | |
parent | ca67251af3f46d685afac8dc6bfe452799c2546e (diff) | |
download | opie-2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a.zip opie-2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a.tar.gz opie-2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a.tar.bz2 |
BUG: There are only 4095 items in the buffer that is zero'd out using 4096.
FIX: Fix the number used in memset.
-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index 52e2be2..8cf92ef 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -495,193 +495,193 @@ void WordGame::endGame() | |||
495 | done->setEnabled(TRUE); | 495 | done->setEnabled(TRUE); |
496 | reset->setEnabled(FALSE); | 496 | reset->setEnabled(FALSE); |
497 | } | 497 | } |
498 | 498 | ||
499 | void WordGame::endTurn() | 499 | void WordGame::endTurn() |
500 | { | 500 | { |
501 | if ( gameover ) { | 501 | if ( gameover ) { |
502 | openGameSelector(namelist); | 502 | openGameSelector(namelist); |
503 | } else { | 503 | } else { |
504 | if ( board->checkTurn() ) { | 504 | if ( board->checkTurn() ) { |
505 | if ( board->turnScore() >= 0 ) { | 505 | if ( board->turnScore() >= 0 ) { |
506 | scoreinfo->addScore(player,board->turnScore()); | 506 | scoreinfo->addScore(player,board->turnScore()); |
507 | board->finalizeTurn(); | 507 | board->finalizeTurn(); |
508 | } else { | 508 | } else { |
509 | QApplication::beep(); | 509 | QApplication::beep(); |
510 | } | 510 | } |
511 | nextPlayer(); | 511 | nextPlayer(); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | void WordGame::resetTurn() | 516 | void WordGame::resetTurn() |
517 | { | 517 | { |
518 | board->resetRack(); | 518 | board->resetRack(); |
519 | } | 519 | } |
520 | 520 | ||
521 | void WordGame::passTurn() | 521 | void WordGame::passTurn() |
522 | { | 522 | { |
523 | // ######## trade? | 523 | // ######## trade? |
524 | nextPlayer(); | 524 | nextPlayer(); |
525 | } | 525 | } |
526 | 526 | ||
527 | bool WordGame::refillRack(int i) | 527 | bool WordGame::refillRack(int i) |
528 | { | 528 | { |
529 | Rack* r = rack(i); | 529 | Rack* r = rack(i); |
530 | while ( !bag->isEmpty() && !r->isFull() ) { | 530 | while ( !bag->isEmpty() && !r->isFull() ) { |
531 | r->addTile(bag->takeRandom()); | 531 | r->addTile(bag->takeRandom()); |
532 | } | 532 | } |
533 | return r->count() != 0; | 533 | return r->count() != 0; |
534 | } | 534 | } |
535 | 535 | ||
536 | void WordGame::readyRack(int i) | 536 | void WordGame::readyRack(int i) |
537 | { | 537 | { |
538 | Rack* r = rack(i); | 538 | Rack* r = rack(i); |
539 | racks->raiseWidget(i); | 539 | racks->raiseWidget(i); |
540 | board->setCurrentRack(r); | 540 | board->setCurrentRack(r); |
541 | 541 | ||
542 | done->setEnabled( !r->computerized() ); | 542 | done->setEnabled( !r->computerized() ); |
543 | reset->setEnabled( !r->computerized() ); | 543 | reset->setEnabled( !r->computerized() ); |
544 | 544 | ||
545 | if ( r->computerized() ) { | 545 | if ( r->computerized() ) { |
546 | cpu = new ComputerPlayer(board, r); | 546 | cpu = new ComputerPlayer(board, r); |
547 | aiheart->start(0); | 547 | aiheart->start(0); |
548 | } | 548 | } |
549 | } | 549 | } |
550 | 550 | ||
551 | Rack* WordGame::rack(int i) const | 551 | Rack* WordGame::rack(int i) const |
552 | { | 552 | { |
553 | return (Rack*)racks->widget(i); | 553 | return (Rack*)racks->widget(i); |
554 | } | 554 | } |
555 | 555 | ||
556 | void WordGame::think() | 556 | void WordGame::think() |
557 | { | 557 | { |
558 | if ( !cpu->step() ) { | 558 | if ( !cpu->step() ) { |
559 | delete cpu; | 559 | delete cpu; |
560 | cpu = 0; | 560 | cpu = 0; |
561 | aiheart->stop(); | 561 | aiheart->stop(); |
562 | if ( board->turnScore() < 0 ) | 562 | if ( board->turnScore() < 0 ) |
563 | passTurn(); | 563 | passTurn(); |
564 | else | 564 | else |
565 | endTurn(); | 565 | endTurn(); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
569 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : | 569 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : |
570 | board(b), rack(r), best(new const Tile*[rack_tiles]), | 570 | board(b), rack(r), best(new const Tile*[rack_tiles]), |
571 | best_blankvalues(new Tile[rack_tiles]) | 571 | best_blankvalues(new Tile[rack_tiles]) |
572 | { | 572 | { |
573 | best_score = -1; | 573 | best_score = -1; |
574 | across=FALSE; | 574 | across=FALSE; |
575 | dict=0; | 575 | dict=0; |
576 | } | 576 | } |
577 | 577 | ||
578 | ComputerPlayer::~ComputerPlayer() | 578 | ComputerPlayer::~ComputerPlayer() |
579 | { | 579 | { |
580 | delete [] best; | 580 | delete [] best; |
581 | delete [] best_blankvalues; | 581 | delete [] best_blankvalues; |
582 | } | 582 | } |
583 | 583 | ||
584 | bool ComputerPlayer::step() | 584 | bool ComputerPlayer::step() |
585 | { | 585 | { |
586 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() | 586 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() |
587 | : Global::fixedDawg().root(); | 587 | : Global::fixedDawg().root(); |
588 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); | 588 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); |
589 | const Tile* tiles[99]; // ### max board size | 589 | const Tile* tiles[99]; // ### max board size |
590 | uchar nletter[4095]; // QDawg only handles 0..4095 | 590 | uchar nletter[4095]; // QDawg only handles 0..4095 |
591 | memset(nletter,0,4096); | 591 | memset(nletter,0,4095); |
592 | for (int i=0; i<rack->count(); i++) { | 592 | for (int i=0; i<rack->count(); i++) { |
593 | const Tile* r = rack->tileRef(i); | 593 | const Tile* r = rack->tileRef(i); |
594 | if ( r->isBlank() ) | 594 | if ( r->isBlank() ) |
595 | nletter[0]++; | 595 | nletter[0]++; |
596 | else | 596 | else |
597 | nletter[r->text()[0].unicode()]++; | 597 | nletter[r->text()[0].unicode()]++; |
598 | } | 598 | } |
599 | Tile blankvalues[99]; // ### max blanks | 599 | Tile blankvalues[99]; // ### max blanks |
600 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); | 600 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); |
601 | if ( ++current.rx() == board->xTiles() ) { | 601 | if ( ++current.rx() == board->xTiles() ) { |
602 | current.rx() = 0; | 602 | current.rx() = 0; |
603 | if ( ++current.ry() == board->yTiles() ) { | 603 | if ( ++current.ry() == board->yTiles() ) { |
604 | if ( across ) { | 604 | if ( across ) { |
605 | if ( dict == 1 ) { | 605 | if ( dict == 1 ) { |
606 | if ( best_score >= 0 ) { | 606 | if ( best_score >= 0 ) { |
607 | rack->arrangeTiles(best,best_n); | 607 | rack->arrangeTiles(best,best_n); |
608 | rack->setBlanks(best_blankvalues); | 608 | rack->setBlanks(best_blankvalues); |
609 | board->scoreTurn(best_start, best_n, best_dir); | 609 | board->scoreTurn(best_start, best_n, best_dir); |
610 | board->showTurn(); | 610 | board->showTurn(); |
611 | } | 611 | } |
612 | return FALSE; | 612 | return FALSE; |
613 | } | 613 | } |
614 | dict++; | 614 | dict++; |
615 | across = FALSE; | 615 | across = FALSE; |
616 | current = QPoint(0,0); | 616 | current = QPoint(0,0); |
617 | } else { | 617 | } else { |
618 | across = TRUE; | 618 | across = TRUE; |
619 | current = QPoint(0,0); | 619 | current = QPoint(0,0); |
620 | } | 620 | } |
621 | } | 621 | } |
622 | } | 622 | } |
623 | return TRUE; | 623 | return TRUE; |
624 | } | 624 | } |
625 | 625 | ||
626 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) | 626 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) |
627 | { | 627 | { |
628 | if ( !node ) | 628 | if ( !node ) |
629 | return; | 629 | return; |
630 | QChar l = node->letter(); | 630 | QChar l = node->letter(); |
631 | const Tile* cur = board->tile(at); | 631 | const Tile* cur = board->tile(at); |
632 | if ( cur ) { | 632 | if ( cur ) { |
633 | if ( cur->text()[0] == l ) { | 633 | if ( cur->text()[0] == l ) { |
634 | bool nextok = board->contains(at+d); | 634 | bool nextok = board->contains(at+d); |
635 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) | 635 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) |
636 | noteChoice(tiles,n,d,blankvalues,blused); | 636 | noteChoice(tiles,n,d,blankvalues,blused); |
637 | if ( nextok ) | 637 | if ( nextok ) |
638 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 638 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
639 | // #### text()[1]... | 639 | // #### text()[1]... |
640 | } | 640 | } |
641 | } else { | 641 | } else { |
642 | if ( nletter[l.unicode()] || nletter[0] ) { | 642 | if ( nletter[l.unicode()] || nletter[0] ) { |
643 | int rc = rack->count(); | 643 | int rc = rack->count(); |
644 | ulong msk = 1; | 644 | ulong msk = 1; |
645 | for ( int x=0; x<rc; x++ ) { | 645 | for ( int x=0; x<rc; x++ ) { |
646 | if ( !(used&msk) ) { | 646 | if ( !(used&msk) ) { |
647 | const Tile* t = rack->tileRef(x); | 647 | const Tile* t = rack->tileRef(x); |
648 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s | 648 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s |
649 | bool nextok = board->contains(at+d); | 649 | bool nextok = board->contains(at+d); |
650 | tiles[n++] = t; | 650 | tiles[n++] = t; |
651 | if ( t->isBlank() ) | 651 | if ( t->isBlank() ) |
652 | blankvalues[blused++] = Tile(l,0); | 652 | blankvalues[blused++] = Tile(l,0); |
653 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) | 653 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) |
654 | noteChoice(tiles,n,d,blankvalues,blused); | 654 | noteChoice(tiles,n,d,blankvalues,blused); |
655 | used |= msk; // mark | 655 | used |= msk; // mark |
656 | nletter[t->text()[0].unicode()]--; | 656 | nletter[t->text()[0].unicode()]--; |
657 | if ( nextok ) | 657 | if ( nextok ) |
658 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 658 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
659 | n--; | 659 | n--; |
660 | nletter[t->text()[0].unicode()]++; | 660 | nletter[t->text()[0].unicode()]++; |
661 | if ( t->isBlank() ) { | 661 | if ( t->isBlank() ) { |
662 | // keep looking | 662 | // keep looking |
663 | blused--; | 663 | blused--; |
664 | used &= ~msk; // unmark | 664 | used &= ~msk; // unmark |
665 | } else { | 665 | } else { |
666 | break; | 666 | break; |
667 | } | 667 | } |
668 | } | 668 | } |
669 | } | 669 | } |
670 | msk <<= 1; | 670 | msk <<= 1; |
671 | } | 671 | } |
672 | } | 672 | } |
673 | // #### text()[1]... | 673 | // #### text()[1]... |
674 | } | 674 | } |
675 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); | 675 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); |
676 | } | 676 | } |
677 | 677 | ||
678 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) | 678 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) |
679 | { | 679 | { |
680 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); | 680 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); |
681 | /* | 681 | /* |
682 | if (s>0 || current==QPoint(5,1)){ | 682 | if (s>0 || current==QPoint(5,1)){ |
683 | QString st; | 683 | QString st; |
684 | for ( int i=0; i<n; i++ ) | 684 | for ( int i=0; i<n; i++ ) |
685 | st += tiles[i]->text(); | 685 | st += tiles[i]->text(); |
686 | odebug << "" << current.x() << "," << current.y() << ": " << st.latin1() << " (" << n << ") for " << s << "" << oendl; | 686 | odebug << "" << current.x() << "," << current.y() << ": " << st.latin1() << " (" << n << ") for " << s << "" << oendl; |
687 | } | 687 | } |