refactor: 去掉成员变量结尾的下划线

第三方库不处理.
This commit is contained in:
Calcitem 2019-09-28 10:21:07 +08:00
parent 4b0569ea65
commit d6574b0fcb
15 changed files with 215 additions and 215 deletions

View File

@ -284,7 +284,7 @@ void AIAlgorithm::deleteTree(Node *node)
#endif #endif
} }
void AIAlgorithm::setGame(const Game &game) void AIAlgorithm::setGame(const Game &g)
{ {
// 如果规则改变重建hashmap // 如果规则改变重建hashmap
if (strcmp(rule.name, rule.name) != 0) { if (strcmp(rule.name, rule.name) != 0) {
@ -301,8 +301,8 @@ void AIAlgorithm::setGame(const Game &game)
history.clear(); history.clear();
} }
this->game_ = game; this->game = g;
tempGame = game; tempGame = g;
position = &(tempGame.position); position = &(tempGame.position);
requiredQuit = false; requiredQuit = false;
deleteTree(root); deleteTree(root);
@ -339,8 +339,8 @@ int AIAlgorithm::search(depth_t depth)
#ifdef THREEFOLD_REPETITION #ifdef THREEFOLD_REPETITION
static int nRepetition = 0; static int nRepetition = 0;
if (game_.getPhase() == PHASE_MOVING) { if (game.getPhase() == PHASE_MOVING) {
hash_t hash = game_.getHash(); hash_t hash = game.getHash();
if (std::find(history.begin(), history.end(), hash) != history.end()) { if (std::find(history.begin(), history.end(), hash) != history.end()) {
nRepetition++; nRepetition++;
@ -353,7 +353,7 @@ int AIAlgorithm::search(depth_t depth)
} }
} }
if (game_.getPhase() == PHASE_PLACING) { if (game.getPhase() == PHASE_PLACING) {
history.clear(); history.clear();
} }
#endif // THREEFOLD_REPETITION #endif // THREEFOLD_REPETITION
@ -690,7 +690,7 @@ const char* AIAlgorithm::bestMove()
i++; i++;
} }
player_t side = game_.position.sideToMove; player_t side = game.position.sideToMove;
#ifdef ENDGAME_LEARNING #ifdef ENDGAME_LEARNING
// 检查是否明显劣势 // 检查是否明显劣势
@ -707,9 +707,9 @@ const char* AIAlgorithm::bestMove()
if (isMostWeak) { if (isMostWeak) {
Endgame endgame; Endgame endgame;
endgame.type = game_.position.sideToMove == PLAYER_1 ? endgame.type = game.position.sideToMove == PLAYER_1 ?
ENDGAME_PLAYER_2_WIN : ENDGAME_PLAYER_1_WIN; ENDGAME_PLAYER_2_WIN : ENDGAME_PLAYER_1_WIN;
hash_t endgameHash = this->game_.getHash(); // TODO: 减少重复计算哈希 hash_t endgameHash = this->game.getHash(); // TODO: 减少重复计算哈希
recordEndgameHash(endgameHash, endgame); recordEndgameHash(endgameHash, endgame);
loggerDebug("Record 0x%08I32x to Endgame Hashmap\n", endgameHash); loggerDebug("Record 0x%08I32x to Endgame Hashmap\n", endgameHash);
} }
@ -730,7 +730,7 @@ const char* AIAlgorithm::bestMove()
// 自动认输 // 自动认输
if (isMostLose) { if (isMostLose) {
sprintf(cmdline, "Player%d give up!", game_.position.sideId); sprintf(cmdline, "Player%d give up!", game.position.sideId);
return cmdline; return cmdline;
} }
} }

View File

@ -185,7 +185,7 @@ protected:
private: private:
// 原始模型 // 原始模型
Game game_; Game game;
// 演算用的模型 // 演算用的模型
Game tempGame; Game tempGame;

View File

