From 3fee6da533a74038478e7f1ce2f2ebf287a59272 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Fri, 20 Sep 2019 01:02:17 +0800 Subject: [PATCH] =?UTF-8?q?option:=20=E5=B0=86=20giveUpIfMostLose=20?= =?UTF-8?q?=E8=BD=AC=20=E5=88=B0=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai/search.cpp | 3 ++- src/game/option.cpp | 12 +++++++++++- src/game/option.h | 2 ++ src/game/position.cpp | 13 ------------- src/game/position.h | 12 ------------ src/ui/qt/gamecontroller.cpp | 9 ++------- src/ui/qt/gamecontroller.h | 7 +------ 7 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/ai/search.cpp b/src/ai/search.cpp index ed3ebc15..1015f736 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -31,6 +31,7 @@ #include "tt.h" #include "endgame.h" #include "types.h" +#include "option.h" using namespace CTSL; @@ -715,7 +716,7 @@ const char* AIAlgorithm::bestMove() #endif /* ENDGAME_LEARNING */ // 检查是否必败 - if (game_.getGiveUpIfMostLose() == true) { + if (options.getGiveUpIfMostLose() == true) { bool isMostLose = true; // 是否必败 for (auto child : root->children) { diff --git a/src/game/option.cpp b/src/game/option.cpp index b9961ea0..fe0dd848 100644 --- a/src/game/option.cpp +++ b/src/game/option.cpp @@ -31,4 +31,14 @@ void Options::setAutoRestart(bool enabled) bool Options::getAutoRestart() { return isAutoRestart; -} \ No newline at end of file +} + +void Options::setGiveUpIfMostLose(bool enabled) +{ + giveUpIfMostLose = enabled; +} + +bool Options::getGiveUpIfMostLose() +{ + return giveUpIfMostLose; +} diff --git a/src/game/option.h b/src/game/option.h index 0e424489..5cf0353b 100644 --- a/src/game/option.h +++ b/src/game/option.h @@ -30,6 +30,8 @@ public: void setAutoRestart(bool enabled); bool getAutoRestart(); + void setGiveUpIfMostLose(bool enabled); + bool getGiveUpIfMostLose(); protected: private: diff --git a/src/game/position.cpp b/src/game/position.cpp index 27c8c94d..f63cee6f 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -63,7 +63,6 @@ Game &Game::operator= (const Game &game) currentStep = game.currentStep; moveStep = game.moveStep; isRandomMove = game.isRandomMove; - giveUpIfMostLose_ = game.giveUpIfMostLose_; boardLocations = position.board.locations; currentLocation = game.currentLocation; winner = game.winner; @@ -79,18 +78,6 @@ Game &Game::operator= (const Game &game) return *this; } -// 设置配置 -bool Game::configure(bool giveUpIfMostLose, bool randomMove) -{ - // 设置是否必败时认输 - this->giveUpIfMostLose_ = giveUpIfMostLose; - - // 设置是否随机走子 - this->isRandomMove = randomMove; - - return true; -} - // 设置棋局状态和棋盘数据,用于初始化 bool Game::setPosition(const struct Rule *rule, step_t maxStepsLedToDraw, int maxTimeLedToLose, step_t initialStep, diff --git a/src/game/position.h b/src/game/position.h index 2429d021..98235ccd 100644 --- a/src/game/position.h +++ b/src/game/position.h @@ -99,9 +99,6 @@ public: // 运算符重载 Game &operator=(const Game &); - // 设置配置 - bool configure(bool giveUpIfMostLose, bool randomMove); - // 设置棋局状态和棋局,用于初始化 bool setPosition(const struct Rule *rule, step_t maxStepsLedToDraw = 0, // 限制步数 @@ -144,12 +141,6 @@ public: return moveStep; } - // 获取是否必败时认输 - bool getGiveUpIfMostLose() const - { - return giveUpIfMostLose_; - } - // 获取 AI 是否随机走子 bool randomMoveEnabled() const { @@ -336,9 +327,6 @@ private: // 从走子阶段开始或上次吃子起的步数 int moveStep {}; - // 是否必败时认输 - bool giveUpIfMostLose_ {false}; - // AI 是否随机走子 bool isRandomMove {true}; diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index 19f62310..501f3cac 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -50,7 +50,6 @@ GameController::GameController(GameScene & scene, QObject * parent) : ruleNo_(-1), timeLimit(0), stepsLimit(50), - giveUpIfMostLose_(false), randomMove_(true) { // 已在view的样式表中添加背景,scene中不用添加背景 @@ -122,7 +121,6 @@ const QMap GameController::getActions() void GameController::gameStart() { - game_.configure(giveUpIfMostLose_, randomMove_); game_.start(); tempGame = game_; @@ -148,7 +146,6 @@ void GameController::gameReset() } // 重置游戏 - game_.configure(giveUpIfMostLose_, randomMove_); game_.reset(); tempGame = game_; @@ -289,8 +286,6 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi void GameController::setEngine(int id, bool arg) { - game_.configure(giveUpIfMostLose_, randomMove_); - isAiPlayer[id] = arg; if (arg) { @@ -371,9 +366,9 @@ void GameController::playSound(const QString &soundPath) #endif /* ! DONOT_PLAY_SOUND */ } -void GameController::setGiveUpIfMostLose(bool arg) +void GameController::setGiveUpIfMostLose(bool enabled) { - giveUpIfMostLose_ = arg; + options.setGiveUpIfMostLose(enabled); } void GameController::setAutoRestart(bool enabled) diff --git a/src/ui/qt/gamecontroller.h b/src/ui/qt/gamecontroller.h index 04f77b26..b2d67725 100644 --- a/src/ui/qt/gamecontroller.h +++ b/src/ui/qt/gamecontroller.h @@ -70,11 +70,6 @@ public: return stepsLimit; } - bool getGiveUpIfMostLose() - { - return giveUpIfMostLose_; - } - bool getRandomMove() { return randomMove_; @@ -155,7 +150,7 @@ public slots: void playSound(const QString &soundPath); // 是否必败时认输 - void setGiveUpIfMostLose(bool arg); + void setGiveUpIfMostLose(bool enabled); // 是否自动开局 void setAutoRestart(bool enabled = false);