コード例 #1
0
        public override WorldDescriptionRecord GetWorldDescriptionRecord()
        {
            string errorString;
            string expressionEffect = "";

            if (ParseAction(ComboBoxAction.SelectedIndex, out errorString) &&
                ParseExpression(TextBoxFormEffect.Text, out expressionEffect, out errorString))
            {
                //allow empty ifExpresion
                string expressionIf = "";
                ParseExpression(TextBoxFormIf.Text, out expressionIf, out errorString);

                var wdr = new ActionCausesIfRecord(this.SelectedAction, expressionEffect, expressionIf);
                CleanValues();
                return(wdr);
            }

            LabelValidation.Content = errorString;
            throw new TypeLoadException("Validation error");
        }
コード例 #2
0
        private IEnumerable <State> GetPossibleFutureStates(WorldAction worldAction, State state, int time)
        {
            var possibleFutureStates = new List <State>();

            // Get released fluents
            var releasedFluents = GetReleasedFluents(worldAction, state, time);

            // Get possible state changes from ActionCausesIf records
            var actionCausesRec = Descriptions.Where(t => t.Item1 == WorldDescriptionRecordType.ActionCausesIf)
                                  .Select(t => t.Item2 as ActionCausesIfRecord).ToList();
            ActionCausesIfRecord causedStatesX = null;

            try
            {
                causedStatesX = actionCausesRec.Where(t => t.IsFulfilled(state, worldAction)).Aggregate((x, y) => x.Concat(y));
            }
            catch (InvalidOperationException)
            {
                return(new List <State>()
                {
                    state
                });
            }
            var causedStates         = causedStatesX.GetResult();
            var possibleStateChanges = new List <State>(causedStates.Select(t => new State {
                Fluents = t.ToList()
            }));

            // Get all future states excluding released fluents changes
            foreach (var stateChange in possibleStateChanges)
            {
                var template = (State)state.Clone();
                template.Fluents.RemoveAll(t => stateChange.Fluents.Any(x => x.Name == t.Name));
                template.Fluents.AddRange(stateChange.Fluents);
                possibleFutureStates.Add(template);
            }

            // Include released fluents
            foreach (var fluent in releasedFluents)
            {
                var statesToAdd = new List <State>();
                foreach (var futureState in possibleFutureStates)
                {
                    var copy            = (State)futureState.Clone();
                    var fluentToRelease = copy.Fluents.First(t => t.Name == fluent.Name);
                    fluentToRelease.Value = !fluentToRelease.Value;
                    statesToAdd.Add(copy);
                }
                possibleFutureStates.AddRange(statesToAdd);
            }

            if (possibleFutureStates.Count == 0)
            {
                possibleFutureStates = new List <State>()
                {
                    state
                };
            }

            return(possibleFutureStates);
        }