コード例 #1
0
        public void Expand(IPatchworkServerClient client)
        {
#if DEBUG
            if (Children.Count != 0)
            {
                throw new Exception("Cannot expand an already expanded node");
            }
            if (IsGameEnd)
            {
                throw new Exception("Cannot expand a GameEnd node");
            }
#endif

            //Advance
            {
                var node = MonteCarloTreeSearchAlphaZero.NodePool.Value.Get();

                State.CloneTo(node.State);
                node.State.Fidelity = SimulationFidelity.NoPiecePlacing;
                node.State.PerformAdvanceMove();

                node.Parent            = this;
                node.PieceToPurchase   = null;
                node.NetworkChildIndex = 0;
                Children.Add(node);
            }

            //Purchase
            for (var i = 0; i < 3; i++)
            {
                //This cares if they can actually place the piece only when expanding the root node
                if (Helpers.ActivePlayerCanPurchasePiece(State, Helpers.GetNextPiece(State, i)))
                {
                    var node = MonteCarloTreeSearchAlphaZero.NodePool.Value.Get();

                    State.CloneTo(node.State);
                    node.State.Fidelity = SimulationFidelity.NoPiecePlacing;
                    var pieceIndex = node.State.NextPieceIndex + i;
                    node.State.PerformPurchasePiece(pieceIndex);

                    node.Parent            = this;
                    node.PieceToPurchase   = pieceIndex;
                    node.NetworkChildIndex = i + 1;
                    Children.Add(node);
                }
            }

            //Evaluate the networks of our children
            var req = new EvaluateRequest();
            for (var i = 0; i < Children.Count; i++)
            {
                req.State.Add(GameStateFactory.CreateGameState(Children[i].State));
            }
            var res = client.Evaluate(req);
            for (var i = 0; i < Children.Count; i++)
            {
                Children[i].NetworkResult = res.Evaluations[i];
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: danzel/PatchworkSim
 public Program(IPatchworkServerClient client)
 {
     _client = client;
     _ai     = new MoveOnlyMonteCarloTreeSearchAlphaZeroMoveMaker(_client, 100);
     _opp    = new MoveOnlyMonteCarloTreeSearchMoveMaker(20);
 }
コード例 #3
0
 public MonteCarloTreeSearchAlphaZero(IPatchworkServerClient client, int iterations)
 {
     _client    = client;
     Iterations = iterations;
 }