refactor: Move option.cpp functions to .h and rename RandomMove to Shuffling
This commit is contained in:
parent
728c7000fa
commit
9875c9c861
|
@ -295,7 +295,7 @@
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionResignIfMostLose_G"/>
|
<addaction name="actionResignIfMostLose_G"/>
|
||||||
<addaction name="actionAutoRestart_A"/>
|
<addaction name="actionAutoRestart_A"/>
|
||||||
<addaction name="actionRandomMove_R"/>
|
<addaction name="actionShuffling_R"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menu_H">
|
<widget class="QMenu" name="menu_H">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -1211,7 +1211,7 @@
|
||||||
<string>自动重新开局(&A)</string>
|
<string>自动重新开局(&A)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionRandomMove_R">
|
<action name="actionShuffling_R">
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -286,7 +286,7 @@ void move_priority_list_shuffle()
|
||||||
movePriorityList3 = { SQ_24, SQ_26, SQ_28, SQ_30, SQ_8, SQ_10, SQ_12, SQ_14 };
|
movePriorityList3 = { SQ_24, SQ_26, SQ_28, SQ_30, SQ_8, SQ_10, SQ_12, SQ_14 };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameOptions.getRandomMoveEnabled()) {
|
if (gameOptions.getShufflingEnabled()) {
|
||||||
uint32_t seed = static_cast<uint32_t>(now());
|
uint32_t seed = static_cast<uint32_t>(now());
|
||||||
|
|
||||||
std::shuffle(movePriorityList0.begin(), movePriorityList0.end(), std::default_random_engine(seed));
|
std::shuffle(movePriorityList0.begin(), movePriorityList0.end(), std::default_random_engine(seed));
|
||||||
|
|
|
@ -19,95 +19,3 @@
|
||||||
#include "option.h"
|
#include "option.h"
|
||||||
|
|
||||||
GameOptions gameOptions;
|
GameOptions gameOptions;
|
||||||
|
|
||||||
void GameOptions::setAutoRestart(bool enabled)
|
|
||||||
{
|
|
||||||
isAutoRestart = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getAutoRestart()
|
|
||||||
{
|
|
||||||
return isAutoRestart;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameOptions::setAutoChangeFirstMove(bool enabled)
|
|
||||||
{
|
|
||||||
isAutoChangeFirstMove = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getAutoChangeFirstMove()
|
|
||||||
{
|
|
||||||
return isAutoChangeFirstMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameOptions::setResignIfMostLose(bool enabled)
|
|
||||||
{
|
|
||||||
resignIfMostLose = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getResignIfMostLose()
|
|
||||||
{
|
|
||||||
return resignIfMostLose;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameOptions::setRandomMoveEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
randomMoveEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getRandomMoveEnabled()
|
|
||||||
{
|
|
||||||
return randomMoveEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameOptions::setLearnEndgameEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
#ifdef ENDGAME_LEARNING_FORCE
|
|
||||||
learnEndgame = true;
|
|
||||||
#else
|
|
||||||
learnEndgame = enabled;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getLearnEndgameEnabled()
|
|
||||||
{
|
|
||||||
#ifdef ENDGAME_LEARNING_FORCE
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return learnEndgame;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameOptions::setIDSEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
IDSEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getIDSEnabled()
|
|
||||||
{
|
|
||||||
return IDSEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepthExtension
|
|
||||||
|
|
||||||
void GameOptions::setDepthExtension(bool enabled)
|
|
||||||
{
|
|
||||||
depthExtension = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getDepthExtension()
|
|
||||||
{
|
|
||||||
return depthExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpeningBook
|
|
||||||
|
|
||||||
void GameOptions::setOpeningBook(bool enabled)
|
|
||||||
{
|
|
||||||
openingBook = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameOptions::getOpeningBook()
|
|
||||||
{
|
|
||||||
return openingBook;
|
|
||||||
}
|
|
||||||
|
|
106
src/option.h
106
src/option.h
|
@ -24,31 +24,103 @@
|
||||||
class GameOptions
|
class GameOptions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setAutoRestart(bool enabled);
|
void setAutoRestart(bool enabled)
|
||||||
bool getAutoRestart();
|
{
|
||||||
|
isAutoRestart = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void setAutoChangeFirstMove(bool enabled);
|
bool getAutoRestart()
|
||||||
bool getAutoChangeFirstMove();
|
{
|
||||||
|
return isAutoRestart;
|
||||||
|
}
|
||||||
|
|
||||||
void setResignIfMostLose(bool enabled);
|
void setAutoChangeFirstMove(bool enabled)
|
||||||
bool getResignIfMostLose();
|
{
|
||||||
|
isAutoChangeFirstMove = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void setRandomMoveEnabled(bool enabled);
|
bool getAutoChangeFirstMove()
|
||||||
bool getRandomMoveEnabled();
|
{
|
||||||
|
return isAutoChangeFirstMove;
|
||||||
|
}
|
||||||
|
|
||||||
void setLearnEndgameEnabled(bool enabled);
|
void setResignIfMostLose(bool enabled)
|
||||||
bool getLearnEndgameEnabled();
|
{
|
||||||
|
resignIfMostLose = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void setIDSEnabled(bool enabled);
|
bool getResignIfMostLose()
|
||||||
bool getIDSEnabled();
|
{
|
||||||
|
return resignIfMostLose;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specify whether the successors of a given state should be shuffled if a
|
||||||
|
// re-evaluation is required so that the AI algorithm is not favoring one
|
||||||
|
// state if multiple ones have equal evaluations. This introduces some
|
||||||
|
// variation between different games against an opponent that tries to do the
|
||||||
|
// same sequence of moves. By default, shuffling is enabled.
|
||||||
|
|
||||||
|
bool getShufflingEnabled()
|
||||||
|
{
|
||||||
|
return shufflingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setShufflingEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
shufflingEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLearnEndgameEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
#ifdef ENDGAME_LEARNING_FORCE
|
||||||
|
learnEndgame = true;
|
||||||
|
#else
|
||||||
|
learnEndgame = enabled;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getLearnEndgameEnabled()
|
||||||
|
{
|
||||||
|
#ifdef ENDGAME_LEARNING_FORCE
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return learnEndgame;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIDSEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
IDSEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getIDSEnabled()
|
||||||
|
{
|
||||||
|
return IDSEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
// DepthExtension
|
// DepthExtension
|
||||||
void setDepthExtension(bool enabled);
|
|
||||||
bool getDepthExtension();
|
void setDepthExtension(bool enabled)
|
||||||
|
{
|
||||||
|
depthExtension = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getDepthExtension()
|
||||||
|
{
|
||||||
|
return depthExtension;
|
||||||
|
}
|
||||||
|
|
||||||
// OpeningBook
|
// OpeningBook
|
||||||
void setOpeningBook(bool enabled);
|
|
||||||
bool getOpeningBook();
|
void setOpeningBook(bool enabled)
|
||||||
|
{
|
||||||
|
openingBook = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getOpeningBook()
|
||||||
|
{
|
||||||
|
return openingBook;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -56,7 +128,7 @@ private:
|
||||||
bool isAutoRestart { false };
|
bool isAutoRestart { false };
|
||||||
bool isAutoChangeFirstMove { false };
|
bool isAutoChangeFirstMove { false };
|
||||||
bool resignIfMostLose { false };
|
bool resignIfMostLose { false };
|
||||||
bool randomMoveEnabled { true };
|
bool shufflingEnabled { true };
|
||||||
#ifdef ENDGAME_LEARNING_FORCE
|
#ifdef ENDGAME_LEARNING_FORCE
|
||||||
bool learnEndgame { true };
|
bool learnEndgame { true };
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -62,7 +62,7 @@ void on_threads(const Option &o)
|
||||||
|
|
||||||
void on_random_move(const Option &o)
|
void on_random_move(const Option &o)
|
||||||
{
|
{
|
||||||
gameOptions.setRandomMoveEnabled((bool)o);
|
gameOptions.setShufflingEnabled((bool)o);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
|
@ -153,7 +153,7 @@ void init(OptionsMap &o)
|
||||||
o["UCI_LimitStrength"] << Option(false);
|
o["UCI_LimitStrength"] << Option(false);
|
||||||
o["UCI_Elo"] << Option(1350, 1350, 2850);
|
o["UCI_Elo"] << Option(1350, 1350, 2850);
|
||||||
|
|
||||||
o["RandomMove"] << Option(true, on_random_move);
|
o["Shuffling"] << Option(true, on_random_move);
|
||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
o["nTotalPiecesEachSide"] << Option(12, 6, 12, on_nTotalPiecesEachSide);
|
o["nTotalPiecesEachSide"] << Option(12, 6, 12, on_nTotalPiecesEachSide);
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Config {
|
||||||
static bool isAutoRestart = false;
|
static bool isAutoRestart = false;
|
||||||
static bool isAutoChangeFirstMove = false;
|
static bool isAutoChangeFirstMove = false;
|
||||||
static bool resignIfMostLose = false;
|
static bool resignIfMostLose = false;
|
||||||
static bool randomMoveEnabled = true;
|
static bool shufflingEnabled = true;
|
||||||
static bool learnEndgame = false;
|
static bool learnEndgame = false;
|
||||||
static bool idsEnabled = false;
|
static bool idsEnabled = false;
|
||||||
static bool depthExtension = true;
|
static bool depthExtension = true;
|
||||||
|
@ -60,7 +60,7 @@ class Config {
|
||||||
Config.isAutoRestart = profile['isAutoRestart'] ?? false;
|
Config.isAutoRestart = profile['isAutoRestart'] ?? false;
|
||||||
Config.isAutoChangeFirstMove = profile['isAutoChangeFirstMove'] ?? false;
|
Config.isAutoChangeFirstMove = profile['isAutoChangeFirstMove'] ?? false;
|
||||||
Config.resignIfMostLose = profile['resignIfMostLose'] ?? false;
|
Config.resignIfMostLose = profile['resignIfMostLose'] ?? false;
|
||||||
Config.randomMoveEnabled = profile['randomMoveEnabled'] ?? true;
|
Config.shufflingEnabled = profile['shufflingEnabled'] ?? true;
|
||||||
Config.learnEndgame = profile['learnEndgame'] ?? false;
|
Config.learnEndgame = profile['learnEndgame'] ?? false;
|
||||||
Config.idsEnabled = profile['idsEnabled'] ?? false;
|
Config.idsEnabled = profile['idsEnabled'] ?? false;
|
||||||
Config.depthExtension = profile['depthExtension'] ?? false;
|
Config.depthExtension = profile['depthExtension'] ?? false;
|
||||||
|
@ -107,7 +107,7 @@ class Config {
|
||||||
profile['isAutoRestart'] = Config.isAutoRestart;
|
profile['isAutoRestart'] = Config.isAutoRestart;
|
||||||
profile['isAutoChangeFirstMove'] = Config.isAutoChangeFirstMove;
|
profile['isAutoChangeFirstMove'] = Config.isAutoChangeFirstMove;
|
||||||
profile['resignIfMostLose'] = Config.resignIfMostLose;
|
profile['resignIfMostLose'] = Config.resignIfMostLose;
|
||||||
profile['randomMoveEnabled'] = Config.randomMoveEnabled;
|
profile['shufflingEnabled'] = Config.shufflingEnabled;
|
||||||
profile['learnEndgame'] = Config.learnEndgame;
|
profile['learnEndgame'] = Config.learnEndgame;
|
||||||
profile['idsEnabled'] = Config.idsEnabled;
|
profile['idsEnabled'] = Config.idsEnabled;
|
||||||
profile['depthExtension'] = Config.depthExtension;
|
profile['depthExtension'] = Config.depthExtension;
|
||||||
|
|
|
@ -133,7 +133,7 @@ class NativeEngine extends AiEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setOptions() async {
|
Future<void> setOptions() async {
|
||||||
await send('setoption name RandomMove value ${Config.randomMoveEnabled}');
|
await send('setoption name Shuffling value ${Config.shufflingEnabled}');
|
||||||
await send(
|
await send(
|
||||||
'setoption name nTotalPiecesEachSide value ${Config.nTotalPiecesEachSide}');
|
'setoption name nTotalPiecesEachSide value ${Config.nTotalPiecesEachSide}');
|
||||||
await send('setoption name nPiecesAtLeast value ${Config.nPiecesAtLeast}');
|
await send('setoption name nPiecesAtLeast value ${Config.nPiecesAtLeast}');
|
||||||
|
|
|
@ -283,8 +283,8 @@
|
||||||
"@resignIfMostLose": {
|
"@resignIfMostLose": {
|
||||||
"description": "AI Resign if Most Lose"
|
"description": "AI Resign if Most Lose"
|
||||||
},
|
},
|
||||||
"randomMoveEnabled": "AI Random Move",
|
"shufflingEnabled": "AI Random Move",
|
||||||
"@randomMoveEnabled": {
|
"@shufflingEnabled": {
|
||||||
"description": "AI Random Move"
|
"description": "AI Random Move"
|
||||||
},
|
},
|
||||||
"learnEndgame": "Learn Endgame",
|
"learnEndgame": "Learn Endgame",
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
"isAutoRestart": "棋局结束时自动重新开局",
|
"isAutoRestart": "棋局结束时自动重新开局",
|
||||||
"isAutoChangeFirstMove": "开局时自动交换先后手",
|
"isAutoChangeFirstMove": "开局时自动交换先后手",
|
||||||
"resignIfMostLose": "机器明显劣势时自动认输",
|
"resignIfMostLose": "机器明显劣势时自动认输",
|
||||||
"randomMoveEnabled": "机器随机走子",
|
"shufflingEnabled": "机器随机走子",
|
||||||
"learnEndgame": "残局库自学习",
|
"learnEndgame": "残局库自学习",
|
||||||
"idsEnabled": "迭代加深",
|
"idsEnabled": "迭代加深",
|
||||||
"depthExtension": "深度扩展",
|
"depthExtension": "深度扩展",
|
||||||
|
|
|
@ -132,9 +132,9 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||||
Config.save();
|
Config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
switchRandomMoveEnabled(bool value) async {
|
switchShufflingEnabled(bool value) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
Config.randomMoveEnabled = value;
|
Config.shufflingEnabled = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
Config.save();
|
Config.save();
|
||||||
|
@ -667,10 +667,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||||
_buildDivider(),
|
_buildDivider(),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
activeColor: UIColors.primaryColor,
|
activeColor: UIColors.primaryColor,
|
||||||
value: Config.randomMoveEnabled,
|
value: Config.shufflingEnabled,
|
||||||
title:
|
title:
|
||||||
Text(S.of(context).randomMoveEnabled, style: itemStyle),
|
Text(S.of(context).shufflingEnabled, style: itemStyle),
|
||||||
onChanged: switchRandomMoveEnabled,
|
onChanged: switchShufflingEnabled,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -549,9 +549,9 @@ void Game::setAutoChangeFirstMove(bool enabled)
|
||||||
gameOptions.setAutoChangeFirstMove(enabled);
|
gameOptions.setAutoChangeFirstMove(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setRandomMove(bool enabled)
|
void Game::setShuffling(bool enabled)
|
||||||
{
|
{
|
||||||
gameOptions.setRandomMoveEnabled(enabled);
|
gameOptions.setShufflingEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::setLearnEndgame(bool enabled)
|
void Game::setLearnEndgame(bool enabled)
|
||||||
|
|
|
@ -239,7 +239,7 @@ public slots:
|
||||||
void setAutoChangeFirstMove(bool enabled = false);
|
void setAutoChangeFirstMove(bool enabled = false);
|
||||||
|
|
||||||
// AI 是否随机走子
|
// AI 是否随机走子
|
||||||
void setRandomMove(bool enabled);
|
void setShuffling(bool enabled);
|
||||||
|
|
||||||
// AI 是否记录残局库
|
// AI 是否记录残局库
|
||||||
void setLearnEndgame(bool enabled);
|
void setLearnEndgame(bool enabled);
|
||||||
|
|
|
@ -235,8 +235,8 @@ void MillGameWindow::initialize()
|
||||||
connect(ui.actionAutoChangeFirstMove_C, SIGNAL(toggled(bool)),
|
connect(ui.actionAutoChangeFirstMove_C, SIGNAL(toggled(bool)),
|
||||||
game, SLOT(setAutoChangeFirstMove(bool)));
|
game, SLOT(setAutoChangeFirstMove(bool)));
|
||||||
|
|
||||||
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
|
connect(ui.actionShuffling_R, SIGNAL(toggled(bool)),
|
||||||
game, SLOT(setRandomMove(bool)));
|
game, SLOT(setShuffling(bool)));
|
||||||
|
|
||||||
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
|
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
|
||||||
game, SLOT(setLearnEndgame(bool)));
|
game, SLOT(setLearnEndgame(bool)));
|
||||||
|
|
Loading…
Reference in New Issue