ui: 去除深度设置

This commit is contained in:
Calcitem 2020-07-11 19:31:11 +08:00
parent 11916ae98b
commit b4f4d80070
7 changed files with 18 additions and 52 deletions

View File

@ -33,7 +33,6 @@ using namespace std;
AiThread::AiThread(int color, QObject *parent) : AiThread::AiThread(int color, QObject *parent) :
QThread(parent), QThread(parent),
position(nullptr), position(nullptr),
depth(2),
timeLimit(3600) timeLimit(3600)
{ {
this->us = color; this->us = color;
@ -77,12 +76,11 @@ void AiThread::setAi(Position *p)
mutex.unlock(); mutex.unlock();
} }
void AiThread::setAi(Position *p, Depth d, int tl) void AiThread::setAi(Position *p, int tl)
{ {
mutex.lock(); mutex.lock();
this->position = p; this->position = p;
ai.setPosition(p); ai.setPosition(p);
depth = d;
timeLimit = tl; timeLimit = tl;
mutex.unlock(); mutex.unlock();
} }
@ -246,7 +244,7 @@ void AiThread::run()
emitCommand(); emitCommand();
} else { } else {
#endif #endif
if (ai.search(depth) == 3) { if (ai.search() == 3) {
loggerDebug("Draw\n\n"); loggerDebug("Draw\n\n");
strCommand = "draw"; strCommand = "draw";
emitCommand(); emitCommand();

View File

@ -51,7 +51,7 @@ protected:
public: public:
void setAi(Position *p); void setAi(Position *p);
void setAi(Position *p, Depth depth, int time); void setAi(Position *p, int time);
Server *getServer() Server *getServer()
{ {
@ -63,11 +63,6 @@ public:
return client; return client;
} }
Depth getDepth()
{
return depth;
}
int getTimeLimit() int getTimeLimit()
{ {
return timeLimit; return timeLimit;
@ -98,7 +93,6 @@ public: // TODO: Change to private
AIAlgorithm ai; AIAlgorithm ai;
private: private:
Depth depth;
int timeLimit; int timeLimit;
QTimer timer; QTimer timer;

View File

@ -66,9 +66,9 @@ AIAlgorithm::~AIAlgorithm()
//delete pos; //delete pos;
} }
Depth AIAlgorithm::changeDepth(Depth origDepth) Depth AIAlgorithm::changeDepth()
{ {
Depth d = origDepth; Depth d = 0;
#ifdef _DEBUG #ifdef _DEBUG
Depth reduce = 0; Depth reduce = 0;
@ -183,11 +183,11 @@ void AIAlgorithm::setPosition(Position *p)
} }
#ifdef ALPHABETA_AI #ifdef ALPHABETA_AI
int AIAlgorithm::search(Depth depth) int AIAlgorithm::search()
{ {
Value value = VALUE_ZERO; Value value = VALUE_ZERO;
Depth d = changeDepth(depth); Depth d = changeDepth();
time_t time0 = time(nullptr); time_t time0 = time(nullptr);
srand(static_cast<unsigned int>(time0)); srand(static_cast<unsigned int>(time0));

View File

@ -158,7 +158,7 @@ public:
} }
#ifdef ALPHABETA_AI #ifdef ALPHABETA_AI
int search(Depth depth); int search();
const char *nextMove(); const char *nextMove();
#endif // ALPHABETA_AI #endif // ALPHABETA_AI
@ -215,7 +215,7 @@ public: /* TODO: Move to private or protected */
public: public:
const char *moveToCommand(Move move); const char *moveToCommand(Move move);
protected: protected:
Depth changeDepth(Depth origDepth); Depth changeDepth();
public: public:
MovePicker *movePicker { nullptr }; MovePicker *movePicker { nullptr };

View File

@ -362,22 +362,19 @@ void GameController::setEngine2(bool arg)
setEngine(2, arg); setEngine(2, arg);
} }
void GameController::setAiDepthTime(Depth depth1, int time1, Depth depth2, int time2) void GameController::setAiDepthTime(int time1, int time2)
{ {
stopAndWaitAiThreads(); stopAndWaitAiThreads();
aiThread[BLACK]->setAi(position, depth1, time1); aiThread[BLACK]->setAi(position, time1);
aiThread[WHITE]->setAi(position, depth2, time2); aiThread[WHITE]->setAi(position, time2);
startAiThreads(); startAiThreads();
} }
void GameController::getAiDepthTime(Depth &depth1, int &time1, Depth &depth2, int &time2) void GameController::getAiDepthTime(int &time1, int &time2)
{ {
depth1 = aiThread[BLACK]->getDepth();
time1 = aiThread[BLACK]->getTimeLimit(); time1 = aiThread[BLACK]->getTimeLimit();
depth2 = aiThread[WHITE]->getDepth();
time2 = aiThread[WHITE]->getTimeLimit(); time2 = aiThread[WHITE]->getTimeLimit();
} }

View File

@ -126,8 +126,8 @@ public:
return &manualListModel; return &manualListModel;
} }
void setAiDepthTime(Depth depth1, int time1, Depth depth2, int time2); void setAiDepthTime(int time1, int time2);
void getAiDepthTime(Depth &depth1, int &time1, Depth &depth2, int &time2); void getAiDepthTime(int &time1, int &time2);
void humanGiveUp(); void humanGiveUp();

