public Node CreateNode(IStateProtocol state) { var action = state.GetLastAction(); var playerIndex = state.GetLastPlayerIndex(); return(Node.CreateRootNode(playerIndex, action, state)); }
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(); }
/// <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(); }
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); }
public StateTree(IStateProtocol state) { _root = new StateLeaf(state); _currentLeaf = _root; }
private void BackPropagation(Node expandedNode, IStateProtocol finalState) { _backPropagationStrategy.Update(expandedNode, finalState); }
private Node(NodeBase parent, uint playerIndex, IActionProtocol action, IStateProtocol state) : base(parent, playerIndex) { Action = action; State = state; }
public static Node CreateNode(Node parent, uint playerIndex, IActionProtocol action, IStateProtocol state) { return(new Node(parent, playerIndex, action, state)); }
public static Node CreateRootNode(uint playerIndex, IActionProtocol action, IStateProtocol state) { return(new Node(null, playerIndex, action, state)); }