option: 新增残局库自学习的菜单并默认打开

This commit is contained in:
CalciteM Team 2019-09-20 01:34:58 +08:00
parent 75ea71b3ea
commit d65acac9a5
8 changed files with 51 additions and 5 deletions

View File

@ -227,7 +227,7 @@
<x>0</x>
<y>0</y>
<width>491</width>
<height>23</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menu_F">
@ -294,6 +294,7 @@
<addaction name="actionGiveUpIfMostLose_G"/>
<addaction name="actionAutoRestart_A"/>
<addaction name="actionRandomMove_R"/>
<addaction name="actionLearnEndgame_E"/>
</widget>
<widget class="QMenu" name="menu_H">
<property name="title">
@ -1125,6 +1126,18 @@
<string>必败时认输(&amp;G)</string>
</property>
</action>
<action name="actionLearnEndgame_E">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>残局自学习
(&amp;E)</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View File

@ -415,7 +415,8 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta, Node *no
// 检索残局库
Endgame endgame;
if (findEndgameHash(hash, endgame)) {
if (options.getLearnEndgameEnabled() &&
findEndgameHash(hash, endgame)) {
switch (endgame.type) {
case ENDGAME_PLAYER_1_WIN:
node->value = VALUE_WIN;
@ -693,7 +694,7 @@ const char* AIAlgorithm::bestMove()
#ifdef ENDGAME_LEARNING
// 检查是否明显劣势
if (1) { // TODO: 替换为开关选项
if (options.getLearnEndgameEnabled()) {
bool isMostWeak = true; // 是否明显劣势
for (auto child : root->children) {

View File

@ -52,3 +52,13 @@ bool Options::getRandomMoveEnabled()
{
return randomMoveEnabled;
}
void Options::setLearnEndgameEnabled(bool enabled)
{
learnEndgame = enabled;
}
bool Options::getLearnEndgameEnabled()
{
return learnEndgame;
}

View File

@ -35,6 +35,9 @@ public:
void setRandomMoveEnabled(bool enabled);
bool getRandomMoveEnabled();
void setLearnEndgameEnabled(bool enabled);
bool getLearnEndgameEnabled();
protected:
private:
@ -46,6 +49,9 @@ private:
// AI 是否随机走子
bool randomMoveEnabled { true };
// AI 是否生成残局库
bool learnEndgame { true };
};
extern Options options;

View File

@ -24,6 +24,7 @@
#include "search.h"
#include "movegen.h"
#include "player.h"
#include "option.h"
#include "zobrist.h"
Game::Game()
@ -36,7 +37,9 @@ Game::Game()
#ifdef ENDGAME_LEARNING
// TODO: 残局文件被加载了多次
AIAlgorithm::loadEndgameFileToHashMap();
if (options.getLearnEndgameEnabled()) {
AIAlgorithm::loadEndgameFileToHashMap();
}
#endif
// 默认选择第1号规则即“打三棋”

View File

@ -97,7 +97,9 @@ GameController::~GameController()
delete ai[2];
#ifdef ENDGAME_LEARNING
AIAlgorithm::recordEndgameHashMapToFile();
if (options.getLearnEndgameEnabled()) {
AIAlgorithm::recordEndgameHashMapToFile();
}
#endif /* ENDGAME_LEARNING */
}
@ -380,6 +382,11 @@ void GameController::setRandomMove(bool enabled)
options.setRandomMoveEnabled(enabled);
}
void GameController::setLearnEndgame(bool enabled)
{
options.setLearnEndgameEnabled(enabled);
}
// 上下翻转
void GameController::flip()
{

View File

@ -153,6 +153,9 @@ public slots:
// AI 是否随机走子
void setRandomMove(bool enabled);
// AI 是否记录残局库
void setLearnEndgame(bool enabled);
// 上下翻转
void flip();

View File

@ -214,6 +214,9 @@ void MillGameWindow::initialize()
connect(ui.actionRandomMove_R, SIGNAL(toggled(bool)),
game, SLOT(setRandomMove(bool)));
connect(ui.actionLearnEndgame_E, SIGNAL(toggled(bool)),
game, SLOT(setLearnEndgame(bool)));
// 视图上下翻转
connect(ui.actionFlip_F, &QAction::triggered,
game, &GameController::flip);