View File

@ -961,14 +961,10 @@ void MillGameWindow::on_actionEngine_E_triggered()
auto *groupBox2 = new QGroupBox(dialog); auto *groupBox2 = new QGroupBox(dialog);
auto *hLayout1 = new QHBoxLayout; auto *hLayout1 = new QHBoxLayout;
auto *label_depth1 = new QLabel(dialog);
auto *spinBox_depth1 = new QSpinBox(dialog);
auto *label_time1 = new QLabel(dialog); auto *label_time1 = new QLabel(dialog);
auto *spinBox_time1 = new QSpinBox(dialog); auto *spinBox_time1 = new QSpinBox(dialog);
auto *hLayout2 = new QHBoxLayout; auto *hLayout2 = new QHBoxLayout;
auto *label_depth2 = new QLabel(dialog);
auto *spinBox_depth2 = new QSpinBox(dialog);
auto *label_time2 = new QLabel(dialog); auto *label_time2 = new QLabel(dialog);
auto *spinBox_time2 = new QSpinBox(dialog); auto *spinBox_time2 = new QSpinBox(dialog);
@ -976,17 +972,11 @@ void MillGameWindow::on_actionEngine_E_triggered()
// 设置各个控件数据 // 设置各个控件数据
groupBox1->setTitle(tr("玩家1 AI设置")); groupBox1->setTitle(tr("玩家1 AI设置"));
label_depth1->setText(tr("深度"));
spinBox_depth1->setMinimum(1);
spinBox_depth1->setMaximum(99);
label_time1->setText(tr("限时")); label_time1->setText(tr("限时"));
spinBox_time1->setMinimum(1); spinBox_time1->setMinimum(1);
spinBox_time1->setMaximum(3600); spinBox_time1->setMaximum(3600);
groupBox2->setTitle(tr("玩家2 AI设置")); groupBox2->setTitle(tr("玩家2 AI设置"));
label_depth2->setText(tr("深度"));
spinBox_depth2->setMinimum(1);
spinBox_depth2->setMaximum(99);
label_time2->setText(tr("限时")); label_time2->setText(tr("限时"));
spinBox_time2->setMinimum(1); spinBox_time2->setMinimum(1);
spinBox_time2->setMaximum(3600); spinBox_time2->setMaximum(3600);
@ -1002,12 +992,8 @@ void MillGameWindow::on_actionEngine_E_triggered()
vLayout->addWidget(buttonBox); vLayout->addWidget(buttonBox);
groupBox1->setLayout(hLayout1); groupBox1->setLayout(hLayout1);
groupBox2->setLayout(hLayout2); groupBox2->setLayout(hLayout2);
hLayout1->addWidget(label_depth1);
hLayout1->addWidget(spinBox_depth1);
hLayout1->addWidget(label_time1); hLayout1->addWidget(label_time1);
hLayout1->addWidget(spinBox_time1); hLayout1->addWidget(spinBox_time1);
hLayout2->addWidget(label_depth2);
hLayout2->addWidget(spinBox_depth2);
hLayout2->addWidget(label_time2); hLayout2->addWidget(label_time2);
hLayout2->addWidget(spinBox_time2); hLayout2->addWidget(spinBox_time2);
@ -1016,31 +1002,22 @@ void MillGameWindow::on_actionEngine_E_triggered()
connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
// 目前数据 // 目前数据
Depth depth1, depth2;
int time1, time2; int time1, time2;
gameController->getAiDepthTime(depth1, time1, depth2, time2); gameController->getAiDepthTime(time1, time2);
spinBox_depth1->setValue(depth1);
spinBox_depth2->setValue(depth2);
spinBox_time1->setValue(time1); spinBox_time1->setValue(time1);
spinBox_time2->setValue(time2); spinBox_time2->setValue(time2);
// 新设数据 // 新设数据
if (dialog->exec() == QDialog::Accepted) { if (dialog->exec() == QDialog::Accepted) {
Depth depth1_new, depth2_new;
int time1_new, time2_new; int time1_new, time2_new;
depth1_new = static_cast<Depth>(spinBox_depth1->value());
depth2_new = static_cast<Depth>(spinBox_depth2->value());
time1_new = spinBox_time1->value(); time1_new = spinBox_time1->value();
time2_new = spinBox_time2->value(); time2_new = spinBox_time2->value();
if (depth1 != depth1_new || if (time1 != time1_new ||
depth2 != depth2_new ||
time1 != time1_new ||
time2 != time2_new) { time2 != time2_new) {
// 重置AI // 重置AI
gameController->setAiDepthTime(depth1_new, time1_new, depth2_new, time2_new); gameController->setAiDepthTime(time1_new, time2_new);
} }
} }