去除 EMIT_COMMAND_DELAY

QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
改为:
emitCommand();

顺带将 i/id 重命名为 sideId/playerId.
This commit is contained in:
Calcitem 2019-11-03 20:23:01 +08:00
parent 9d2f548220
commit 22ffd83b19
3 changed files with 7 additions and 17 deletions

View File

@ -34,11 +34,9 @@
//#define DEBUG_MODE_A //#define DEBUG_MODE_A
#ifdef DEBUG_MODE_A #ifdef DEBUG_MODE_A
#define EMIT_COMMAND_DELAY (0)
#define DONOT_PLAY_SOUND #define DONOT_PLAY_SOUND
#else #else
#define RANDOM_MOVE #define RANDOM_MOVE
#define EMIT_COMMAND_DELAY (0)
#endif #endif
#define DEFAULT_RULE_NUMBER 1 #define DEFAULT_RULE_NUMBER 1

View File

@ -29,7 +29,7 @@ AiThread::AiThread(int id, QObject *parent) :
depth(2), depth(2),
timeLimit(3600) timeLimit(3600)
{ {
this->id = id; this->playerId = id;
// 连接定时器启动减去118毫秒的返回时间 // 连接定时器启动减去118毫秒的返回时间
connect(this, &AiThread::calcStarted, this, [=]() {timer.start(timeLimit * 1000 - 118); }, Qt::QueuedConnection); connect(this, &AiThread::calcStarted, this, [=]() {timer.start(timeLimit * 1000 - 118); }, Qt::QueuedConnection);
@ -101,16 +101,16 @@ void AiThread::run()
#endif #endif
// 设一个标识1号线程只管玩家12号线程只管玩家2 // 设一个标识1号线程只管玩家12号线程只管玩家2
int i = 0; int sideId = 0;
loggerDebug("Thread %d start\n", id); loggerDebug("Thread %d start\n", playerId);
while (!isInterruptionRequested()) { while (!isInterruptionRequested()) {
mutex.lock(); 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); pauseCondition.wait(&mutex);
mutex.unlock(); mutex.unlock();
continue; continue;
@ -124,20 +124,12 @@ void AiThread::run()
// 三次重复局面和 // 三次重复局面和
loggerDebug("Draw\n\n"); loggerDebug("Draw\n\n");
strCommand = "draw"; strCommand = "draw";
#ifdef TRAINING_MODE
emitCommand(); emitCommand();
#else
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
#endif
} else { } else {
strCommand = ai.bestMove(); strCommand = ai.bestMove();
if (strCommand && strcmp(strCommand, "error!") != 0) { if (strCommand && strcmp(strCommand, "error!") != 0) {
loggerDebug("Computer: %s\n\n", strCommand); loggerDebug("Computer: %s\n\n", strCommand);
#ifdef TRAINING_MODE
emitCommand(); emitCommand();
#else
QTimer::singleShot(EMIT_COMMAND_DELAY, this, &AiThread::emitCommand);
#endif
} }
} }
@ -151,7 +143,7 @@ void AiThread::run()
mutex.unlock(); mutex.unlock();
} }
loggerDebug("Thread %d quit\n", id); loggerDebug("Thread %d quit\n", playerId);
} }
void AiThread::act() void AiThread::act()

View File

@ -95,7 +95,7 @@ public slots:
public: public:
// 玩家ID // 玩家ID
int id; int playerId;
private: private: