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="actionResignIfMostLose_G"/>
|
||||
<addaction name="actionAutoRestart_A"/>
|
||||
<addaction name="actionRandomMove_R"/>
|
||||
<addaction name="actionShuffling_R"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_H">
|
||||
<property name="title">
|
||||
|
@ -1211,7 +1211,7 @@
|
|||
<string>自动重新开局(&A)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRandomMove_R">
|
||||
<action name="actionShuffling_R">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</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 };
|
||||
}
|
||||
|
||||
if (gameOptions.getRandomMoveEnabled()) {
|
||||
if (gameOptions.getShufflingEnabled()) {
|
||||
uint32_t seed = static_cast<uint32_t>(now());
|
||||
|
||||
std::shuffle(movePriorityList0.begin(), movePriorityList0.end(), std::default_random_engine(seed));
|
||||
|
|
|
@ -19,95 +19,3 @@
|
|||
#include "option.h"
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
void setAutoRestart(bool enabled);
|
||||
bool getAutoRestart();
|
||||
void setAutoRestart(bool enabled)
|
||||
{
|
||||
isAutoRestart = enabled;
|
||||
}
|
||||
|
||||
void setAutoChangeFirstMove(bool enabled);
|
||||
bool getAutoChangeFirstMove();
|
||||
bool getAutoRestart()
|
||||
{
|
||||
return isAutoRestart;
|
||||
}
|
||||
|
||||
void setResignIfMostLose(bool enabled);
|
||||
bool getResignIfMostLose();
|
||||
void setAutoChangeFirstMove(bool enabled)
|
||||
{
|
||||
isAutoChangeFirstMove = enabled;
|
||||
}
|
||||
|
||||
void setRandomMoveEnabled(bool enabled);
|
||||
bool getRandomMoveEnabled();
|
||||
bool getAutoChangeFirstMove()
|
||||
{
|
||||
return isAutoChangeFirstMove;
|
||||
}
|
||||
|
||||
void setLearnEndgameEnabled(bool enabled);
|
||||
bool getLearnEndgameEnabled();
|
||||
void setResignIfMostLose(bool enabled)
|
||||
{
|
||||
resignIfMostLose = enabled;
|
||||
}
|
||||
|
||||
void setIDSEnabled(bool enabled);
|
||||
bool getIDSEnabled();
|
||||
bool getResignIfMostLose()
|
||||
{
|
||||
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
|
||||
void setDepthExtension(bool enabled);
|
||||
bool getDepthExtension();
|
||||
|
||||
void setDepthExtension(bool enabled)
|
||||
{
|
||||
depthExtension = enabled;
|
||||
}
|
||||
|
||||
bool getDepthExtension()
|
||||
{
|
||||
return depthExtension;
|
||||
}
|
||||
|
||||
// OpeningBook
|
||||
void setOpeningBook(bool enabled);
|
||||
bool getOpeningBook();
|
||||
|
||||
void setOpeningBook(bool enabled)
|
||||
{
|
||||
openingBook = enabled;
|
||||
}
|
||||
|
||||
bool getOpeningBook()
|
||||
{
|
||||
return openingBook;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -56,7 +128,7 @@ private:
|
|||
bool isAutoRestart { false };
|
||||
bool isAutoChangeFirstMove { false };
|
||||
bool resignIfMostLose { false };
|
||||
bool randomMoveEnabled { true };
|
||||
bool shufflingEnabled { true };
|
||||
#ifdef ENDGAME_LEARNING_FORCE
|
||||
bool learnEndgame { true };
|
||||
#else
|
||||
|
|
|
@ -62,7 +62,7 @@ void on_threads(const Option &o)
|
|||
|
||||
void on_random_move(const Option &o)
|
||||
{
|
||||
gameOptions.setRandomMoveEnabled((bool)o);
|
||||
gameOptions.setShufflingEnabled((bool)o);
|
||||
}
|
||||
|
||||
// Rules
|
||||
|
@ -153,7 +153,7 @@ void init(OptionsMap &o)
|
|||
o["UCI_LimitStrength"] << Option(false);
|
||||
o["UCI_Elo"] << Option(1350, 1350, 2850);
|
||||
|
||||
o["RandomMove"] << Option(true, on_random_move);
|
||||
o["Shuffling"] << Option(true, on_random_move);
|
||||
|
||||
// Rules
|
||||
o["nTotalPiecesEachSide"] << Option(12, 6, 12, on_nTotalPiecesEachSide);
|
||||
|
|
|
@ -30,7 +30,7 @@ class Config {
|
|||
static bool isAutoRestart = false;
|
||||
static bool isAutoChangeFirstMove = false;
|
||||
static bool resignIfMostLose = false;
|
||||
static bool randomMoveEnabled = true;
|
||||
static bool shufflingEnabled = true;
|
||||
static bool learnEndgame = false;
|
||||
static bool idsEnabled = false;
|
||||
static bool depthExtension = true;
|
||||
|
@ -60,7 +60,7 @@ class Config {
|
|||
Config.isAutoRestart = profile['isAutoRestart'] ?? false;
|
||||
Config.isAutoChangeFirstMove = profile['isAutoChangeFirstMove'] ?? false;
|
||||
Config.resignIfMostLose = profile['resignIfMostLose'] ?? false;
|
||||
Config.randomMoveEnabled = profile['randomMoveEnabled'] ?? true;
|
||||
Config.shufflingEnabled = profile['shufflingEnabled'] ?? true;
|
||||
Config.learnEndgame = profile['learnEndgame'] ?? false;
|
||||
Config.idsEnabled = profile['idsEnabled'] ?? false;
|
||||
Config.depthExtension = profile['depthExtension'] ?? false;
|
||||
|
@ -107,7 +107,7 @@ class Config {
|
|||
profile['isAutoRestart'] = Config.isAutoRestart;
|
||||
profile['isAutoChangeFirstMove'] = Config.isAutoChangeFirstMove;
|
||||
profile['resignIfMostLose'] = Config.resignIfMostLose;
|
||||
profile['randomMoveEnabled'] = Config.randomMoveEnabled;
|
||||
profile['shufflingEnabled'] = Config.shufflingEnabled;
|
||||
profile['learnEndgame'] = Config.learnEndgame;
|
||||
profile['idsEnabled'] = Config.idsEnabled;
|
||||
profile['depthExtension'] = Config.depthExtension;
|
||||
|
|
|
@ -133,7 +133,7 @@ class NativeEngine extends AiEngine {
|
|||
}
|
||||
|
||||
Future<void> setOptions() async {
|
||||
await send('setoption name RandomMove value ${Config.randomMoveEnabled}');
|
||||
await send('setoption name Shuffling value ${Config.shufflingEnabled}');
|
||||
await send(
|
||||
'setoption name nTotalPiecesEachSide value ${Config.nTotalPiecesEachSide}');
|
||||
await send('setoption name nPiecesAtLeast value ${Config.nPiecesAtLeast}');
|
||||
|
|
|
@ -283,8 +283,8 @@
|
|||
"@resignIfMostLose": {
|
||||
"description": "AI Resign if Most Lose"
|
||||
},
|
||||
"randomMoveEnabled": "AI Random Move",
|
||||
"@randomMoveEnabled": {
|
||||
"shufflingEnabled": "AI Random Move",
|
||||
"@shufflingEnabled": {
|
||||
"description": "AI Random Move"
|
||||
},
|
||||
"learnEndgame": "Learn Endgame",
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
"isAutoRestart": "棋局结束时自动重新开局",
|
||||
"isAutoChangeFirstMove": "开局时自动交换先后手",
|
||||
"resignIfMostLose": "机器明显劣势时自动认输",
|
||||
"randomMoveEnabled": "机器随机走子",
|
||||
"shufflingEnabled": "机器随机走子",
|
||||
"learnEndgame": "残局库自学习",
|
||||
"idsEnabled": "迭代加深",
|
||||
"depthExtension": "深度扩展",
|
||||
|
|
|
@ -132,9 +132,9 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
Config.save();
|
||||
}
|
||||
|
||||
switchRandomMoveEnabled(bool value) async {
|
||||
switchShufflingEnabled(bool value) async {
|
||||
setState(() {
|
||||
Config.randomMoveEnabled = value;
|
||||
Config.shufflingEnabled = value;
|
||||
});
|
||||
|
||||
Config.save();
|
||||
|
@ -667,10 +667,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
_buildDivider(),
|
||||
SwitchListTile(
|
||||
activeColor: UIColors.primaryColor,
|
||||
value: Config.randomMoveEnabled,
|
||||
value: Config.shufflingEnabled,
|
||||
title:
|
||||
Text(S.of(context).randomMoveEnabled, style: itemStyle),
|
||||
onChanged: switchRandomMoveEnabled,
|
||||
Text(S.of(context).shufflingEnabled, style: itemStyle),
|
||||
onChanged: switchShufflingEnabled,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -549,9 +549,9 @@ void Game::setAutoChangeFirstMove(bool 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)
|
||||
|
|
|
@ -239,7 +239,7 @@ public slots:
|
|||
void setAutoChangeFirstMove(bool enabled = false);
|
||||
|
||||
// AI 是否随机走子
|
||||
void setRandomMove(bool enabled);
|
||||
void setShuffling(bool enabled);
|
||||
|
||||
// AI 是否记录残局库
|
||||
void setLearnEndgame(bool enabled);
|
||||
|
|
|
@ -235,8 +235,8 @@ void MillGameWindow::initialize()
|
|||
connect(ui.actionAutoChangeFirstMove_C, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setAutoChangeFirstMove(bool)));
|
||||
|
||||
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setRandomMove(bool)));
|
||||
connect(ui.actionShuffling_R, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setShuffling(bool)));
|
||||
|
||||
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
|
||||
game, SLOT(setLearnEndgame(bool)));
|
||||
|
|
Loading…
Reference in New Issue