openingbook: 新增开局库部分代码 (未完成)

This commit is contained in:
Calcitem 2020-05-03 23:49:18 +08:00
parent 79c10960c8
commit 4013b5bb7f
3 changed files with 81 additions and 7 deletions

View File

@ -115,6 +115,9 @@
//#define RAPID_GAME
// WIP, Debugging only
//#define OPENING_BOOK
//#define ENDGAME_LEARNING
//#define ENDGAME_LEARNING_FORCE
//#define ENDGAME_LEARNING_DEBUG

View File

@ -22,6 +22,11 @@
#include "tt.h"
#include "player.h"
#ifdef OPENING_BOOK
#include <deque>
using namespace std;
#endif
AiThread::AiThread(int id, QObject *parent) :
QThread(parent),
state(nullptr),
@ -97,6 +102,49 @@ move_t computeMove(StateInfo state,
const MCTSOptions options);
#endif // MCTS_AI
#ifdef OPENING_BOOK
deque<int> openingBookDeque(
{
/* B W */
21, 23,
19, 20,
17, 18,
15, 10,
26, 12,
28, 11,
27, 9, -15,
29, -12, 25,
13, -25
}
);
deque<int> openingBookDequeBak;
void sq2str(char *str)
{
int sq = openingBookDeque.front();
openingBookDeque.pop_front();
openingBookDequeBak.push_back(sq);
int r = 0;
int s = 0;
int sig = 1;
if (sq < 0) {
sq = -sq;
sig = 0;
}
Board::squareToPolar((square_t)sq, r, s);
if (sig == 1) {
sprintf_s(str, 16, "(%d,%d)", r, s);
} else {
sprintf_s(str, 16, "-(%d,%d)", r, s);
}
}
#endif // OPENING_BOOK
void AiThread::run()
{
// 测试用数据
@ -133,18 +181,30 @@ void AiThread::run()
emitCommand();
#else // MCTS_AI
if (ai.search(depth) == 3) {
// 三次重复局面和
loggerDebug("Draw\n\n");
strCommand = "draw";
#ifdef OPENING_BOOK
// gameOptions.getOpeningBook()
if (!openingBookDeque.empty()) {
char obc[16] = { 0 };
sq2str(obc);
strCommand = obc;
emitCommand();
} else {
strCommand = ai.ttMove();
if (strCommand && strcmp(strCommand, "error!") != 0) {
loggerDebug("Computer: %s\n\n", strCommand);
#endif
if (ai.search(depth) == 3) {
// 三次重复局面和
loggerDebug("Draw\n\n");
strCommand = "draw";
emitCommand();
} else {
strCommand = ai.ttMove();
if (strCommand && strcmp(strCommand, "error!") != 0) {
loggerDebug("Computer: %s\n\n", strCommand);
emitCommand();
}
}
#ifdef OPENING_BOOK
}
#endif
#endif // MCTS_AI

View File

@ -141,6 +141,10 @@ const map<int, QStringList> GameController::getActions()
return actions;
}
#ifdef OPENING_BOOK
extern deque<int> openingBookDeque;
extern deque<int> openingBookDequeBak;
#endif
void GameController::gameStart()
{
@ -154,6 +158,13 @@ void GameController::gameStart()
gameStartTime = now();
gameStartCycle = stopwatch::rdtscp_clock::now();
#ifdef OPENING_BOOK
if (openingBookDeque.empty() && !openingBookDequeBak.empty()) {
openingBookDeque = openingBookDequeBak;
openingBookDequeBak.clear();
}
#endif
}
void GameController::gameReset()