some fixes
This commit is contained in:
parent
700b8cffef
commit
ec89afcb7e
1 changed files with 13 additions and 11 deletions
|
@ -231,20 +231,18 @@ void bt_t::mcts_expansion(bt_node_t *root) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_t::mcts_simulation(bt_node_t *node) {
|
bool bt_t::mcts_simulation(bt_node_t *node) {
|
||||||
bt_t b_copy = *this;
|
int me = (turn % 2 == 0) ? WHITE : BLACK;
|
||||||
|
|
||||||
int me = (b_copy.turn % 2 == 0) ? WHITE : BLACK;
|
|
||||||
|
|
||||||
// try to play my move
|
// try to play my move
|
||||||
b_copy.play(node->move);
|
play(node->move);
|
||||||
|
|
||||||
// then play randomly 'til the game is over
|
// then play randomly 'til the game is over
|
||||||
while (b_copy.endgame() != EMPTY) {
|
while (endgame() != EMPTY) {
|
||||||
b_copy.play(b_copy.get_rand_move());
|
play(get_rand_move());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if i won
|
// if i won
|
||||||
return ((b_copy.turn % 2 == 0) ? WHITE : BLACK == me) ? true : false;
|
return ((turn % 2 == 0) ? WHITE : BLACK == me) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_t::mcts_back_propagation(bt_node_t *simulated, bool won) {
|
void bt_t::mcts_back_propagation(bt_node_t *simulated, bool won) {
|
||||||
|
@ -273,14 +271,17 @@ bt_move_t bt_t::get_mcts_move(double max_time) {
|
||||||
|
|
||||||
// MCTS
|
// MCTS
|
||||||
while (elapsed.count() < max_time) {
|
while (elapsed.count() < max_time) {
|
||||||
|
// Copy board
|
||||||
|
bt_t copy_b = *this;
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
auto selected = mcts_selection(tree);
|
auto selected = copy_b.mcts_selection(tree);
|
||||||
|
|
||||||
// Expansion
|
// Expansion
|
||||||
mcts_expansion(selected);
|
copy_b.mcts_expansion(selected);
|
||||||
|
|
||||||
// Simulation
|
// Simulation
|
||||||
bool is_win = mcts_simulation(selected);
|
bool is_win = copy_b.mcts_simulation(selected);
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
mcts_back_propagation(selected, is_win);
|
mcts_back_propagation(selected, is_win);
|
||||||
|
@ -291,9 +292,10 @@ bt_move_t bt_t::get_mcts_move(double max_time) {
|
||||||
|
|
||||||
// Select best move
|
// Select best move
|
||||||
bt_node_t *best_node = nullptr;
|
bt_node_t *best_node = nullptr;
|
||||||
int best_score = -1;
|
int best_score = 0;
|
||||||
for (auto i : tree->children) {
|
for (auto i : tree->children) {
|
||||||
if (i->nb_simulation > best_score) {
|
if (i->nb_simulation > best_score) {
|
||||||
|
best_score = i->nb_simulation;
|
||||||
best_node = i;
|
best_node = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue