diff --git a/src/ai/movegen.cpp b/src/ai/movegen.cpp index 9dd4dc04..80e9d1f9 100644 --- a/src/ai/movegen.cpp +++ b/src/ai/movegen.cpp @@ -24,6 +24,7 @@ #include "movegen.h" #include "player.h" #include "misc.h" +#include "option.h" void MoveList::generate(AIAlgorithm &ai, Game &tempGame, AIAlgorithm::Node *node, AIAlgorithm::Node *root, @@ -374,14 +375,14 @@ void MoveList::create(Game &game) #endif } -void MoveList::shuffle(Game &game) +void MoveList::shuffle() { array movePriorityTable0 = { (move_t)17, (move_t)19, (move_t)21, (move_t)23 }; // 中圈四个顶点 (星位) array movePriorityTable1 = { (move_t)25, (move_t)27, (move_t)29, (move_t)31, (move_t)9, (move_t)11, (move_t)13, (move_t)15 }; // 外圈和内圈四个顶点 array movePriorityTable2 = { (move_t)16, (move_t)18, (move_t)20, (move_t)22 }; // 中圈十字架 array movePriorityTable3 = { (move_t)24, (move_t)26, (move_t)28, (move_t)30, (move_t)8, (move_t)10, (move_t)12, (move_t)14 }; // 外内圈十字架 - if (game.randomMoveEnabled()) { + if (options.getRandomMoveEnabled()) { uint32_t seed = static_cast(now()); std::shuffle(movePriorityTable0.begin(), movePriorityTable0.end(), std::default_random_engine(seed)); diff --git a/src/ai/movegen.h b/src/ai/movegen.h index ad76198a..00a7b448 100644 --- a/src/ai/movegen.h +++ b/src/ai/movegen.h @@ -42,7 +42,7 @@ public: static void create(Game &game); // 随机打乱着法搜索顺序 - static void shuffle(Game &game); + static void shuffle(); // 着法表 // TODO: Move to private inline static move_t moveTable[Board::N_LOCATIONS][DIRECTIONS_COUNT] = { {MOVE_NONE} }; diff --git a/src/ai/search.cpp b/src/ai/search.cpp index 1015f736..63b4c4dc 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -359,7 +359,7 @@ int AIAlgorithm::search(depth_t depth) #endif // THREEFOLD_REPETITION // 随机打乱着法顺序 - MoveList::shuffle(game_); + MoveList::shuffle(); #ifdef IDS_SUPPORT // 深化迭代 diff --git a/src/game/option.cpp b/src/game/option.cpp index fe0dd848..18f97088 100644 --- a/src/game/option.cpp +++ b/src/game/option.cpp @@ -42,3 +42,13 @@ bool Options::getGiveUpIfMostLose() { return giveUpIfMostLose; } + +void Options::setRandomMoveEnabled(bool enabled) +{ + randomMoveEnabled = enabled; +} + +bool Options::getRandomMoveEnabled() +{ + return randomMoveEnabled; +} diff --git a/src/game/option.h b/src/game/option.h index 5cf0353b..2ec4635a 100644 --- a/src/game/option.h +++ b/src/game/option.h @@ -32,6 +32,9 @@ public: void setGiveUpIfMostLose(bool enabled); bool getGiveUpIfMostLose(); + + void setRandomMoveEnabled(bool enabled); + bool getRandomMoveEnabled(); protected: private: @@ -40,6 +43,9 @@ private: // 是否必败时认输 bool giveUpIfMostLose { false }; + + // AI 是否随机走子 + bool randomMoveEnabled { true }; }; extern Options options; diff --git a/src/game/position.cpp b/src/game/position.cpp index f63cee6f..358e6746 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -62,7 +62,6 @@ Game &Game::operator= (const Game &game) position = game.position; currentStep = game.currentStep; moveStep = game.moveStep; - isRandomMove = game.isRandomMove; boardLocations = position.board.locations; currentLocation = game.currentLocation; winner = game.winner; diff --git a/src/game/position.h b/src/game/position.h index 98235ccd..c135767a 100644 --- a/src/game/position.h +++ b/src/game/position.h @@ -141,12 +141,6 @@ public: return moveStep; } - // 获取 AI 是否随机走子 - bool randomMoveEnabled() const - { - return isRandomMove; - } - // 获取局面阶段标识 enum phase_t getPhase() const { @@ -327,10 +321,7 @@ private: // 从走子阶段开始或上次吃子起的步数 int moveStep {}; - // AI 是否随机走子 - bool isRandomMove {true}; - - // 游戏起始时间 + // 游戏起始时间 time_t startTime {}; // 当前游戏时间 diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index 501f3cac..074fc3e4 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -49,8 +49,7 @@ GameController::GameController(GameScene & scene, QObject * parent) : timeID(0), ruleNo_(-1), timeLimit(0), - stepsLimit(50), - randomMove_(true) + stepsLimit(50) { // 已在view的样式表中添加背景,scene中不用添加背景 // 区别在于,view中的背景不随视图变换而变换,scene中的背景随视图变换而变换 @@ -376,9 +375,9 @@ void GameController::setAutoRestart(bool enabled) options.setAutoRestart(enabled); } -void GameController::setRandomMove(bool arg) +void GameController::setRandomMove(bool enabled) { - randomMove_ = arg; + options.setRandomMoveEnabled(enabled); } // 上下翻转 diff --git a/src/ui/qt/gamecontroller.h b/src/ui/qt/gamecontroller.h index b2d67725..276c975a 100644 --- a/src/ui/qt/gamecontroller.h +++ b/src/ui/qt/gamecontroller.h @@ -70,11 +70,6 @@ public: return stepsLimit; } - bool getRandomMove() - { - return randomMove_; - } - bool isAnimation() { return hasAnimation; @@ -156,7 +151,7 @@ public slots: void setAutoRestart(bool enabled = false); // AI 是否随机走子 - void setRandomMove(bool arg); + void setRandomMove(bool enabled); // 上下翻转 void flip(); @@ -239,9 +234,6 @@ private: // 是否必败时认输 bool giveUpIfMostLose_ {false}; - // AI 是否随机走子 - bool randomMove_; - // 定时器ID int timeID;