算出最佳着法后延迟100ms才执行

This commit is contained in:
CalciteM 2019-07-29 23:25:39 +08:00
parent 476dc231b0
commit 780c448f0b
2 changed files with 18 additions and 6 deletions

View File

@ -20,6 +20,7 @@
*****************************************************************************/
#include <QDebug>
#include <QTimer>
#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

View File

@ -87,10 +87,16 @@ public slots:
// 退出线程
void stop();
// 发射着法信号
void emitCommand();
private:
// 玩家ID
int id;
// 发射的指令
const char* strCommand;
// 互斥锁
QMutex mutex;