From 5c34a678ded24782da1dc7ac96f15b7fc03f9175 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 5 Sep 2020 01:40:40 +0800 Subject: [PATCH] =?UTF-8?q?analyze:=20=E6=A0=87=E6=98=8E=E6=98=AF=E9=9D=A2?= =?UTF-8?q?=E5=90=91=E5=93=AA=E6=96=B9=E7=9A=84=E5=B1=80=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/aithread.cpp | 36 ++++++++++++++++++------------------ src/aithread.h | 2 +- src/ui/qt/gamecontroller.cpp | 14 ++++++++------ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/aithread.cpp b/src/aithread.cpp index ef75c094..2755975b 100644 --- a/src/aithread.cpp +++ b/src/aithread.cpp @@ -128,7 +128,7 @@ void sq2str(char *str) } #endif // OPENING_BOOK -void AiThread::analyze() +void AiThread::analyze(Color c) { int d = (int)ai.originDepth; int v = (int)ai.bestvalue; @@ -137,6 +137,9 @@ void AiThread::analyze() bool lose = v <= -VALUE_MATE; int p = v / VALUE_EACH_PIECE; + string strUs = (c == BLACK ? "黑方" : "白方"); + string strThem = (c == BLACK ? "白方" : "黑方"); + cout << *ai.position() << endl; if (v == VALUE_UNIQUE) { @@ -145,57 +148,57 @@ void AiThread::analyze() } if (lv < -VALUE_EACH_PIECE && v == 0) { - cout << "坏棋, 被拉回均势!" << endl; + cout << strThem << "坏棋, 被" << strUs << "拉回均势!" << endl; } if (lv < 0 && v > 0) { - cout << "坏棋, 被翻转了局势!" << endl; + cout << strThem << "坏棋, 被" << strUs << "翻转了局势!" << endl; } if (lv == 0 && v > VALUE_EACH_PIECE) { - cout << "败着!" << endl; + cout << strThem << "败着!" << endl; } if (lv > VALUE_EACH_PIECE && v == 0) { - cout << "好棋, 拉回均势!" << endl; + cout << strThem << "好棋, 拉回均势!" << endl; } if (lv > 0 && v < 0) { - cout << "好棋, 翻转了局势!" << endl; + cout << strThem << "好棋, 翻转了局势!" << endl; } if (lv == 0 && v < -VALUE_EACH_PIECE) { - cout << "秒棋!" << endl; + cout << strThem << "秒棋!" << endl; } if (lv != v) { if (lv < 0 && v < 0) { if (abs(lv) < abs(v)) { - cout << "领先幅度扩大" << endl; + cout << strThem << "领先幅度扩大" << endl; } else if (abs(lv) > abs(v)) { - cout << "领先幅度缩小" << endl; + cout << strThem << "领先幅度缩小" << endl; } } if (lv > 0 && v > 0) { if (abs(lv) < abs(v)) { - cout << "落后幅度扩大" << endl; + cout << strThem << "落后幅度扩大" << endl; } else if (abs(lv) > abs(v)) { - cout << "落后幅度缩小" << endl; + cout << strThem << "落后幅度缩小" << endl; } } } if (win) { - cout << "将在 " << d << " 步后输棋!" << endl; + cout << strThem << "将在 " << d << " 步后输棋!" << endl; } else if (lose) { - cout << "将在 " << d << " 步后赢棋!" << endl; + cout << strThem << "将在 " << d << " 步后赢棋!" << endl; } else if (p == 0) { cout << "将在 " << d << " 步后双方保持均势" << endl; } else if (p > 0) { - cout << "将在 " << d << " 步后落后 " << p << " 子" << endl; + cout << strThem << "将在 " << d << " 步后落后 " << p << " 子" << endl; } else if (p < 0) { - cout << "将在 " << d << " 步后领先 " << -p << " 子" << endl; + cout << strThem << "将在 " << d << " 步后领先 " << -p << " 子" << endl; } cout << endl << endl; @@ -253,10 +256,7 @@ void AiThread::run() } else { strCommand = ai.nextMove(); if (strCommand && strcmp(strCommand, "error!") != 0) { - loggerDebug("Computer: %s\n\n", strCommand); - emitCommand(); - //analyze(); } } #ifdef OPENING_BOOK diff --git a/src/aithread.h b/src/aithread.h index e86a467a..56597496 100644 --- a/src/aithread.h +++ b/src/aithread.h @@ -68,7 +68,7 @@ public: return timeLimit; } - void analyze(); + void analyze(Color c); public slots: void act(); // Force move, not quit thread diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index 526feadf..47f26c30 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -940,7 +940,10 @@ bool GameController::command(const QString &cmd, bool update /* = true */) gameStart(); } - if (!position.command(cmd.toStdString().c_str())) + string command = cmd.toStdString(); + loggerDebug("Computer: %s\n\n", command.c_str()); + + if (!position.command(command.c_str())) return false; #ifndef TRAINING_MODE @@ -949,7 +952,6 @@ bool GameController::command(const QString &cmd, bool update /* = true */) } if (update) { - //cout << position << endl; playSound(soundType, position.side_to_move()); updateScence(&position); } @@ -1082,10 +1084,10 @@ bool GameController::command(const QString &cmd, bool update /* = true */) } #endif // TRAINING_MODE - if (isAiPlayer[BLACK]) { - aiThread[BLACK]->analyze(); - } else if (isAiPlayer[WHITE]) { - aiThread[WHITE]->analyze(); + if (isAiPlayer[WHITE]) { + aiThread[WHITE]->analyze(WHITE); + } else if (isAiPlayer[BLACK]) { + aiThread[BLACK]->analyze(BLACK); } return true;