protected override MCTreeSearchNode <GameState, GameAction> SelectExpanded(MCTreeSearchNode <GameState, GameAction> node) { // return node.Children.Values.MaxItem(child => child.SelectionRating); return(node.Children.First().Value); }
public MCTreeSearchNode(MCTreeSearchNode <TState, TAction> parent, TState gameState, TAction lastAction) : base(parent, gameState, lastAction) { }
protected override MCTreeSearchNode <GameState, GameAction> CreateNode(MCTreeSearchNode <GameState, GameAction> parentNode, GameState gameState, GameAction action) { return(new MCTreeSearchNode <GameState, GameAction>(parentNode, gameState, action)); }
protected override double Playout(MCTreeSearchNode <GameState, GameAction> leafNode, out IEnumerable <Tuple <GameAction, GameState> > path) { throw new NotImplementedException(); }
protected override double Playout(MCTreeSearchNode <GameState, GameAction> leafNode) { return(Network.Evaluate(leafNode.State)[leafNode.State.CurrentPlayer]); }
public VNetworkMCTreeSearchNavigator(VNetworkBasedMCTreeSearch mcts, MCTreeSearchNode <GameState, GameAction> rootNode) : base(mcts, TicTacToeGame.Instance, rootNode) { }
public static string ToString(MCTreeSearchNode <GameState, GameAction> node) { string[] lines = node.State.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); for (ushort y = 0; y < 3; y++) { lines[y] += " "; for (ushort x = 0; x < 3; x++) { var action = new GameAction(new BoardCoordinates(x, y)); if (node.Children.TryGetValue(action, out var child)) { lines[y] += $" {child.Visits,3}"; } else { lines[y] += $" ---"; } } } for (ushort y = 0; y < 3; y++) { lines[y] += " "; for (ushort x = 0; x < 3; x++) { var action = new GameAction(new BoardCoordinates(x, y)); if (node.Children.TryGetValue(action, out var child)) { lines[y] += $" {child.Value,5:f2}"; } else { lines[y] += $" -----"; } } } double wonX; double wonO; if (node.State.CurrentPlayer.IsCross) { wonX = node.Children.Select(p => p.Value.Value / p.Value.Visits).Max(); wonO = 1.0 - node.Children.Select(p => p.Value.Value / p.Value.Visits).Min(); } else { wonX = 1.0 - node.Children.Select(p => p.Value.Value / p.Value.Visits).Min(); wonO = node.Children.Select(p => p.Value.Value / p.Value.Visits).Max(); } lines[0] += $" X: {wonX}"; lines[1] += $" O: {wonO}"; return(string.Join(Environment.NewLine, lines)); }