Book: 启用开局学习并实现将开局库导出到文件的特性
This commit is contained in:
parent
6f60b425c8
commit
044991678f
|
@ -66,6 +66,10 @@ GameController::~GameController()
|
|||
ai2.stop();
|
||||
ai1.wait();
|
||||
ai2.wait();
|
||||
|
||||
#ifdef BOOK_LEARNING
|
||||
NineChessAi_ab::recordOpeningBookHashMapToFile();
|
||||
#endif /* BOOK_LEARNING */
|
||||
}
|
||||
|
||||
const QMap<int, QStringList> GameController::getActions()
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <QFile>
|
||||
#include <iostream>
|
||||
#include "HashNode.h"
|
||||
|
||||
#include "config.h"
|
||||
|
@ -111,6 +113,28 @@ namespace CTSL //Concurrent Thread Safe Library
|
|||
#endif
|
||||
}
|
||||
|
||||
//Function to dump the hash map to file
|
||||
void dump(const QString &filename)
|
||||
{
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write((char *)hashTable, sizeof(HashNode<K, V>) * hashSize);
|
||||
file.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
//Function to load the hash map from file
|
||||
void load(const QString &filename)
|
||||
{
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
file.read((char *)hashTable, sizeof(HashNode<K, V>) * hashSize);
|
||||
file.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef DISABLE_HASHBUCKET
|
||||
HashNode<K, V> *hashTable;
|
||||
|
|
|
@ -132,6 +132,11 @@ NineChess::NineChess()
|
|||
constructHash();
|
||||
#endif
|
||||
|
||||
#ifdef BOOK_LEARNING
|
||||
// TODO: 开局库文件被加载了多次
|
||||
NineChessAi_ab::loadOpeningBookFileToHashMap();
|
||||
#endif
|
||||
|
||||
// 默认选择第1号规则,即“打三棋”
|
||||
setContext(&RULES[1]);
|
||||
|
||||
|
|
|
@ -1096,4 +1096,18 @@ void NineChessAi_ab::recordOpeningBookToHashMap()
|
|||
|
||||
openingBook.clear();
|
||||
}
|
||||
|
||||
void NineChessAi_ab::recordOpeningBookHashMapToFile()
|
||||
{
|
||||
const QString bookFileName = "opening-book.txt";
|
||||
qDebug() << "Dump Opening Book to file...";
|
||||
bookHashMap.dump(bookFileName);
|
||||
}
|
||||
|
||||
void NineChessAi_ab::loadOpeningBookFileToHashMap()
|
||||
{
|
||||
const QString bookFileName = "opening-book.txt";
|
||||
qDebug() << "Loading Opening Book from file...";
|
||||
bookHashMap.load(bookFileName);
|
||||
}
|
||||
#endif // BOOK_LEARNING
|
||||
|
|
|
@ -116,6 +116,8 @@ public:
|
|||
static int recordBookHash(uint64_t hash, const HashValue &hashValue);
|
||||
void clearBookHashMap();
|
||||
static void recordOpeningBookToHashMap();
|
||||
static void recordOpeningBookHashMapToFile();
|
||||
static void loadOpeningBookFileToHashMap();
|
||||
#endif // BOOK_LEARNING
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue