~ubuntu-branches/debian/sid/chessx/sid

« back to all changes in this revision

Viewing changes to src/database/polyglotdatabase.cpp

  • Committer: Package Import Robot
  • Author(s): Niklas Fiekas
  • Date: 2014-10-06 18:26:02 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20141006182602-4kpiyz31knghkbrq
Tags: 1.2.2-1
* New upstream release.
  - Fix crash and data loss when trying to save a database other than the
    currently selected one.
  - Exclude autogenerated files from source tarball; fixes lintian warning
    source-contains-autogenerated-visual-c++-file.
  - Remove debian/patches/desktop-file.patch; applied upstream.
  - Remove debian/patches/desktop-mime-but-no-exec-code.patch; applied
    upstream.
* debian/chessx.6:
  - Adjust tagline in manpage.
* debian/rules:
  - Remove duplicate QT_SELECT=5.
* debian/control:
  - Update standards version to 3.9.6.0; no relevant changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
456
456
int PolyglotDatabase::find_key(quint64 key, entry_t *entry)
457
457
{
458
458
    entry_t test_entry;
459
 
    // qDebug() << key << endl;
460
459
    while(!entry_from_file(&test_entry))
461
460
    {
462
461
        if (key==test_entry.key)
473
472
    return -1;
474
473
}
475
474
 
 
475
// ---------------------------------------------------------
 
476
// Book parser - public interface
 
477
// ---------------------------------------------------------
 
478
 
476
479
bool PolyglotDatabase::findMove(quint64 key, MoveData& m)
477
480
{
478
481
    entry_t entry;
515
518
    }
516
519
}
517
520
 
 
521
// ---------------------------------------------------------
 
522
// Book building - public interface
 
523
// ---------------------------------------------------------
 
524
 
518
525
bool PolyglotDatabase::openForWriting(const QString &filename, int maxPly, int minGame, bool uniform)
519
526
{
520
527
    if(m_file)
530
537
    return openFile(filename, false);
531
538
}
532
539
 
533
 
// ---------------------------------------------------------
534
 
// Book building - public interface
535
 
// ---------------------------------------------------------
536
 
 
537
540
void PolyglotDatabase::book_make(Database &db, volatile bool& breakFlag)
538
541
{
539
 
    qDebug() << "Adding Databse" << endl;
540
542
    if (!breakFlag) add_database(db);
541
 
    qDebug() << "Overflow Correction" << endl;
 
543
    if (!breakFlag) spool_map();
542
544
    if (!breakFlag) overflow_correction();
543
 
    qDebug() << "Filter" << endl;
544
545
    if (!breakFlag) book_filter();
545
 
    qDebug() << "Sort" << endl;
546
546
    if (!breakFlag) book_sort();
547
 
    qDebug() << "Save" << endl;
548
547
    if (!breakFlag) book_save();
549
 
    qDebug() << "Close" << endl;
550
548
    close();
551
 
    qDebug() << "Done" << endl;
552
549
}
553
550
 
554
551
// ---------------------------------------------------------
587
584
    }
588
585
}
589
586
 
 
587
void PolyglotDatabase::spool_map()
 
588
{
 
589
    foreach(book_key k, m_bookDictionary.keys())
 
590
    {
 
591
        book_entry b(k, m_bookDictionary.value(k));
 
592
        m_book.append(b);
 
593
    }
 
594
    m_bookDictionary.clear();
 
595
}
 
596
 
590
597
void PolyglotDatabase::overflow_correction()
591
598
{
592
599
    for (Book::iterator i=m_book.begin(); i!=m_book.end();++i)
613
620
 
614
621
void PolyglotDatabase::update_entry(book_entry& entry, int result)
615
622
{
616
 
    if (book_entry* b = find_entry(entry))
617
 
    {
618
 
        b->n++;
619
 
        b->sum += result + 1;
620
 
    }
621
 
    else
622
 
    {
623
 
        entry.n = 1;
624
 
        entry.sum = result + 1;
625
 
        m_book.append(entry);
626
 
    }
 
623
    book_key key;
 
624
    key.key = entry.key;
 
625
    key.move = entry.move;
 
626
 
 
627
    book_value b = m_bookDictionary.value(key);
 
628
 
 
629
    b.n++;
 
630
    b.sum += result + 1;
 
631
 
 
632
    m_bookDictionary[key] = b;
627
633
}
628
634
 
629
635
void PolyglotDatabase::book_sort()
732
738
 
733
739
            // Get a move in ChessX format
734
740
            entry.key = getHashFromBoard(g.board());
735
 
            // qDebug() << entry.key << endl;
736
741
 
737
742
            g.forward();
738
743
            Move m = g.move();
739
 
            // qDebug() << m.from() << "-" << m.to() << endl;
740
744
 
741
745
            // convert into polyglot move format
742
746
            if (!get_move_entry(m,entry))