option: 将 giveUpIfMostLose 转 到 options

This commit is contained in:
CalciteM Team 2019-09-20 01:02:17 +08:00
parent 08cd2d97bb
commit 3fee6da533
7 changed files with 18 additions and 40 deletions

View File

@ -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) {

View File

@ -31,4 +31,14 @@ void Options::setAutoRestart(bool enabled)
bool Options::getAutoRestart()
{
return isAutoRestart;
}
}
void Options::setGiveUpIfMostLose(bool enabled)
{
giveUpIfMostLose = enabled;
}
bool Options::getGiveUpIfMostLose()
{
return giveUpIfMostLose;
}

View File

@ -30,6 +30,8 @@ public:
void setAutoRestart(bool enabled);
bool getAutoRestart();
void setGiveUpIfMostLose(bool enabled);
bool getGiveUpIfMostLose();
protected:
private:

View File

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

View File

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

View File

@ -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<int, QStringList> 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)

View File

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