UXWFBRYCNZIYOGP6MGMT5KGY6NFS566QDDJJZIP3YJODQI5QIHDAC
AI26KKCYBXQDE6DUM6FWLFSSCTQ6QJCVHATZSCXZQCQIC2EZVAXQC
5H3MOKBPGSOSPZW2VIGCWZC5DUTTMJ7PYRERELC7ANHMNPGM3JEQC
KN2H7F5CIEAKA5XQ4NQXAZV25VNZ6AV7Q3M2FVOX2JF7JKMDFDCAC
LT2L5OITYEO7I6P5WA35E5FJ5AUGPMLFYYKPVI4WLBIH65AINECQC
U3JHTSEMJLXNKOMAQJQPZKRW6GRPHYLG6DK53XVADIETKVCS2MFQC
WN26XTZ7IZN4WNAVXZ4NKD4CXIU7IC6V7BFNVICNMQUVHBZXBNCAC
O325HSUUTHFZ2BM23FLJVHZKYV742BLUWCDYSYDMIEAZRU6RRO7AC
class testNNPV implements NeuralNetworkPolicyAndValue<int?, TicTacToePlayer> {
@override
double getCurrentValue(GameState<int?, TicTacToePlayer> game) {
// TODO: implement getCurrentValue
throw UnimplementedError();
}
@override
Map<int?, double> getMoveProbabilities(
GameState<int?, TicTacToePlayer?> game) {
// pretend that the neural net thinks corner moves are good first moves
if (game.getMoves().length == 9) {
return <int?, double>{
0: 0.25,
1: 0,
2: 0.25,
3: 0,
4: 0,
5: 0,
6: 0.25,
7: 0,
8: 0.25,
};
}
return {};
}
}
test('visits neural net prescribed nodes more frequently', () {
var o = TicTacToePlayer.O;
var x = TicTacToePlayer.X;
var e;
var ttgg = TicTacToeGame(
board: [e, e, e, e, e, e, e, e, e], currentPlayer: o, scores: {});
MCTSResult<int?, TicTacToePlayer> result = MCTS(gameState: ttgg)
.getSimulationResult(iterations: 100, nnpv: testNNPV());
expect(result.root!.children.length, equals(9));
expect(result.maxDepth, equals(9));
Map<int?, int> visits = {};
result.root!.children.forEach((key, value) {
visits[value.move] = value.visits;
});
print(visits);
ttgg = TicTacToeGame(
board: [e, e, e, e, e, e, e, e, e], currentPlayer: o, scores: {});
result = MCTS(gameState: ttgg).getSimulationResult(iterations: 100);
result.root!.children.forEach((key, value) {
visits[value.move] = value.visits;
});
print(visits);
});
return b.value
.ucb1(player, maxScore)
.compareTo(a.value.ucb1(player, maxScore));
double bScore = b.value
.ucb1(player, maxScore, _moveProbabilitiesFromNN[b.key] ?? 1.0);
double aScore = a.value
.ucb1(player, maxScore, _moveProbabilitiesFromNN[a.key] ?? 1.0);
return bScore.compareTo(aScore);
MCTSResult<MoveType, PlayerType> getSimulationResult(
{Node<MoveType, PlayerType>? initialRootNode,
int iterations = 100,
double? maxSeconds,
List<MoveType>? actualMoves}) {
MCTSResult<MoveType, PlayerType> getSimulationResult({
Node<MoveType, PlayerType>? initialRootNode,
int iterations = 100,
double? maxSeconds,
List<MoveType>? actualMoves,
NeuralNetworkPolicyAndValue? nnpv,
int? useValueAfterDepth,
double? valueThreshold,
}) {
gameState: gameState,
parent: null,
move: null,
c: c,
backpropObserver: backpropObserver);
gameState: gameState,
parent: null,
move: null,
c: c,
backpropObserver: backpropObserver,
nnpv: nnpv,
useValueAfterDepth: useValueAfterDepth,
valueThreshold: valueThreshold,
);
if (currentNode.useValueAfterDepth != null &&
currentNode.depth >= currentNode.useValueAfterDepth!) {
if (currentNode.nnpv!.getCurrentValue(currentNode.gameState!) >=
currentNode.valueThreshold!) {
currentNode.gameState!.winner =
currentNode.gameState!.currentPlayer;
} else {
currentNode.gameState!.winner = null;
}
break t;
}