option: 新增残局库自学习的菜单并默认打开
This commit is contained in:
parent
75ea71b3ea
commit
d65acac9a5
|
@ -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>必败时认输(&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>残局自学习
|
||||
(&E)</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -52,3 +52,13 @@ bool Options::getRandomMoveEnabled()
|
|||
{
|
||||
return randomMoveEnabled;
|
||||
}
|
||||
|
||||
void Options::setLearnEndgameEnabled(bool enabled)
|
||||
{
|
||||
learnEndgame = enabled;
|
||||
}
|
||||
|
||||
bool Options::getLearnEndgameEnabled()
|
||||
{
|
||||
return learnEndgame;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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号规则,即“打三棋”
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -153,6 +153,9 @@ public slots:
|
|||
// AI 是否随机走子
|
||||
void setRandomMove(bool enabled);
|
||||
|
||||
// AI 是否记录残局库
|
||||
void setLearnEndgame(bool enabled);
|
||||
|
||||
// 上下翻转
|
||||
void flip();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue