Esempio n. 1
0
        private bool ExecutePendingDecisions(Func <bool> shouldContinue)
        {
            var should = false;

            while (shouldContinue())
            {
                if (CurrentHandler == null || CurrentHandler.HasCompleted)
                {
                    if (_decisionQueue.Count == 0)
                    {
                        should = true;
                        break;
                    }

                    var decision = _decisionQueue.Dequeue();
                    CurrentHandler = decision.CreateHandler(Game);
                }

                // execute is called multiple times, during
                // search tree generation
                CurrentHandler.Execute();
            }

            return(should);
        }
Esempio n. 2
0
        private bool ExecutePendingDecisions(Func <bool> shouldContinue)
        {
            var resultsToSave = new List <IDecisionHandler>();

            var should = false;

            while (shouldContinue())
            {
                if (CurrentHandler == null || CurrentHandler.HasCompleted)
                {
                    if (_decisionQueue.Count == 0)
                    {
                        should = true;
                        break;
                    }

                    var decision = _decisionQueue.Dequeue();
                    CurrentHandler = decision.CreateHandler(Game);
                }

                CurrentHandler.Execute();
                resultsToSave.Add(CurrentHandler);
            }

            // it's important to save the results only when decision queue is empty
            // if its not the playback will not work, because the decisions not yet
            // executed, can not be saved properly
            foreach (var decision in resultsToSave)
            {
                decision.SaveDecisionResults();
            }

            return(should);
        }
Esempio n. 3
0
        internal void Work()
        {
            WorkType   = Board.WorkTypes.Nothing;
            OutputType = Board.OutputTypes.Nothing;
            Output     = null;

            if (_currentDecision == null && _decisionQueue.Count > 0)
            {
                _currentDecision = _decisionQueue.Dequeue();
            }
            if (_currentSummons == null && _summonsQueue.Count > 0)
            {
                _currentSummons = _summonsQueue.Dequeue();
            }

            if (_currentDecision != null)
            {
                WorkType = Board.WorkTypes.Decision;
                _currentDecision.DoWork();
                if (_currentDecision.WorkHours == _decisionHours)
                {
                    OutputType       = Board.OutputTypes.Decision;
                    Output           = _currentDecision.Copy();
                    _currentDecision = null;
                }
            }
            else if (_currentSummons != null)
            {
                WorkType = Board.WorkTypes.Summons;
                _currentSummons.DoWork();
                if (_currentSummons.WorkHours == _summonsHours)
                {
                    OutputType      = Board.OutputTypes.Summons;
                    Output          = _currentSummons.Copy();
                    _currentSummons = null;
                }
            }
        }