예제 #1
0
 protected override MCTreeSearchNode <GameState, GameAction> SelectExpanded(MCTreeSearchNode <GameState, GameAction> node)
 {
     // return node.Children.Values.MaxItem(child => child.SelectionRating);
     return(node.Children.First().Value);
 }
예제 #2
0
 public MCTreeSearchNode(MCTreeSearchNode <TState, TAction> parent, TState gameState, TAction lastAction) : base(parent, gameState, lastAction)
 {
 }
예제 #3
0
 protected override MCTreeSearchNode <GameState, GameAction> CreateNode(MCTreeSearchNode <GameState, GameAction> parentNode, GameState gameState, GameAction action)
 {
     return(new MCTreeSearchNode <GameState, GameAction>(parentNode, gameState, action));
 }
예제 #4
0
 protected override double Playout(MCTreeSearchNode <GameState, GameAction> leafNode, out IEnumerable <Tuple <GameAction, GameState> > path)
 {
     throw new NotImplementedException();
 }
예제 #5
0
 protected override double Playout(MCTreeSearchNode <GameState, GameAction> leafNode)
 {
     return(Network.Evaluate(leafNode.State)[leafNode.State.CurrentPlayer]);
 }
예제 #6
0
 public VNetworkMCTreeSearchNavigator(VNetworkBasedMCTreeSearch mcts, MCTreeSearchNode <GameState, GameAction> rootNode) : base(mcts, TicTacToeGame.Instance, rootNode)
 {
 }
예제 #7
0
        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));
        }