From 22ffd83b196d48e99601f8347356e9df61ef21a0 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 3 Nov 2019 20:23:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=20EMIT=5FCOMMAND=5FDELAY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand); 改为: emitCommand(); 顺带将 i/id 重命名为 sideId/playerId. --- include/config.h | 2 -- src/base/thread.cpp | 20 ++++++-------------- src/base/thread.h | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/include/config.h b/include/config.h index 1ae12e46..4663b205 100644 --- a/include/config.h +++ b/include/config.h @@ -34,11 +34,9 @@ //#define DEBUG_MODE_A #ifdef DEBUG_MODE_A -#define EMIT_COMMAND_DELAY (0) #define DONOT_PLAY_SOUND #else #define RANDOM_MOVE -#define EMIT_COMMAND_DELAY (0) #endif #define DEFAULT_RULE_NUMBER 1 diff --git a/src/base/thread.cpp b/src/base/thread.cpp index df4de85f..d32f8866 100644 --- a/src/base/thread.cpp +++ b/src/base/thread.cpp @@ -29,7 +29,7 @@ AiThread::AiThread(int id, QObject *parent) : depth(2), timeLimit(3600) { - this->id = id; + this->playerId = id; // 连接定时器启动,减去118毫秒的返回时间 connect(this, &AiThread::calcStarted, this, [=]() {timer.start(timeLimit * 1000 - 118); }, Qt::QueuedConnection); @@ -101,16 +101,16 @@ void AiThread::run() #endif // 设一个标识,1号线程只管玩家1,2号线程只管玩家2 - int i = 0; + int sideId = 0; - loggerDebug("Thread %d start\n", id); + loggerDebug("Thread %d start\n", playerId); while (!isInterruptionRequested()) { mutex.lock(); - i = Player::toId(game->position.sideToMove); + sideId = Player::toId(game->position.sideToMove); - if (i != id || waiting) { + if (sideId != playerId || waiting) { pauseCondition.wait(&mutex); mutex.unlock(); continue; @@ -124,20 +124,12 @@ void AiThread::run() // 三次重复局面和 loggerDebug("Draw\n\n"); strCommand = "draw"; -#ifdef TRAINING_MODE emitCommand(); -#else - QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand); -#endif } else { strCommand = ai.bestMove(); if (strCommand && strcmp(strCommand, "error!") != 0) { loggerDebug("Computer: %s\n\n", strCommand); -#ifdef TRAINING_MODE emitCommand(); -#else - QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand); -#endif } } @@ -151,7 +143,7 @@ void AiThread::run() mutex.unlock(); } - loggerDebug("Thread %d quit\n", id); + loggerDebug("Thread %d quit\n", playerId); } void AiThread::act() diff --git a/src/base/thread.h b/src/base/thread.h index 183ba776..37d13665 100644 --- a/src/base/thread.h +++ b/src/base/thread.h @@ -95,7 +95,7 @@ public slots: public: // 玩家ID - int id; + int playerId; private: