Пример #1
0
        public bool CheckTransition(Transition transition)
        {
            var condition = _parameterIndexToUse
                            .Where(v => v.Value)
                            .Select(v => v.Key)
                            .All(index => CheckModification(_parameterIndexToValue[index], transition.modifiers[index]));

            var passed = (transition.passCount == 0) ||
                         !(_transitionCounts.ContainsKey(transition.id) && (_transitionCounts[transition.id] >= transition.passCount));

            if (passed && condition && (transition.globalCondition.Length == 0 ||
                                        (int)Token.eval(transition.globalCondition, _parameterIndexToValue) != 0))
            {
                PossibleTransitions.Add(transition);
            }

            if (transition.alwaysVisible)
            {
                _alwaysVisibleTransitions.Add(transition);
            }

            return(false);
        }
Пример #2
0
        private void ReduceTransition(Location currentLocation)
        {
            var rnd = new Random();

            var allTransactions          = new Dictionary <string, IList <Transition> >();
            var alwaysVisibleTransitions = new List <Transition>();

            // Группируем транзакции по имени перехода
            foreach (var possibleTransition in PossibleTransitions)
            {
                IList <Transition> transactionList;
                var titleText = string.IsNullOrEmpty(possibleTransition.title.Text)
                    ?""
                    :possibleTransition.title.Text;
                if (!allTransactions.TryGetValue(titleText, out transactionList))
                {
                    transactionList = new List <Transition>();
                    allTransactions.Add(titleText, transactionList);
                }
                transactionList.Add(possibleTransition);
            }

            // Добавляем всегда видимыет транзакции
            foreach (var alwaysVisibleTransition in _alwaysVisibleTransitions)
            {
                var titleText = string.IsNullOrEmpty(alwaysVisibleTransition.title.Text)
                    ? ""
                    : alwaysVisibleTransition.title.Text;
                if (!allTransactions.ContainsKey(alwaysVisibleTransition.title.Text))
                {
                    alwaysVisibleTransitions.Add(alwaysVisibleTransition);
                }
            }

            //var allTransactions = _possibleTransitions.Concat(_alwaysVisibleTransitions).ToList();

            PossibleTransitions.Clear();
            _alwaysVisibleTransitions.Clear();

            alwaysVisibleTransitions.ForEach(v => _alwaysVisibleTransitions.Add(v));

            foreach (var allTransaction in allTransactions)
            {
                if (allTransaction.Value.Count == 1)
                {
                    var transition = allTransaction.Value.Single();
                    var priority   = transition.priority;
                    if (priority < 1f)
                    {
                        if (rnd.Next(1000) < (int)(priority * 1000))
                        {
                            PossibleTransitions.Add(transition);
                        }
                    }
                    else
                    {
                        PossibleTransitions.Add(transition);
                    }
                    continue;
                }
                var        allRange          = allTransaction.Value.Sum(v => v.priority);
                var        randValue         = rnd.Next((int)(allRange * 1000));
                var        countPriority     = 0;
                Transition selectTransaction = null;
                foreach (var transition in allTransaction.Value)
                {
                    selectTransaction = transition;
                    countPriority     = (int)(transition.priority * 1000);
                    if (countPriority >= randValue)
                    {
                        break;
                    }
                }
                PossibleTransitions.Add(selectTransaction);
            }
        }
Пример #3
0
 public void AddTransition(string command, BaseFolder folder)
 {
     PossibleTransitions.Add(command, folder);
 }