コード例 #1
0
ファイル: Rule.cs プロジェクト: silhanji/lsystems
        /// <summary>
        /// Checks if module at given index meets all conditions of this rule.
        /// </summary>
        /// <param name="index">Determines module which is checked against conditions of rule</param>
        /// <returns>True if module at given index meets all conditions of rule, false otherwise</returns>
        internal bool CanBeApplied(GenerationIndex <T> index)
        {
            //Check ids
            if (_sourceId != index.Module.Id)
            {
                return(false);
            }

            //Check all context conditions
            foreach (var condition in _contextConditions)
            {
                if (!condition(index))
                {
                    return(false);
                }
            }

            //Check parametric conditions
            foreach (var condition in _paramConditions)
            {
                if (!condition(index.Module.Parameters))
                {
                    return(false);
                }
            }

            //All conditions passed
            return(true);
        }
コード例 #2
0
            public void Start()
            {
                NextGeneration = new List <Module <T> >();

                for (int i = _startIndex; i < _startIndex + _count; i++)
                {
                    bool existsRule = false;
                    var  genIndex   = new GenerationIndex <T>(_generator.CurrentGeneration, i);
                    foreach (var rule in _generator._rules)
                    {
                        if (rule.CanBeApplied(genIndex))
                        {
                            NextGeneration.AddRange(rule.Apply(_generator.CurrentGeneration[i]));
                            existsRule = true;
                            break;
                        }
                    }
                    if (!existsRule)                    //Default 'copy' rule
                    {
                        NextGeneration.Add(_generator.CurrentGeneration[i]);
                    }
                }

                Completed = true;
            }