最优招法随机选最优的两步其中一步

This commit is contained in:
CalciteM Team 2019-07-04 00:12:05 +08:00
parent 619217a5eb
commit 1795357070
2 changed files with 37 additions and 10 deletions

View File

@ -5,6 +5,8 @@
//#define DEAL_WITH_HORIZON_EFFECT
#define RANDOM_BEST_MOVE
#ifdef DEBUG
#define DONOT_PLAY_SOUND
#define DEBUG_AB_TREE
@ -14,8 +16,7 @@
//#define AB_RANDOM_SORT_CHILDREN
#endif
#define AB_RANDOM_SORT_CHILDREN
#define DONOT_PLAY_SOUND
//#define DONOT_PLAY_SOUND
#ifdef DEBUG
#define GAME_PLACING_FIXED_DEPTH 4

View File

@ -650,8 +650,12 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
return node->value;
}
const char *NineChessAi_ab::bestMove()
const char* NineChessAi_ab::bestMove()
{
vector<Node*> bestMoves;
size_t retIndex = 0;
size_t bestMovesSize = 0;
if ((rootNode->children).size() == 0)
return "error!";
@ -668,26 +672,48 @@ const char *NineChessAi_ab::bestMove()
qDebug() << "29 ----- 28 ----- 27";
qDebug() << "";
int i = 0;
string moves = "";
for (auto child : rootNode->children) {
if (child->value == rootNode->value)
qDebug() << "[" << child->move << "] " << move2string(child->move) << " : " << child->value << "*";
qDebug("[%.2d] %d\t%s\t%d *", i, child->move, move2string(child->move), child->value);
else
qDebug() << "[" << child->move << "] " << move2string(child->move) << " : " << child->value;
qDebug("[%.2d] %d\t%s\t%d", i, child->move, move2string(child->move), child->value);
i++;
}
for (auto child : rootNode->children) {
if (child->value == rootNode->value) {
qDebug() << "Evaluated: " << evaluatedNodeCount << "/" << nodeCount << " = " << evaluatedNodeCount * 100 / nodeCount << "%";
nodeCount = 0;
evaluatedNodeCount = 0;
return move2string(child->move);
bestMoves.push_back(child);
}
}
return "error!";
qDebug() << "Evaluated: " << evaluatedNodeCount << "/" << nodeCount << " = "
<< evaluatedNodeCount * 100 / nodeCount << "%";
nodeCount = 0;
evaluatedNodeCount = 0;
bestMovesSize = bestMoves.size();
if (bestMovesSize == 0) {
return "error!";
}
#ifdef RANDOM_BEST_MOVE
time_t time0 = time(0);
retIndex = bestMovesSize > 1 ? time0 % 2 : 0;
#else
retIndex = 0;
#endif
qDebug() << "Return" << retIndex << "of" << bestMovesSize << "results" << "(" << time0 << ")";
return move2string(bestMoves[retIndex]->move);
}
const char *NineChessAi_ab::move2string(int move)
{
int c, p;