示例#1
0
        public Node CreateNode(IStateProtocol state)
        {
            var action      = state.GetLastAction();
            var playerIndex = state.GetLastPlayerIndex();

            return(Node.CreateRootNode(playerIndex, action, state));
        }
示例#2
0
        public void Update(Node node, IStateProtocol finalState)
        {
            var rewardDifferences = new double[MAX_PLAYER_COUNT];

            for (uint i = 0; i < finalState.PlayerCount; i++)
            {
                var reward            = finalState.GetReward(i);
                var otherPlayerReward = double.MinValue;
                for (uint j = 0; j < finalState.PlayerCount; j++)
                {
                    if (i != j)
                    {
                        otherPlayerReward = Math.Max(otherPlayerReward, finalState.GetReward(j));
                    }
                }

                rewardDifferences[i] = Normalizer.Normalize(reward - otherPlayerReward);
            }

            var currentNode = node;

            while (!currentNode.IsRoot)
            {
                var playerIndex = currentNode.PlayerIndex;
                currentNode.AddReward(rewardDifferences[playerIndex]);
                currentNode.IncreaseVisitCount();
                currentNode = currentNode.Parent;
            }

            // Root node
            currentNode.IncreaseVisitCount();
        }
示例#3
0
        /// <summary>
        /// Tính toán hành động tiếp theo cho State này
        /// </summary>
        public void ComputeMove(IStateProtocol state)
        {
            if (IsComputing)
            {
                return;
            }

            _beginPoint = DateTime.Now.Millisecond;
            Func <mcts.IActionProtocol> act = () => {
                return(_callback?.Invoke(state));
            };

            _future = new Task <mcts.IActionProtocol>(act);
            _future.Start();
        }
示例#4
0
        public void Update(Node node, IStateProtocol finalState)
        {
            var rewards = new double[MAX_PLAYER_COUNT];

            for (uint i = 0; i < finalState.PlayerCount; i++)
            {
                rewards[i] = Normalizer.Normalize(finalState.GetReward(i));
            }

            var currentNode = node;

            while (!currentNode.IsRoot)
            {
                var playerIndex = currentNode.PlayerIndex;
                currentNode.AddReward(rewards[playerIndex]);
                currentNode.IncreaseVisitCount();
                currentNode = currentNode.Parent;
            }

            // Root node
            currentNode.IncreaseVisitCount();
        }
 public IActionProtocol ComputeAction(IStateProtocol state, Action <string> logger)
 {
     // FIXME: chưa làm
     return(null);
 }
示例#6
0
 public StateTree(IStateProtocol state)
 {
     _root        = new StateLeaf(state);
     _currentLeaf = _root;
 }
示例#7
0
 private void BackPropagation(Node expandedNode, IStateProtocol finalState)
 {
     _backPropagationStrategy.Update(expandedNode, finalState);
 }
示例#8
0
 private Node(NodeBase parent, uint playerIndex, IActionProtocol action, IStateProtocol state) : base(parent, playerIndex)
 {
     Action = action;
     State  = state;
 }
示例#9
0
 public static Node CreateNode(Node parent, uint playerIndex, IActionProtocol action, IStateProtocol state)
 {
     return(new Node(parent, playerIndex, action, state));
 }
示例#10
0
 public static Node CreateRootNode(uint playerIndex, IActionProtocol action, IStateProtocol state)
 {
     return(new Node(null, playerIndex, action, state));
 }