diff --git a/NineChess/src/aithread.cpp b/NineChess/src/aithread.cpp index 1e2cedaa..12416c70 100644 --- a/NineChess/src/aithread.cpp +++ b/NineChess/src/aithread.cpp @@ -20,6 +20,7 @@ *****************************************************************************/ #include +#include #include "aithread.h" AiThread::AiThread(int id, QObject *parent) : @@ -85,6 +86,11 @@ void AiThread::setAi(const NineChess &chess, int depth, int time) mutex.unlock(); } +void AiThread::emitCommand() +{ + emit command(strCommand); +} + void AiThread::run() { // 测试用数据 @@ -119,13 +125,13 @@ void AiThread::run() if (ai_ab.alphaBetaPruning(aiDepth) == 3) { qDebug() << "Draw\n"; - const char *str = "draw"; - emit command(str); + strCommand = "draw"; + QTimer::singleShot(100, this, &AiThread::emitCommand); } else { - const char *str = ai_ab.bestMove(); - qDebug() << "Computer:" << str << "\n"; - if (strcmp(str, "error!")) - emit command(str); + strCommand = ai_ab.bestMove(); + qDebug() << "Computer:" << strCommand << "\n"; + if (strcmp(strCommand, "error!")) + QTimer::singleShot(100, this, &AiThread::emitCommand); } #ifdef DEBUG_MODE diff --git a/NineChess/src/aithread.h b/NineChess/src/aithread.h index 218a7160..a870de50 100644 --- a/NineChess/src/aithread.h +++ b/NineChess/src/aithread.h @@ -87,10 +87,16 @@ public slots: // 退出线程 void stop(); + // 发射着法信号 + void emitCommand(); + private: // 玩家ID int id; + // 发射的指令 + const char* strCommand; + // 互斥锁 QMutex mutex;