nextMove() 返回值改为 string

并且 command 类型由 QString 改为 string。
This commit is contained in:
Calcitem 2020-09-07 01:03:34 +08:00
parent e1ecfcc2df
commit d26c78580f
12 changed files with 39 additions and 29 deletions

View File

@ -293,7 +293,7 @@ void AiThread::run()
emitCommand();
} else {
strCommand = ai.nextMove();
if (strCommand && strcmp(strCommand, "error!") != 0) {
if (strCommand != "" && strCommand != "error!") {
emitCommand();
}
}

View File

@ -40,7 +40,7 @@ public:
~AiThread() override;
signals:
void command(const QString &cmdline, bool update = true);
void command(const string &cmdline, bool update = true);
void searchStarted();
@ -80,7 +80,7 @@ public:
int us;
private:
const char* strCommand {};
string strCommand;
QMutex mutex;
// For ext in future

View File

@ -522,9 +522,9 @@ int AIAlgorithm::search()
#endif // ALPHABETA_AI
#ifdef ALPHABETA_AI
const char* AIAlgorithm::nextMove()
string AIAlgorithm::nextMove()
{
return UCI::move(bestMove).c_str();
return UCI::move(bestMove);
#if 0
char charSelect = '*';

View File

@ -151,7 +151,7 @@ public:
#ifdef ALPHABETA_AI
int search();
const char *nextMove();
string nextMove();
#endif // ALPHABETA_AI
void undo_move();

View File

@ -217,7 +217,7 @@ void Test::readFromMemory()
memset(to, 0, SHARED_MEMORY_SIZE);
sharedMemory.unlock();
readStr = str;
emit command(str);
emit command(str.toStdString());
}
}
}

View File

@ -29,6 +29,9 @@
#include <QString>
#include <QBuffer>
#include <QDialog>
#include <string>
using std::string;
class Test : public QDialog
{
@ -51,7 +54,7 @@ public:
void stop();
signals:
void command(const QString &cmd, bool update = true);
void command(const string &cmd, bool update = true);
public slots:
void writeToMemory(const QString &str);

View File

@ -139,7 +139,7 @@ void Client::readAction()
currentAction = nextAction;
statusLabel->setText(currentAction);
emit command(currentAction);
emit command(currentAction.toStdString());
getActionButton->setEnabled(true);
QTimer::singleShot(10, this, &Client::requestNewAction);

View File

@ -23,6 +23,9 @@
#include <QDataStream>
#include <QDialog>
#include <QTcpSocket>
#include <string>
using std::string;
QT_BEGIN_NAMESPACE
class QComboBox;
@ -41,7 +44,7 @@ public:
explicit Client(QWidget *parent = nullptr, uint16_t port = 33333);
signals:
void command(const QString &cmd, bool update = true);
void command(const string &cmd, bool update = true);
private slots:
void requestNewAction();

View File

@ -79,19 +79,21 @@ GameController::GameController(
gameTest = new Test();
// 关联AI和控制器的着法命令行
connect(aiThread[BLACK], SIGNAL(command(const QString &, bool)),
this, SLOT(command(const QString &, bool)));
connect(aiThread[WHITE], SIGNAL(command(const QString &, bool)),
this, SLOT(command(const QString &, bool)));
qRegisterMetaType<std::string>("string");
connect(this->gameTest, SIGNAL(command(const QString &, bool)),
this, SLOT(command(const QString &, bool)));
// 关联AI和控制器的着法命令行
connect(aiThread[BLACK], SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
connect(aiThread[WHITE], SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
connect(this->gameTest, SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
#ifndef TRAINING_MODE
// 关联AI和网络类的着法命令行
connect(aiThread[BLACK]->getClient(), SIGNAL(command(const QString &, bool)),
this, SLOT(command(const QString &, bool)));
connect(aiThread[BLACK]->getClient(), SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
#endif // TRAINING_MODE
#ifdef ENDGAME_LEARNING_FORCE
@ -905,7 +907,7 @@ bool GameController::giveUp()
}
// 关键槽函数棋谱的命令行执行与actionPiece独立
bool GameController::command(const QString &cmd, bool update /* = true */)
bool GameController::command(const string &cmd, bool update /* = true */)
{
#ifndef TRAINING_MODE
Q_UNUSED(hasSound)
@ -940,10 +942,9 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
gameStart();
}
string command = cmd.toStdString();
loggerDebug("Computer: %s\n\n", command.c_str());
loggerDebug("Computer: %s\n\n", cmd.c_str());
if (!position.command(command.c_str()))
if (!position.command(cmd.c_str()))
return false;
#ifndef TRAINING_MODE
@ -1073,14 +1074,14 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
#endif
}
gameTest->writeToMemory(cmd);
gameTest->writeToMemory(QString::fromStdString(cmd));
#ifndef TRAINING_MODE
// 网络: 将着法放到服务器的发送列表中
if (isAiPlayer[BLACK]) {
aiThread[BLACK]->getServer()->setAction(cmd);
aiThread[BLACK]->getServer()->setAction(QString::fromStdString(cmd));
} else if (isAiPlayer[WHITE]) {
aiThread[BLACK]->getServer()->setAction(cmd); // 注意: 同样是 aiThread[BLACK]
aiThread[BLACK]->getServer()->setAction(QString::fromStdString(cmd)); // 注意: 同样是 aiThread[BLACK]
}
#endif // TRAINING_MODE

View File

@ -320,7 +320,7 @@ public slots:
bool giveUp();
// 棋谱的命令行执行
bool command(const QString &cmd, bool update = true);
bool command(const string &cmd, bool update = true);
// 历史局面及局面改变
bool phaseChange(int row, bool forceUpdate = false);

View File

@ -691,7 +691,7 @@ void MillGameWindow::on_actionOpen_O_triggered()
cmd = textStream.readLine();
// 读取并显示棋谱时,不必刷新棋局场景
if (!(gameController->command(cmd, false))) {
if (!(gameController->command(cmd.toStdString(), false))) {
// 定义新对话框
QMessageBox msgBox(QMessageBox::Warning, tr("文件错误"), tr("不是正确的棋谱文件"), QMessageBox::Ok);
msgBox.exec();
@ -700,7 +700,7 @@ void MillGameWindow::on_actionOpen_O_triggered()
while (!textStream.atEnd()) {
cmd = textStream.readLine();
gameController->command(cmd, false);
gameController->command(cmd.toStdString(), false);
}
// 最后刷新棋局场景

View File

@ -24,9 +24,12 @@
#include <QString>
#include <QVector>
#include <queue>
#include <string>
#include "config.h"
using std::string;
QT_BEGIN_NAMESPACE
class QLabel;
class QTcpServer;