option: RandomMoveEnabled 转移到 options

This commit is contained in:
CalciteM Team 2019-09-20 01:18:56 +08:00
parent 3fee6da533
commit 75ea71b3ea
9 changed files with 26 additions and 28 deletions

View File

@ -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<move_t, 4> movePriorityTable0 = { (move_t)17, (move_t)19, (move_t)21, (move_t)23 }; // 中圈四个顶点 (星位)
array<move_t, 8> 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<move_t, 4> movePriorityTable2 = { (move_t)16, (move_t)18, (move_t)20, (move_t)22 }; // 中圈十字架
array<move_t, 8> 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<uint32_t>(now());
std::shuffle(movePriorityTable0.begin(), movePriorityTable0.end(), std::default_random_engine(seed));

View File

@ -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} };

View File

@ -359,7 +359,7 @@ int AIAlgorithm::search(depth_t depth)
#endif // THREEFOLD_REPETITION
// 随机打乱着法顺序
MoveList::shuffle(game_);
MoveList::shuffle();
#ifdef IDS_SUPPORT
// 深化迭代

View File

@ -42,3 +42,13 @@ bool Options::getGiveUpIfMostLose()
{
return giveUpIfMostLose;
}
void Options::setRandomMoveEnabled(bool enabled)
{
randomMoveEnabled = enabled;
}
bool Options::getRandomMoveEnabled()
{
return randomMoveEnabled;
}

View File

@ -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;

View File

@ -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;

View File

@ -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 {};
// 当前游戏时间

View File

@ -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);
}
// 上下翻转

View File

@ -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;