I just need to clarify some points, i needed to modify various part of the code provided at mcts.ai since it could lead to exceptions and other bad behaviours.
1) How are handled "final" nodes? With final i mean nodes that contains a win or a loss. The algorithm will try to expand them, but they can't be expanded as the simulated player can't do any move(since he lost and it is no more present on the board)
cur.expand();
TreeNode newNode = cur.select();
visited.add(newNode);
double value = rollOut(newNode);
become
cur.expand();
double value;
if(!cur.isLeaf()) //the node is not a final state, the player can do a move and is not dead
{
TreeNode newNode = cur.select();
EvaluationContext.getCurrentBoard().apply_move(newNode.getMove());
EvaluationContext.getCurrentBoard().nextPlayer();
visited.add(newNode);
value = rollOut(newNode);
}
else
{
value = EvaluationContext.getCurrentBoard().playerWins(EvaluationContext.getCurrentBoard().getCurrentPlayerID()) ? 1:0;
}
where
public void expand() {
children = new TreeNode[nActions];
for (int i=0; i<nActions; i++) {
children = new TreeNode();
}
}
become
public void expand() {
if(!isLeaf())
return;
List<Move> moves = EvaluationContext.getCurrentBoard().generate_moves();
if(moves.size() == 0)
return;
children = new TreeNode[moves.size()];
int i = 0;
for (Move move : moves) {
children[i++] = new TreeNode(move, EvaluationContext);
}
}
so each time it will continue to simulate them even if it is not needed..
2) I have my "real" board (the one on which the player plays and interact) and a board for each Ai simulating thread, and i keep this 2 in sync updating the real board with the ai moves and updating the ai ones with player moves. Each thread have also a board on which it plays simulations (since simulations change the board state). deepCopying the board or generating a new one from the real one (the implementations are different, ai board is by far more memory efficient) takes quite the same time. I'm facing sync problems (i blame myself for not commintting when all worked, i changed a few things and now i'm not no more able to sync it lots of debug time is waiting for me), i'm already planning to solve it anywais, but is it wrong to generate ai boards from real board instead of keeping them in sync?