@ -26,8 +26,8 @@
AiThread::AiThread(int id, QObject *parent) : AiThread::AiThread(int id, QObject *parent) :
QThread(parent), QThread(parent),
waiting_(false), waiting(false),
game_(nullptr), game(nullptr),
depth(2), depth(2),
timeLimit(3600) timeLimit(3600)
{ {
@ -61,12 +61,12 @@ AiThread::~AiThread()
wait(); wait();
} }
void AiThread::setAi(const Game &game) void AiThread::setAi(const Game &g)
{ {
mutex.lock(); mutex.lock();
this->game_ = &game; this->game = &g;
ai.setGame(*(this->game_)); ai.setGame(*(this->game));
#ifdef TRANSPOSITION_TABLE_ENABLE #ifdef TRANSPOSITION_TABLE_ENABLE
// 新下一盘前清除哈希表 (注意可能同时存在每步之前清除) // 新下一盘前清除哈希表 (注意可能同时存在每步之前清除)
@ -78,11 +78,11 @@ void AiThread::setAi(const Game &game)
mutex.unlock(); mutex.unlock();
} }
void AiThread::setAi(const Game &game, depth_t d, int tl) void AiThread::setAi(const Game &g, depth_t d, int tl)
{ {
mutex.lock(); mutex.lock();
this->game_ = &game; this->game = &g;
ai.setGame(game); ai.setGame(g);
depth = d; depth = d;
timeLimit = tl; timeLimit = tl;
mutex.unlock(); mutex.unlock();
@ -108,15 +108,15 @@ void AiThread::run()
while (!isInterruptionRequested()) { while (!isInterruptionRequested()) {
mutex.lock(); mutex.lock();
i = Player::toId(game_->position.sideToMove); i = Player::toId(game->position.sideToMove);
if (i != id || waiting_) { if (i != id || waiting) {
pauseCondition.wait(&mutex); pauseCondition.wait(&mutex);
mutex.unlock(); mutex.unlock();
continue; continue;
} }
ai.setGame(*game_); ai.setGame(*game);
emit calcStarted(); emit calcStarted();
mutex.unlock(); mutex.unlock();
@ -152,7 +152,7 @@ void AiThread::act()
return; return;
mutex.lock(); mutex.lock();
waiting_ = false; waiting = false;
ai.quit(); ai.quit();
mutex.unlock(); mutex.unlock();
} }
@ -160,14 +160,14 @@ void AiThread::act()
void AiThread::pause() void AiThread::pause()
{ {
mutex.lock(); mutex.lock();
waiting_ = true; waiting = true;
mutex.unlock(); mutex.unlock();
} }
void AiThread::resume() void AiThread::resume()
{ {
mutex.lock(); mutex.lock();
waiting_ = false; waiting = false;
pauseCondition.wakeAll(); pauseCondition.wakeAll();
mutex.unlock(); mutex.unlock();
} }
@ -180,7 +180,7 @@ void AiThread::stop()
if (!isInterruptionRequested()) { if (!isInterruptionRequested()) {
requestInterruption(); requestInterruption();
mutex.lock(); mutex.lock();
waiting_ = false; waiting = false;
ai.quit(); ai.quit();
pauseCondition.wakeAll(); pauseCondition.wakeAll();
mutex.unlock(); mutex.unlock();

View File

@ -108,13 +108,13 @@ private:
QMutex mutex; QMutex mutex;
// 线程等待标识,这里没用到,留着以后扩展用 // 线程等待标识,这里没用到,留着以后扩展用
bool waiting_; bool waiting;
// 等待条件,这里没用到,留着以后扩展用 // 等待条件,这里没用到,留着以后扩展用
QWaitCondition pauseCondition; QWaitCondition pauseCondition;
// 主线程棋对象的引用 // 主线程棋对象的引用
const Game *game_; const Game *game;
// AI 算法类 // AI 算法类
AIAlgorithm ai; AIAlgorithm ai;

View File

@ -71,7 +71,7 @@ Game &Game::operator= (const Game &game)
currentTime = game.currentTime; currentTime = game.currentTime;
elapsedSeconds[1] = game.elapsedSeconds[1]; elapsedSeconds[1] = game.elapsedSeconds[1];
elapsedSeconds[2] = game.elapsedSeconds[2]; elapsedSeconds[2] = game.elapsedSeconds[2];
move_ = game.move_; move = game.move;
memcpy(cmdline, game.cmdline, sizeof(cmdline)); memcpy(cmdline, game.cmdline, sizeof(cmdline));
cmdlist = game.cmdlist; cmdlist = game.cmdlist;
tips = game.tips; tips = game.tips;
@ -320,7 +320,7 @@ bool Game::place(int location, int8_t updateCmdlist)
updateHash(location); updateHash(location);
move_ = static_cast<move_t>(location); move = static_cast<move_t>(location);
if (updateCmdlist) { if (updateCmdlist) {
seconds = update(); seconds = update();
@ -400,7 +400,7 @@ bool Game::place(int location, int8_t updateCmdlist)
} }
// 移子 // 移子
move_ = static_cast<move_t>((currentLocation << 8) + location); move = static_cast<move_t>((currentLocation << 8) + location);
if (updateCmdlist) { if (updateCmdlist) {
seconds = update(); seconds = update();
@ -515,7 +515,7 @@ bool Game::capture(int location, int8_t updateCmdlist)
position.nPiecesOnBoard[position.opponentId]--; position.nPiecesOnBoard[position.opponentId]--;
move_ = static_cast<move_t>(-location); move = static_cast<move_t>(-location);
if (updateCmdlist) { if (updateCmdlist) {
seconds = update(); seconds = update();
@ -744,18 +744,18 @@ bool Game::command(const char *cmd)
return false; return false;
} }
bool Game::command(int move) bool Game::command(int m)
{ {
if (move < 0) { if (m < 0) {
return capture(-move); return capture(-m);
} }
if (move & 0x1f00) { if (m & 0x1f00) {
if (choose(move >> 8)) { if (choose(m >> 8)) {
return place(move & 0x00ff); return place(m & 0x00ff);
} }
} else { } else {
return place(move & 0x00ff); return place(m & 0x00ff);
} }
return false; return false;

View File

@ -288,7 +288,7 @@ public: /* TODO: move to private */
| / | \ | | / | \ |
29 ----- 28 ----- 27 29 ----- 28 ----- 27
*/ */
move_t move_{}; move_t move{};
// 选中的棋子在board中的位置 // 选中的棋子在board中的位置
int currentLocation{}; int currentLocation{};

View File

@ -50,13 +50,13 @@ private slots:
void displayError(QAbstractSocket::SocketError socketError); void displayError(QAbstractSocket::SocketError socketError);
void enableGetActionButton(); void enableGetActionButton();
void sessionOpened(); void sessionOpened();
void setPort(uint16_t port) void setPort(uint16_t p)
{ {
this->port_ = port; this->port = p;
} }
uint16_t getPort() uint16_t getPort()
{ {
return port_; return port;
} }
private: private:
@ -71,7 +71,7 @@ private:
QNetworkSession *networkSession = nullptr; QNetworkSession *networkSession = nullptr;
uint16_t port_ {}; uint16_t port {};
}; };
#endif // CLIENT_H #endif // CLIENT_H

View File

@ -47,7 +47,7 @@ GameController::GameController(GameScene & scene, QObject * parent) :
durationTime(500), durationTime(500),
hasSound(true), hasSound(true),
timeID(0), timeID(0),
ruleNo_(-1), ruleIndex(-1),
timeLimit(0), timeLimit(0),
stepsLimit(50) stepsLimit(50)
{ {
@ -122,8 +122,8 @@ const QMap<int, QStringList> GameController::getActions()
void GameController::gameStart() void GameController::gameStart()
{ {
game_.start(); game.start();
tempGame = game_; tempGame = game;
// 每隔100毫秒调用一次定时器处理函数 // 每隔100毫秒调用一次定时器处理函数
if (timeID == 0) { if (timeID == 0) {
@ -141,14 +141,14 @@ void GameController::gameReset()
timeID = 0; timeID = 0;
// 棋未下完,则算对手得分 // 棋未下完,则算对手得分
if (game_.getPhase() == PHASE_MOVING && if (game.getPhase() == PHASE_MOVING &&
game_.whoWin() == PLAYER_NOBODY) { game.whoWin() == PLAYER_NOBODY) {
giveUp(); giveUp();
} }
// 重置游戏 // 重置游戏
game_.reset(); game.reset();
tempGame = game_; tempGame = game;
// 停掉线程 // 停掉线程
if (!options.getAutoRestart()) { if (!options.getAutoRestart()) {
@ -218,7 +218,7 @@ void GameController::gameReset()
// 更新棋谱 // 更新棋谱
manualListModel.removeRows(0, manualListModel.rowCount()); manualListModel.removeRows(0, manualListModel.rowCount());
manualListModel.insertRow(0); manualListModel.insertRow(0);
manualListModel.setData(manualListModel.index(0), game_.getCmdLine()); manualListModel.setData(manualListModel.index(0), game.getCmdLine());
currentRow = 0; currentRow = 0;
// 发出信号通知主窗口更新LCD显示 // 发出信号通知主窗口更新LCD显示
@ -227,13 +227,13 @@ void GameController::gameReset()
emit time2Changed(qtime.toString("hh:mm:ss")); emit time2Changed(qtime.toString("hh:mm:ss"));
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 更新比分 LCD 显示 // 更新比分 LCD 显示
emit score1Changed(QString::number(game_.score[1], 10)); emit score1Changed(QString::number(game.score[1], 10));
emit score2Changed(QString::number(game_.score[2], 10)); emit score2Changed(QString::number(game.score[2], 10));
emit scoreDrawChanged(QString::number(game_.score_draw, 10)); emit scoreDrawChanged(QString::number(game.score_draw, 10));
// 播放音效 // 播放音效
//playSound(":/sound/resources/sound/newgame.wav"); //playSound(":/sound/resources/sound/newgame.wav");
@ -270,7 +270,7 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi
// 更新规则,原限时和限步不变 // 更新规则,原限时和限步不变
if (ruleNo < 0 || ruleNo >= N_RULES) if (ruleNo < 0 || ruleNo >= N_RULES)
return; return;
this->ruleNo_ = ruleNo; this->ruleIndex = ruleNo;
if (stepLimited != UINT16_MAX && timeLimited != -1) { if (stepLimited != UINT16_MAX && timeLimited != -1) {
stepsLimit = stepLimited; stepsLimit = stepLimited;
@ -278,8 +278,8 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi
} }
// 设置模型规则,重置游戏 // 设置模型规则,重置游戏
game_.setPosition(&RULES[ruleNo], stepsLimit, timeLimit); game.setPosition(&RULES[ruleNo], stepsLimit, timeLimit);
tempGame = game_; tempGame = game;
// 重置游戏 // 重置游戏
gameReset(); gameReset();
@ -290,7 +290,7 @@ void GameController::setEngine(int id, bool arg)
isAiPlayer[id] = arg; isAiPlayer[id] = arg;
if (arg) { if (arg) {
ai[id]->setAi(game_); ai[id]->setAi(game);
if (ai[id]->isRunning()) if (ai[id]->isRunning())
ai[id]->resume(); ai[id]->resume();
else else
@ -321,8 +321,8 @@ void GameController::setAiDepthTime(depth_t depth1, int time1, depth_t depth2, i
ai[2]->wait(); ai[2]->wait();
} }
ai[1]->setAi(game_, depth1, time1); ai[1]->setAi(game, depth1, time1);
ai[2]->setAi(game_, depth2, time2); ai[2]->setAi(game, depth2, time2);
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->start(); ai[1]->start();
@ -402,13 +402,13 @@ void GameController::flip()
ai[2]->wait(); ai[2]->wait();
} }
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation); game.position.board.mirror(game.cmdlist, game.cmdline, game.move, game.currentLocation);
game_.position.board.rotate(180, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation); game.position.board.rotate(180, game.cmdlist, game.cmdline, game.move, game.currentLocation);
tempGame = game_; tempGame = game;
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(game_.getCmdList())) { for (const auto &str : *(game.getCmdList())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -418,8 +418,8 @@ void GameController::flip()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
ai[1]->setAi(game_); ai[1]->setAi(game);
ai[2]->setAi(game_); ai[2]->setAi(game);
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->start(); ai[1]->start();
@ -442,13 +442,13 @@ void GameController::mirror()
ai[2]->wait(); ai[2]->wait();
} }
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation); game.position.board.mirror(game.cmdlist, game.cmdline, game.move, game.currentLocation);
tempGame = game_; tempGame = game;
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(game_.getCmdList())) { for (const auto &str : *(game.getCmdList())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -460,8 +460,8 @@ void GameController::mirror()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
ai[1]->setAi(game_); ai[1]->setAi(game);
ai[2]->setAi(game_); ai[2]->setAi(game);
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->start(); ai[1]->start();
@ -484,13 +484,13 @@ void GameController::turnRight()
ai[2]->wait(); ai[2]->wait();
} }
game_.position.board.rotate(-90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation); game.position.board.rotate(-90, game.cmdlist, game.cmdline, game.move, game.currentLocation);
tempGame = game_; tempGame = game;
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(game_.getCmdList())) { for (const auto &str : *(game.getCmdList())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
@ -500,8 +500,8 @@ void GameController::turnRight()
else else
phaseChange(currentRow, true); phaseChange(currentRow, true);
ai[1]->setAi(game_); ai[1]->setAi(game);
ai[2]->setAi(game_); ai[2]->setAi(game);
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->start(); ai[1]->start();
@ -524,20 +524,20 @@ void GameController::turnLeft()
ai[2]->wait(); ai[2]->wait();
} }
game_.position.board.rotate(90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentLocation); game.position.board.rotate(90, game.cmdlist, game.cmdline, game.move, game.currentLocation);
tempGame = game_; tempGame = game;
// 更新棋谱 // 更新棋谱
int row = 0; int row = 0;
for (const auto &str : *(game_.getCmdList())) { for (const auto &str : *(game.getCmdList())) {
manualListModel.setData(manualListModel.index(row++), str.c_str()); manualListModel.setData(manualListModel.index(row++), str.c_str());
} }
// 刷新显示 // 刷新显示
updateScence(); updateScence();
ai[1]->setAi(game_); ai[1]->setAi(game);
ai[2]->setAi(game_); ai[2]->setAi(game);
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->start(); ai[1]->start();
} }
@ -552,9 +552,9 @@ void GameController::timerEvent(QTimerEvent *event)
static QTime qt1, qt2; static QTime qt1, qt2;
// 玩家的已用时间 // 玩家的已用时间
game_.update(); game.update();
remainingTime[1] = game_.getElapsedTime(1); remainingTime[1] = game.getElapsedTime(1);
remainingTime[2] = game_.getElapsedTime(2); remainingTime[2] = game.getElapsedTime(2);
// 如果规则要求计时则time1和time2表示倒计时 // 如果规则要求计时则time1和time2表示倒计时
if (timeLimit > 0) { if (timeLimit > 0) {
@ -570,7 +570,7 @@ void GameController::timerEvent(QTimerEvent *event)
emit time2Changed(qt2.toString("hh:mm:ss")); emit time2Changed(qt2.toString("hh:mm:ss"));
// 如果胜负已分 // 如果胜负已分
if (game_.whoWin() != PLAYER_NOBODY) { if (game.whoWin() != PLAYER_NOBODY) {
// 停止计时 // 停止计时
killTimer(timeID); killTimer(timeID);
@ -578,7 +578,7 @@ void GameController::timerEvent(QTimerEvent *event)
timeID = 0; timeID = 0;
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 弹框 // 弹框
@ -615,7 +615,7 @@ void GameController::timerEvent(QTimerEvent *event)
bool GameController::isAIsTurn() bool GameController::isAIsTurn()
{ {
return isAiPlayer[game_.position.sideId]; return isAiPlayer[game.position.sideId];
} }
// 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子 // 关键槽函数根据QGraphicsScene的信号和状态来执行选子、落子或去子
@ -648,17 +648,17 @@ bool GameController::actionPiece(QPointF pos)
if (QMessageBox::Ok == msgBox.exec()) { if (QMessageBox::Ok == msgBox.exec()) {
#endif /* !MOBILE_APP_UI */ #endif /* !MOBILE_APP_UI */
game_ = tempGame; game = tempGame;
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1); manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
// 如果再决出胜负后悔棋,则重新启动计时 // 如果再决出胜负后悔棋,则重新启动计时
if (game_.whoWin() == PLAYER_NOBODY) { if (game.whoWin() == PLAYER_NOBODY) {
// 重新启动计时 // 重新启动计时
timeID = startTimer(100); timeID = startTimer(100);
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
emit statusBarChanged(message); emit statusBarChanged(message);
#ifndef MOBILE_APP_UI #ifndef MOBILE_APP_UI
} }
@ -669,7 +669,7 @@ bool GameController::actionPiece(QPointF pos)
} }
// 如果未开局则开局 // 如果未开局则开局
if (game_.getPhase() == PHASE_NOTSTARTED) if (game.getPhase() == PHASE_NOTSTARTED)
gameStart(); gameStart();
// 判断执行选子、落子或去子 // 判断执行选子、落子或去子
@ -677,10 +677,10 @@ bool GameController::actionPiece(QPointF pos)
PieceItem *piece = nullptr; PieceItem *piece = nullptr;
QGraphicsItem *item = scene.itemAt(pos, QTransform()); QGraphicsItem *item = scene.itemAt(pos, QTransform());
switch (game_.getAction()) { switch (game.getAction()) {
case ACTION_PLACE: case ACTION_PLACE:
if (game_._place(r, s)) { if (game._place(r, s)) {
if (game_.getAction() == ACTION_CAPTURE) { if (game.getAction() == ACTION_CAPTURE) {
// 播放成三音效 // 播放成三音效
playSound(":/sound/resources/sound/capture.wav"); playSound(":/sound/resources/sound/capture.wav");
} else { } else {
@ -698,7 +698,7 @@ bool GameController::actionPiece(QPointF pos)
piece = qgraphicsitem_cast<PieceItem *>(item); piece = qgraphicsitem_cast<PieceItem *>(item);
if (!piece) if (!piece)
break; break;
if (game_.choose(r, s)) { if (game.choose(r, s)) {
// 播放选子音效 // 播放选子音效
playSound(":/sound/resources/sound/choose.wav"); playSound(":/sound/resources/sound/choose.wav");
result = true; result = true;
@ -709,7 +709,7 @@ bool GameController::actionPiece(QPointF pos)
break; break;
case ACTION_CAPTURE: case ACTION_CAPTURE:
if (game_._capture(r, s)) { if (game._capture(r, s)) {
// 播放音效 // 播放音效
playSound(":/sound/resources/sound/remove.wav"); playSound(":/sound/resources/sound/remove.wav");
result = true; result = true;
@ -726,7 +726,7 @@ bool GameController::actionPiece(QPointF pos)
if (result) { if (result) {
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 将新增的棋谱行插入到ListModel // 将新增的棋谱行插入到ListModel
@ -734,7 +734,7 @@ bool GameController::actionPiece(QPointF pos)
int k = 0; int k = 0;
// 输出命令行 // 输出命令行
for (const auto & i : *(game_.getCmdList())) { for (const auto & i : *(game.getCmdList())) {
// 跳过已添加的因标准list容器没有下标 // 跳过已添加的因标准list容器没有下标
if (k++ <= currentRow) if (k++ <= currentRow)
continue; continue;
@ -744,16 +744,16 @@ bool GameController::actionPiece(QPointF pos)
// 播放胜利或失败音效 // 播放胜利或失败音效
#ifndef DONOT_PLAY_WIN_SOUND #ifndef DONOT_PLAY_WIN_SOUND
if (game_.whoWin() != PLAYER_NOBODY && if (game.whoWin() != PLAYER_NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over."))
playSound(":/sound/resources/sound/win.wav"); playSound(":/sound/resources/sound/win.wav");
#endif #endif
// AI设置 // AI设置
if (&game_ == &(this->game_)) { if (&game == &(this->game)) {
// 如果还未决出胜负 // 如果还未决出胜负
if (game_.whoWin() == PLAYER_NOBODY) { if (game.whoWin() == PLAYER_NOBODY) {
if (game_.position.sideToMove == PLAYER_1) { if (game.position.sideToMove == PLAYER_1) {
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->resume(); ai[1]->resume();
} }
@ -773,7 +773,7 @@ bool GameController::actionPiece(QPointF pos)
ai[2]->stop(); ai[2]->stop();
// 弹框 // 弹框
//message = QString::fromStdString(game_.getTips()); //message = QString::fromStdString(game.getTips());
//QMessageBox::about(NULL, "游戏结果", message); //QMessageBox::about(NULL, "游戏结果", message);
} }
} }
@ -785,7 +785,7 @@ bool GameController::actionPiece(QPointF pos)
bool GameController::giveUp() bool GameController::giveUp()
{ {
bool result = game_.giveup(game_.position.sideToMove); bool result = game.giveup(game.position.sideToMove);
if (!result) { if (!result) {
return false; return false;
@ -796,7 +796,7 @@ bool GameController::giveUp()
int k = 0; int k = 0;
// 输出命令行 // 输出命令行
for (const auto & i : *(game_.getCmdList())) { for (const auto & i : *(game.getCmdList())) {
// 跳过已添加的因标准list容器没有下标 // 跳过已添加的因标准list容器没有下标
if (k++ <= currentRow) if (k++ <= currentRow)
continue; continue;
@ -804,7 +804,7 @@ bool GameController::giveUp()
manualListModel.setData(manualListModel.index(currentRow), i.c_str()); manualListModel.setData(manualListModel.index(currentRow), i.c_str());
} }
if (game_.whoWin() != PLAYER_NOBODY) if (game.whoWin() != PLAYER_NOBODY)
playSound(":/sound/resources/sound/loss.wav"); playSound(":/sound/resources/sound/loss.wav");
return result; return result;
@ -825,7 +825,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
// 声音 // 声音
QString sound; QString sound;
switch (game_.getAction()) { switch (game.getAction()) {
case ACTION_CHOOSE: case ACTION_CHOOSE:
case ACTION_PLACE: case ACTION_PLACE:
sound = ":/sound/resources/sound/drog.wav"; sound = ":/sound/resources/sound/drog.wav";
@ -838,44 +838,44 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
} }
// 如果未开局则开局 // 如果未开局则开局
if (game_.getPhase() == PHASE_NOTSTARTED) { if (game.getPhase() == PHASE_NOTSTARTED) {
gameStart(); gameStart();
} }
if (!game_.command(cmd.toStdString().c_str())) if (!game.command(cmd.toStdString().c_str()))
return false; return false;
if (sound == ":/sound/resources/sound/drog.wav" && game_.getAction() == ACTION_CAPTURE) { if (sound == ":/sound/resources/sound/drog.wav" && game.getAction() == ACTION_CAPTURE) {
sound = ":/sound/resources/sound/capture.wav"; sound = ":/sound/resources/sound/capture.wav";
} }
if (update) { if (update) {
playSound(sound); playSound(sound);
updateScence(game_); updateScence(game);
} }
// 发信号更新状态栏 // 发信号更新状态栏
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
emit statusBarChanged(message); emit statusBarChanged(message);
// 对于新开局 // 对于新开局
if (game_.getCmdList()->size() <= 1) { if (game.getCmdList()->size() <= 1) {
manualListModel.removeRows(0, manualListModel.rowCount()); manualListModel.removeRows(0, manualListModel.rowCount());
manualListModel.insertRow(0); manualListModel.insertRow(0);
manualListModel.setData(manualListModel.index(0), game_.getCmdLine()); manualListModel.setData(manualListModel.index(0), game.getCmdLine());
currentRow = 0; currentRow = 0;
} }
// 对于当前局 // 对于当前局
else { else {
currentRow = manualListModel.rowCount() - 1; currentRow = manualListModel.rowCount() - 1;
// 跳过已添加行,迭代器不支持+运算符,只能一个个++ // 跳过已添加行,迭代器不支持+运算符,只能一个个++
auto i = (game_.getCmdList()->begin()); auto i = (game.getCmdList()->begin());
for (int r = 0; i != (game_.getCmdList())->end(); i++) { for (int r = 0; i != (game.getCmdList())->end(); i++) {
if (r++ > currentRow) if (r++ > currentRow)
break; break;
} }
// 将新增的棋谱行插入到ListModel // 将新增的棋谱行插入到ListModel
while (i != game_.getCmdList()->end()) { while (i != game.getCmdList()->end()) {
manualListModel.insertRow(++currentRow); manualListModel.insertRow(++currentRow);
manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str()); manualListModel.setData(manualListModel.index(currentRow), (*i++).c_str());
} }
@ -883,17 +883,17 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
// 播放胜利或失败音效 // 播放胜利或失败音效
#ifndef DONOT_PLAY_WIN_SOUND #ifndef DONOT_PLAY_WIN_SOUND
if (game_.whoWin() != PLAYER_NOBODY && if (game.whoWin() != PLAYER_NOBODY &&
(manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) { (manualListModel.data(manualListModel.index(currentRow - 1))).toString().contains("Time over.")) {
playSound(":/sound/resources/sound/win.wav"); playSound(":/sound/resources/sound/win.wav");
} }
#endif #endif
// AI设置 // AI设置
if (&game_ == &(this->game_)) { if (&game == &(this->game)) {
// 如果还未决出胜负 // 如果还未决出胜负
if (game_.whoWin() == PLAYER_NOBODY) { if (game.whoWin() == PLAYER_NOBODY) {
if (game_.position.sideToMove == PLAYER_1) { if (game.position.sideToMove == PLAYER_1) {
if (isAiPlayer[1]) { if (isAiPlayer[1]) {
ai[1]->resume(); ai[1]->resume();
} }
@ -926,7 +926,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
#ifdef MESSAGEBOX_ENABLE #ifdef MESSAGEBOX_ENABLE
// 弹框 // 弹框
message = QString::fromStdString(game_.getTips()); message = QString::fromStdString(game.getTips());
QMessageBox::about(NULL, "游戏结果", message); QMessageBox::about(NULL, "游戏结果", message);
#endif #endif
} }
@ -963,7 +963,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
} }
// 下面这步关键,会让悔棋者承担时间损失 // 下面这步关键,会让悔棋者承担时间损失
tempGame.setStartTime(game_.getStartTimeb()); tempGame.setStartTime(game.getStartTimeb());
// 刷新棋局场景 // 刷新棋局场景
updateScence(tempGame); updateScence(tempGame);
@ -973,12 +973,12 @@ bool GameController::phaseChange(int row, bool forceUpdate)
bool GameController::updateScence() bool GameController::updateScence()
{ {
return updateScence(game_); return updateScence(game);
} }
bool GameController::updateScence(Game &game) bool GameController::updateScence(Game &g)
{ {
const int *board = game.getBoardLocations(); const int *board = g.getBoardLocations();
QPointF pos; QPointF pos;
// game类中的棋子代码 // game类中的棋子代码
@ -1032,10 +1032,10 @@ bool GameController::updateScence(Game &game)
if (j == (Board::N_SEATS) * (Board::N_RINGS + 1)) { if (j == (Board::N_SEATS) * (Board::N_RINGS + 1)) {
// 判断是被吃掉的子,还是未安放的子 // 判断是被吃掉的子,还是未安放的子
if (key & 0x10) { if (key & 0x10) {
pos = (key - 0x11 < nTotalPieces / 2 - game.getPiecesInHandCount(1)) ? pos = (key - 0x11 < nTotalPieces / 2 - g.getPiecesInHandCount(1)) ?
scene.pos_p2_g : scene.pos_p1; scene.pos_p2_g : scene.pos_p1;
} else { } else {
pos = (key - 0x21 < nTotalPieces / 2 - game.getPiecesInHandCount(2)) ? pos = (key - 0x21 < nTotalPieces / 2 - g.getPiecesInHandCount(2)) ?
scene.pos_p1_g : scene.pos_p2; scene.pos_p1_g : scene.pos_p2;
} }
@ -1062,7 +1062,7 @@ bool GameController::updateScence(Game &game)
} }
// 添加摆棋阶段禁子点 // 添加摆棋阶段禁子点
if (rule.hasForbiddenLocations && game.getPhase() == PHASE_PLACING) { if (rule.hasForbiddenLocations && g.getPhase() == PHASE_PLACING) {
for (int j = Board::LOCATION_BEGIN; j < Board::LOCATION_END; j++) { for (int j = Board::LOCATION_BEGIN; j < Board::LOCATION_END; j++) {
if (board[j] == 0x0F) { if (board[j] == 0x0F) {
pos = scene.rs2pos(j / Board::N_SEATS, j % Board::N_SEATS + 1); pos = scene.rs2pos(j / Board::N_SEATS, j % Board::N_SEATS + 1);
@ -1081,7 +1081,7 @@ bool GameController::updateScence(Game &game)
} }
// 走棋阶段清除禁子点 // 走棋阶段清除禁子点
if (rule.hasForbiddenLocations && game.getPhase() != PHASE_PLACING) { if (rule.hasForbiddenLocations && g.getPhase() != PHASE_PLACING) {
while (nTotalPieces < pieceList.size()) { while (nTotalPieces < pieceList.size()) {
delete pieceList.at(nTotalPieces); delete pieceList.at(nTotalPieces);
pieceList.removeAt(nTotalPieces); pieceList.removeAt(nTotalPieces);
@ -1089,9 +1089,9 @@ bool GameController::updateScence(Game &game)
} }
// 选中当前棋子 // 选中当前棋子
int ipos = game.getCurrentLocation(); int ipos = g.getCurrentLocation();
if (ipos) { if (ipos) {
key = board[game.getCurrentLocation()]; key = board[g.getCurrentLocation()];
ipos = key & 0x10 ? (key - 0x11) * 2 : (key - 0x21) * 2 + 1; ipos = key & 0x10 ? (key - 0x11) * 2 : (key - 0x21) * 2 + 1;
if (ipos >= 0 && ipos < nTotalPieces) { if (ipos >= 0 && ipos < nTotalPieces) {
currentPiece = pieceList.at(ipos); currentPiece = pieceList.at(ipos);
@ -1107,9 +1107,9 @@ bool GameController::updateScence(Game &game)
animationGroup->start(QAbstractAnimation::DeleteWhenStopped); animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
// 更新比分 LCD 显示 // 更新比分 LCD 显示
emit score1Changed(QString::number(game.score[1], 10)); emit score1Changed(QString::number(g.score[1], 10));
emit score2Changed(QString::number(game.score[2], 10)); emit score2Changed(QString::number(g.score[2], 10));
emit scoreDrawChanged(QString::number(game.score_draw, 10)); emit scoreDrawChanged(QString::number(g.score_draw, 10));
return true; return true;
} }

View File

@ -55,9 +55,9 @@ public:
//主窗口菜单栏明细 //主窗口菜单栏明细
const QMap <int, QStringList> getActions(); const QMap <int, QStringList> getActions();
int getRuleNo() int getRuleIndex()
{ {
return ruleNo_; return ruleIndex;
} }
int getTimeLimit() int getTimeLimit()
@ -196,7 +196,7 @@ protected:
private: private:
// 棋对象的数据模型 // 棋对象的数据模型
Game game_; Game game;
// 棋对象的数据模型(临时) // 棋对象的数据模型(临时)
Game tempGame; Game tempGame;
@ -241,7 +241,7 @@ private:
int timeID; int timeID;
// 规则号 // 规则号
int ruleNo_; int ruleIndex;
// 规则限时(分钟) // 规则限时(分钟)
int timeLimit; int timeLimit;

View File

@ -114,9 +114,9 @@ MillGameWindow::MillGameWindow(QWidget * parent) :
MillGameWindow::~MillGameWindow() MillGameWindow::~MillGameWindow()
{ {
if (game) { if (gameController) {
game->disconnect(); gameController->disconnect();
game->deleteLater(); gameController->deleteLater();
} }
qDeleteAll(ruleActionList); qDeleteAll(ruleActionList);
@ -154,14 +154,14 @@ bool MillGameWindow::eventFilter(QObject *watched, QEvent *event)
void MillGameWindow::initialize() void MillGameWindow::initialize()
{ {
// 初始化函数,仅执行一次 // 初始化函数,仅执行一次
if (game) if (gameController)
return; return;
// 开辟一个新的游戏控制器 // 开辟一个新的游戏控制器
game = new GameController(*scene, this); gameController = new GameController(*scene, this);
// 添加新菜单栏动作 // 添加新菜单栏动作
QMap <int, QStringList> actions = game->getActions(); QMap <int, QStringList> actions = gameController->getActions();
for (auto i = actions.constBegin(); i != actions.constEnd(); i++) { for (auto i = actions.constBegin(); i != actions.constEnd(); i++) {
// QMap的key存放int索引值value存放规则名称和规则提示 // QMap的key存放int索引值value存放规则名称和规则提示
@ -185,7 +185,7 @@ void MillGameWindow::initialize()
// 关联主窗口动作信号和控制器的槽 // 关联主窗口动作信号和控制器的槽
connect(ui.actionGiveUp_G, SIGNAL(triggered()), connect(ui.actionGiveUp_G, SIGNAL(triggered()),
game, SLOT(giveUp())); gameController, SLOT(giveUp()));
#ifdef MOBILE_APP_UI #ifdef MOBILE_APP_UI
connect(ui.pushButton_giveUp, SIGNAL(released()), connect(ui.pushButton_giveUp, SIGNAL(released()),
@ -193,71 +193,71 @@ void MillGameWindow::initialize()
#endif #endif
connect(ui.actionEngine1_T, SIGNAL(toggled(bool)), connect(ui.actionEngine1_T, SIGNAL(toggled(bool)),
game, SLOT(setEngine1(bool))); gameController, SLOT(setEngine1(bool)));
connect(ui.actionEngine2_R, SIGNAL(toggled(bool)), connect(ui.actionEngine2_R, SIGNAL(toggled(bool)),
game, SLOT(setEngine2(bool))); gameController, SLOT(setEngine2(bool)));
connect(ui. connect(ui.
actionSound_S, SIGNAL(toggled(bool)), actionSound_S, SIGNAL(toggled(bool)),
game, SLOT(setSound(bool))); gameController, SLOT(setSound(bool)));
connect(ui.actionAnimation_A, SIGNAL(toggled(bool)), connect(ui.actionAnimation_A, SIGNAL(toggled(bool)),
game, SLOT(setAnimation(bool))); gameController, SLOT(setAnimation(bool)));
connect(ui.actionGiveUpIfMostLose_G, SIGNAL(toggled(bool)), connect(ui.actionGiveUpIfMostLose_G, SIGNAL(toggled(bool)),
game, SLOT(setGiveUpIfMostLose(bool))); gameController, SLOT(setGiveUpIfMostLose(bool)));
connect(ui.actionAutoRestart_A, SIGNAL(toggled(bool)), connect(ui.actionAutoRestart_A, SIGNAL(toggled(bool)),
game, SLOT(setAutoRestart(bool))); gameController, SLOT(setAutoRestart(bool)));
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)), connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
game, SLOT(setRandomMove(bool))); gameController, SLOT(setRandomMove(bool)));
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)), connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
game, SLOT(setLearnEndgame(bool))); gameController, SLOT(setLearnEndgame(bool)));
// 视图上下翻转 // 视图上下翻转
connect(ui.actionFlip_F, &QAction::triggered, connect(ui.actionFlip_F, &QAction::triggered,
game, &GameController::flip); gameController, &GameController::flip);
// 视图左右镜像 // 视图左右镜像
connect(ui.actionMirror_M, &QAction::triggered, connect(ui.actionMirror_M, &QAction::triggered,
game, &GameController::mirror); gameController, &GameController::mirror);
// 视图须时针旋转90° // 视图须时针旋转90°
connect(ui.actionTurnRight_R, &QAction::triggered, connect(ui.actionTurnRight_R, &QAction::triggered,
game, &GameController::turnRight); gameController, &GameController::turnRight);
// 视图逆时针旋转90° // 视图逆时针旋转90°
connect(ui.actionTurnLeftt_L, &QAction::triggered, connect(ui.actionTurnLeftt_L, &QAction::triggered,
game, &GameController::turnLeft); gameController, &GameController::turnLeft);
// 关联控制器的信号和主窗口控件的槽 // 关联控制器的信号和主窗口控件的槽
// 更新LCD显示玩家1赢盘数 // 更新LCD显示玩家1赢盘数
connect(game, SIGNAL(score1Changed(QString)), connect(gameController, SIGNAL(score1Changed(QString)),
ui.scoreLcdNumber_1, SLOT(display(QString))); ui.scoreLcdNumber_1, SLOT(display(QString)));
// 更新LCD显示玩家2赢盘数 // 更新LCD显示玩家2赢盘数
connect(game, SIGNAL(score2Changed(QString)), connect(gameController, SIGNAL(score2Changed(QString)),
ui.scoreLcdNumber_2, SLOT(display(QString))); ui.scoreLcdNumber_2, SLOT(display(QString)));
// 更新LCD显示和棋数 // 更新LCD显示和棋数
connect(game, SIGNAL(scoreDrawChanged(QString)), connect(gameController, SIGNAL(scoreDrawChanged(QString)),
ui.scoreLcdNumber_draw, SLOT(display(QString))); ui.scoreLcdNumber_draw, SLOT(display(QString)));
// 更新LCD1显示玩家1用时 // 更新LCD1显示玩家1用时
connect(game, SIGNAL(time1Changed(QString)), connect(gameController, SIGNAL(time1Changed(QString)),
ui.lcdNumber_1, SLOT(display(QString))); ui.lcdNumber_1, SLOT(display(QString)));
// 更新LCD2显示玩家2用时 // 更新LCD2显示玩家2用时
connect(game, SIGNAL(time2Changed(QString)), connect(gameController, SIGNAL(time2Changed(QString)),
ui.lcdNumber_2, SLOT(display(QString))); ui.lcdNumber_2, SLOT(display(QString)));
// 关联场景的信号和控制器的槽 // 关联场景的信号和控制器的槽
connect(scene, SIGNAL(mouseReleased(QPointF)), connect(scene, SIGNAL(mouseReleased(QPointF)),
game, SLOT(actionPiece(QPointF))); gameController, SLOT(actionPiece(QPointF)));
// 为状态栏添加一个正常显示的标签 // 为状态栏添加一个正常显示的标签
auto *statusBarlabel = new QLabel(this); auto *statusBarlabel = new QLabel(this);
@ -267,7 +267,7 @@ void MillGameWindow::initialize()
ui.statusBar->addWidget(statusBarlabel); ui.statusBar->addWidget(statusBarlabel);
// 更新状态栏 // 更新状态栏
connect(game, SIGNAL(statusBarChanged(QString)), connect(gameController, SIGNAL(statusBarChanged(QString)),
statusBarlabel, SLOT(setText(QString))); statusBarlabel, SLOT(setText(QString)));
// 默认第2号规则 // 默认第2号规则
@ -275,13 +275,13 @@ void MillGameWindow::initialize()
ruleActionList.at(ruleNo)->setChecked(true); ruleActionList.at(ruleNo)->setChecked(true);
// 重置游戏规则 // 重置游戏规则
game->setRule(ruleNo); gameController->setRule(ruleNo);
// 更新规则显示 // 更新规则显示
ruleInfo(); ruleInfo();
// 关联列表视图和字符串列表模型 // 关联列表视图和字符串列表模型
ui.listView->setModel(game->getManualListModel()); ui.listView->setModel(gameController->getManualListModel());
// 因为QListView的rowsInserted在setModel之后才能启动 // 因为QListView的rowsInserted在setModel之后才能启动
// 第一次需手动初始化选中listView第一项 // 第一次需手动初始化选中listView第一项
@ -372,8 +372,8 @@ void MillGameWindow::ctxMenu(const QPoint &pos)
void MillGameWindow::ruleInfo() void MillGameWindow::ruleInfo()
{ {
int s = game->getStepsLimit(); int s = gameController->getStepsLimit();
int t = game->getTimeLimit(); int t = gameController->getTimeLimit();
QString tl(" 不限时"); QString tl(" 不限时");
QString sl(" 不限步"); QString sl(" 不限步");
@ -406,8 +406,8 @@ void MillGameWindow::on_actionLimited_T_triggered()
* *
* QDialog界面 * QDialog界面
*/ */
int gStep = game->getStepsLimit(); int gStep = gameController->getStepsLimit();
int gTime = game->getTimeLimit(); int gTime = gameController->getTimeLimit();
// 定义新对话框 // 定义新对话框
auto *dialog = new QDialog(this); auto *dialog = new QDialog(this);
@ -470,7 +470,7 @@ void MillGameWindow::on_actionLimited_T_triggered()
int dTime = comboBox_time->currentData().toInt(); int dTime = comboBox_time->currentData().toInt();
if (gStep != dStep || gTime != dTime) { if (gStep != dStep || gTime != dTime) {
// 重置游戏规则 // 重置游戏规则
game->setRule(ruleNo, static_cast<step_t>(dStep), dTime); gameController->setRule(ruleNo, static_cast<step_t>(dStep), dTime);
} }
} }
@ -497,7 +497,7 @@ void MillGameWindow::actionRules_triggered()
ruleNo = action->data().toInt(); ruleNo = action->data().toInt();
// 如果游戏规则没变化,则返回 // 如果游戏规则没变化,则返回
if (ruleNo == game->getRuleNo()) if (ruleNo == gameController->getRuleIndex())
return; return;
// 取消AI设定 // 取消AI设定
@ -505,7 +505,7 @@ void MillGameWindow::actionRules_triggered()
ui.actionEngine2_R->setChecked(false); ui.actionEngine2_R->setChecked(false);
// 重置游戏规则 // 重置游戏规则
game->setRule(ruleNo); gameController->setRule(ruleNo);
// 更新规则显示 // 更新规则显示
ruleInfo(); ruleInfo();
@ -539,7 +539,7 @@ void MillGameWindow::on_actionNew_N_triggered()
ui.actionAutoRun_A->setChecked(false); ui.actionAutoRun_A->setChecked(false);
// 重置游戏规则 // 重置游戏规则
game->gameReset(); gameController->gameReset();
// 重设AI设定 // 重设AI设定
if (ui.actionEngine2_R->isChecked()) { if (ui.actionEngine2_R->isChecked()) {
@ -592,7 +592,7 @@ void MillGameWindow::on_actionOpen_O_triggered()
cmd = textStream.readLine(); cmd = textStream.readLine();
// 读取并显示棋谱时,不必刷新棋局场景 // 读取并显示棋谱时,不必刷新棋局场景
if (!(game->command(cmd, false))) { if (!(gameController->command(cmd, false))) {
// 定义新对话框 // 定义新对话框
QMessageBox msgBox(QMessageBox::Warning, tr("文件错误"), tr("不是正确的棋谱文件"), QMessageBox::Ok); QMessageBox msgBox(QMessageBox::Warning, tr("文件错误"), tr("不是正确的棋谱文件"), QMessageBox::Ok);
msgBox.exec(); msgBox.exec();
@ -601,11 +601,11 @@ void MillGameWindow::on_actionOpen_O_triggered()
while (!textStream.atEnd()) { while (!textStream.atEnd()) {
cmd = textStream.readLine(); cmd = textStream.readLine();
game->command(cmd, false); gameController->command(cmd, false);
} }
// 最后刷新棋局场景 // 最后刷新棋局场景
game->updateScence(); gameController->updateScence();
} }
void MillGameWindow::on_actionSave_S_triggered() void MillGameWindow::on_actionSave_S_triggered()
@ -685,7 +685,7 @@ void MillGameWindow::on_actionInvert_I_toggled(bool arg1)
} }
// 让控制器改变棋子颜色 // 让控制器改变棋子颜色
game->setInvert(arg1); gameController->setInvert(arg1);
} }
// 前后招的公共槽 // 前后招的公共槽
@ -749,7 +749,7 @@ void MillGameWindow::on_actionRowChange()
} }
// 更新局面 // 更新局面
game->phaseChange(currentRow); gameController->phaseChange(currentRow);
#if 0 #if 0
// 下面的代码全部取消改用QTimer的方式实现 // 下面的代码全部取消改用QTimer的方式实现
@ -818,7 +818,7 @@ void MillGameWindow::onAutoRunTimeOut(QPrivateSignal signal)
} }
// 更新局面 // 更新局面
game->phaseChange(currentRow); gameController->phaseChange(currentRow);
} }
// 自动运行 // 自动运行
@ -830,7 +830,7 @@ void MillGameWindow::on_actionAutoRun_A_toggled(bool arg1)
ui.gameView->setEnabled(false); ui.gameView->setEnabled(false);
// 启动定时器 // 启动定时器
autoRunTimer.start(game->getDurationTime() * 10 + 50); autoRunTimer.start(gameController->getDurationTime() * 10 + 50);
} else { } else {
// 关闭定时器 // 关闭定时器
autoRunTimer.stop(); autoRunTimer.stop();
@ -852,7 +852,7 @@ void MillGameWindow::on_actionInternet_I_triggered()
ui.actionLocal_L->setChecked(false); ui.actionLocal_L->setChecked(false);
ui.actionInternet_I->setChecked(true); ui.actionInternet_I->setChecked(true);
game->showNetworkWindow(); gameController->showNetworkWindow();
} }
void MillGameWindow::on_actionEngine_E_triggered() void MillGameWindow::on_actionEngine_E_triggered()
@ -928,7 +928,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
// 目前数据 // 目前数据
depth_t depth1, depth2; depth_t depth1, depth2;
int time1, time2; int time1, time2;
game->getAiDepthTime(depth1, time1, depth2, time2); gameController->getAiDepthTime(depth1, time1, depth2, time2);
spinBox_depth1->setValue(depth1); spinBox_depth1->setValue(depth1);
spinBox_depth2->setValue(depth2); spinBox_depth2->setValue(depth2);
spinBox_time1->setValue(time1); spinBox_time1->setValue(time1);
@ -950,7 +950,7 @@ void MillGameWindow::on_actionEngine_E_triggered()
time1 != time1_new || time1 != time1_new ||
time2 != time2_new) { time2 != time2_new) {
// 重置AI // 重置AI
game->setAiDepthTime(depth1_new, time1_new, depth2_new, time2_new); gameController->setAiDepthTime(depth1_new, time1_new, depth2_new, time2_new);
} }
} }

View File

@ -114,7 +114,7 @@ private:
GameScene *scene {nullptr}; GameScene *scene {nullptr};
// 控制器 // 控制器
GameController *game {nullptr}; GameController *gameController {nullptr};
// 动态增加的菜单栏动作列表 // 动态增加的菜单栏动作列表
QList <QAction *> ruleActionList; QList <QAction *> ruleActionList;

View File

@ -49,7 +49,7 @@ PieceItem::PieceItem(QGraphicsItem *parent) :
//setAcceptHoverEvents(true); //setAcceptHoverEvents(true);
// 默认模型为没有棋子 // 默认模型为没有棋子
model_ = noPiece; model = noPiece;
// 棋子尺寸 // 棋子尺寸
size = PIECE_SIZE; size = PIECE_SIZE;
@ -95,7 +95,7 @@ void PieceItem::paint(QPainter *painter,
// 空模型不画棋子 // 空模型不画棋子
switch (model_) { switch (model) {
case blackPiece: case blackPiece:
// 如果模型为黑色,则画黑色棋子 // 如果模型为黑色,则画黑色棋子
#ifdef MOBILE_APP_UI #ifdef MOBILE_APP_UI
@ -126,11 +126,11 @@ void PieceItem::paint(QPainter *painter,
// 如果模型要求显示序号 // 如果模型要求显示序号
if (showNum) { if (showNum) {
// 如果模型为黑色,用白色笔画序号 // 如果模型为黑色,用白色笔画序号
if (model_ == blackPiece) if (model == blackPiece)
painter->setPen(QColor(255, 255, 255)); painter->setPen(QColor(255, 255, 255));
// 如果模型为白色,用白色笔画序号 // 如果模型为白色,用白色笔画序号
if (model_ == whitePiece) if (model == whitePiece)
painter->setPen(QColor(0, 0, 0)); painter->setPen(QColor(0, 0, 0));
// 字体 // 字体
@ -162,7 +162,7 @@ void PieceItem::paint(QPainter *painter,
} }
// 如果模型为删除状态,则画上叉号 // 如果模型为删除状态,则画上叉号
if (deleted_) { if (deleted) {
QPen pen(removeLineColor, removeLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin); QPen pen(removeLineColor, removeLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
painter->setPen(pen); painter->setPen(pen);

View File

@ -69,12 +69,12 @@ public:
enum Models getModel() enum Models getModel()
{ {
return model_; return model;
} }
void setModel(enum Models model) void setModel(enum Models m)
{ {
this->model_ = model; this->model = m;
} }
int getNum() int getNum()
@ -89,15 +89,15 @@ public:
bool isDeleted() bool isDeleted()
{ {
return deleted_; return deleted;
} }
void setDeleted(bool deleted = true) void setDeleted(bool del = true)
{ {
this->deleted_ = deleted; deleted = del;
if (deleted) if (deleted)
this->model_ = noPiece; this->model = noPiece;
update(boundingRect()); update(boundingRect());
} }
@ -114,7 +114,7 @@ protected:
private: private:
// 棋子本质 // 棋子本质
enum Models model_; enum Models model;
// 棋子序号黑白都从1开始 // 棋子序号黑白都从1开始
int num = 1; int num = 1;
@ -123,7 +123,7 @@ private:
int size; int size;
// 有无删除线 // 有无删除线
bool deleted_ {false}; bool deleted {false};
// 显示序号 // 显示序号
bool showNum {false}; bool showNum {false};

View File

@ -31,7 +31,7 @@ Server::Server(QWidget *parent, uint16_t port)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); statusLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
this->port_ = port; this->port = port;
QNetworkConfigurationManager manager; QNetworkConfigurationManager manager;
@ -110,9 +110,9 @@ void Server::sessionOpened()
tcpServer = new QTcpServer(this); tcpServer = new QTcpServer(this);
if (!tcpServer->listen(QHostAddress::LocalHost, port_)) { if (!tcpServer->listen(QHostAddress::LocalHost, port)) {
port_++; port++;
if (!tcpServer->listen(QHostAddress::LocalHost, port_)) { if (!tcpServer->listen(QHostAddress::LocalHost, port)) {
QMessageBox::critical(this, tr("Server"), QMessageBox::critical(this, tr("Server"),
tr("Unable to start the server: %1.") tr("Unable to start the server: %1.")
.arg(tcpServer->errorString())); .arg(tcpServer->errorString()));
@ -150,9 +150,9 @@ void Server::sessionOpened()
.arg(ipAddress).arg(tcpServer->serverPort())); .arg(ipAddress).arg(tcpServer->serverPort()));
} }
void Server::setAction(const QString &action) void Server::setAction(const QString &a)
{ {
actions.push(action); actions.push(a);
} }
void Server::sendAction() void Server::sendAction()
@ -162,10 +162,10 @@ void Server::sendAction()
out.setVersion(QDataStream::Qt_5_10); out.setVersion(QDataStream::Qt_5_10);
if (!actions.empty()) { if (!actions.empty()) {
action_ = actions.front(); action = actions.front();
} }
out << action_; out << action;
QTcpSocket *clientConnection = tcpServer->nextPendingConnection(); QTcpSocket *clientConnection = tcpServer->nextPendingConnection();

View File

@ -39,13 +39,13 @@ class Server : public QDialog
public: public:
explicit Server(QWidget *parent = nullptr, uint16_t port = 33333); explicit Server(QWidget *parent = nullptr, uint16_t port = 33333);
void setAction(const QString &action); void setAction(const QString &action);
void setPort(uint16_t port) void setPort(uint16_t p)
{ {
this->port_ = port; port = p;
} }
uint16_t getPort() uint16_t getPort()
{ {
return port_; return port;
} }
private slots: private slots:
@ -56,9 +56,9 @@ private:
QLabel *statusLabel = nullptr; QLabel *statusLabel = nullptr;
QTcpServer *tcpServer = nullptr; QTcpServer *tcpServer = nullptr;
QNetworkSession *networkSession = nullptr; QNetworkSession *networkSession = nullptr;
uint16_t port_; uint16_t port;
std::queue<QString> actions; std::queue<QString> actions;
QString action_; QString action;
}; };
#endif // SERVER_H #endif // SERVER_H