/// <summary>
        /// Returns the Value For the Setting, when the type is Active/Dead (If not found, it will automatically Search in Global)
        /// </summary>
        /// <param name="settingName">The Name of the setting to return.</param>
        /// <param name="OpponentIsDead">Specify which setting to return, (Active or Dead)</param>
        /// <returns>Returns the Instance Value of the Proper Setting (Active/Dead or Global)</returns>
        internal int GetSetting(string settingName, bool OpponentIsDead)
        {
            AlgorithmSetting foundSetting = null;

            if (GlobalSettings.Any(v => v.Name == settingName))
            {
                //Setting was not found in Active/Dead - try in Global...
                foundSetting = GlobalSettings.FirstOrDefault(v => v.Name == settingName);
            }
            else
            {
                //Get the Value from the Proper Collection.
                if (OpponentIsDead)
                {
                    foundSetting = DeadSettings.FirstOrDefault(v => v.Name == settingName);
                }
                else
                {
                    foundSetting = ActiveSettings.FirstOrDefault(v => v.Name == settingName);
                }
            }

            if (foundSetting == null)
            {
                Log.Error($"[Custom Algorithm Settings]{settingName} Setting Does not exist! - Developer! - Check Algorithm Configuration!");
                return(-1);
            }

            return(foundSetting.Value);
        }
        /// <summary>
        /// Called to define a Setting for the Algorithm that can be used at runtime.
        /// </summary>
        /// <param name="setting"></param>
        public void DefineSetting(AlgorithmSetting setting)
        {
            //Active
            if (setting.TypeOfSetting == SettingType.ActiveAndDead || setting.TypeOfSetting == SettingType.ActiveOnly)
            {
                var instanceCopy = setting.Clone();
                instanceCopy.InstanceType = SettingInstanceType.Active;
                ActiveSettings.Add(instanceCopy);
            }

            //Dead
            if (setting.TypeOfSetting == SettingType.ActiveAndDead || setting.TypeOfSetting == SettingType.DeadOnly)
            {
                var instanceCopy = setting.Clone();
                instanceCopy.InstanceType = SettingInstanceType.Dead;
                DeadSettings.Add(instanceCopy);
            }

            //Global
            if (setting.TypeOfSetting == SettingType.Global)
            {
                var instanceCopy = setting.Clone();
                instanceCopy.InstanceType = SettingInstanceType.Global;
                GlobalSettings.Add(instanceCopy);
            }
        }
示例#3
0
        internal void SetIndividualSetting(AlgorithmSetting setting, string algorithmName, int newValue)
        {
            if (setting.PossibleValues.Count > 0)
            {
                //If there are possible Values set, and the new value is not one of them, do NOT set the value.
                if (!setting.PossibleValues.Any(v => v.Value == newValue))
                {
                    Log.Warning($"[Custom Algorithm Settings] {algorithmName} - {setting.Name} - Stored value of {newValue} is no longer in the list of possible values.  Value not set.");
                    return;
                }
            }

            if (newValue > setting.MaxValue)
            {
                //Setting is invalid, set to Maximum.
                Log.Warning($"[Custom Algorithm Settings] {algorithmName} - {setting.Name} - Stored value of {newValue} is higher than the Maximum.  Defaulting to Maximum of {setting.MaxValue}.");
                setting.Value = setting.MaxValue;
            }
            else if (newValue < setting.MinValue)
            {
                //Setting is invalid, set to Minimum.
                Log.Warning($"[Custom Algorithm Settings] {algorithmName} - {setting.Name} - Stored value of {newValue} is lower than the Minimum.  Defaulting to Minimum of {setting.MinValue}.");
                setting.Value = setting.MinValue;
            }
            else
            {
                //Set the value
                setting.Value = newValue;
            }
        }
        /// <summary>
        /// Provides a Clone of the Algorithm Setting
        /// </summary>
        /// <returns></returns>
        internal AlgorithmSetting Clone()
        {
            var clone = new AlgorithmSetting(Name, Description, Value, TypeOfSetting);

            clone.InstanceType = InstanceType;
            clone.MinValue     = MinValue;
            clone.MaxValue     = MaxValue;
            clone.HideInUiWhen.AddRange(HideInUiWhen);
            clone.PossibleValues.AddRange(PossibleValues); //Since these are only for the UI, we dont care if they are a reference...
            return(clone);
        }
        /// <summary>
        /// Sets the Visibility for an individual Setting - by evaluating conditions in HideInUiWhen Collection.
        /// </summary>
        private void SetIndividualVisibility(AlgorithmSetting setting, FlowLayoutPanel flowLayoutPanel, bool deadSetting)
        {
            //Get a reference to the Control for this setting, and set it to visible by default.
            var control = GetControl(flowLayoutPanel, setting.Name);

            control.Visible = true;

            foreach (var settingCondition in setting.HideInUiWhen)
            {
                //Get the current Setting, and compare it against the condition.
                if (_settings.GetSetting(settingCondition.Key, deadSetting) == settingCondition.Value)
                {
                    //Conditions are met to Hide this Setting! (once a single condition is met, no need to compare other conditions)
                    control.Visible = false;
                    break;
                }
            }
        }