Beispiel #1
0
        private void RemoveWorker(SearchWorker worker)
        {
            lock (_workersLock)
            {
                var key = _workers.Single(x => x.Value == worker).Key;
                _workers.Remove(key);
            }

            Interlocked.Add(ref _subtreesPrunned, worker.SubTreesPrunned);
        }
Beispiel #2
0
        private SearchWorker CreateWorker(InnerResult rootResult, Game game)
        {
            var worker = new SearchWorker(this, rootResult, game, _searchResults);

            lock (_workersLock)
            {
                _workers.Add(worker.Id, worker);
                _numWorkersCreated++;
            }

            return(worker);
        }
Beispiel #3
0
        public Task EvaluateBranch(SearchWorker worker, ISearchNode rootNode, InnerResult rootResult, int moveIndex)
        {
            var shouldCreateNewWorker = IsItFeasibleToCreateNewWorker(rootNode, moveIndex);

            if (shouldCreateNewWorker)
            {
                rootNode = new CopyService().CopyRoot(rootNode);
                worker   = CreateWorker(rootResult, rootNode.Game);

                var task = Task.Factory.StartNew(() =>
                {
                    worker.EvaluateBranch(moveIndex, rootNode, rootResult);
                    RemoveWorker(worker);
                }, TaskCreationOptions.PreferFairness);

                return(task);
            }
            worker.EvaluateBranch(moveIndex, rootNode, rootResult);
            return(null);
        }
Beispiel #4
0
        public Task EvaluateBranch(SearchWorker worker, ISearchNode rootNode, InnerResult rootResult, int moveIndex)
        {
            var shouldCreateNewWorker = IsItFeasibleToCreateNewWorker(rootNode, moveIndex);

              if (shouldCreateNewWorker)
              {
            rootNode = new CopyService().CopyRoot(rootNode);
            worker = CreateWorker(rootResult, rootNode.Game);

            var task = Task.Factory.StartNew(() =>
              {
            worker.EvaluateBranch(moveIndex, rootNode, rootResult);
            RemoveWorker(worker);
              }, TaskCreationOptions.PreferFairness);

            return task;
              }
              worker.EvaluateBranch(moveIndex, rootNode, rootResult);
              return null;
        }
Beispiel #5
0
        private void RemoveWorker(SearchWorker worker)
        {
            lock (_workersLock)
              {
            var key = _workers.Single(x => x.Value == worker).Key;
            _workers.Remove(key);
              }

              Interlocked.Add(ref _subtreesPrunned, worker.SubTreesPrunned);
        }
Beispiel #6
0
        private SearchWorker CreateWorker(InnerResult rootResult, Game game)
        {
            var worker = new SearchWorker(this, rootResult, game, _searchResults);

              lock (_workersLock)
              {
            _workers.Add(worker.Id, worker);
            _numWorkersCreated++;
              }

              return worker;
        }