mcts: 新增分段线性分布相关代码

使用 MCTS_PLD 宏控制,暂不启用。
若启用,棋力反而比均匀分布弱。
This commit is contained in:
Calcitem 2020-03-06 00:17:10 +08:00
parent 9014a4d949
commit 7da2d0416c
2 changed files with 29 additions and 0 deletions

View File

@ -37,6 +37,8 @@
#define ALPHABETA_AI
//#define MCTS_AI
//#define MCTS_PLD
#ifdef TEST_MODE
#define DONOT_PLAY_SOUND
#endif // TEST_MODE

View File

@ -24,8 +24,21 @@ void Game::doRandomMove(Node *node, mt19937_64 *engine)
generateMoves(moves);
int movesSize = moves.size();
#ifdef MCTS_PLD
int i = 0;
if (movesSize > 1)
{
std::vector<int> v{ 0, movesSize - 1 }; // Sample values
std::vector<int> w{ movesSize - 1, 0 }; // Weights for the samples
std::piecewise_linear_distribution<> index{ std::begin(v), std::end(v), std::begin(w) };
i = (int)index(*engine);
}
#else
uniform_int_distribution<int> index(0, movesSize - 1);
auto i = index(*engine);
#endif // MCTS_PLD
move_t m = moves[i];
doMove(m);
}
@ -110,9 +123,23 @@ move_t Node::getUntriedMove(RandomEngine *engine) const
{
assert(!moves.empty());
#ifdef MCTS_PLD
int i = 0;
int movesSize = moves.size();
if (movesSize > 1) {
std::vector<int> v{ 0, movesSize - 1 }; // Sample values
std::vector<int> w{ movesSize - 1, 0 }; // Weights for the samples
std::piecewise_linear_distribution<> index{ std::begin(v), std::end(v), std::begin(w) };
i = (int)index(*engine);
}
return moves[i];
#else
uniform_int_distribution<size_t> movesDistribution(0, moves.size() - 1);
return moves[movesDistribution(*engine)];
#endif // #ifdef MCTS_PLD
}
bool Node::hasChildren() const