Exemplo n.º 1
0
        private void LoadTheme(Themes theme)
        {
            Primary   p   = (Primary)Enum.Parse(typeof(Primary), theme.Primary.ToString());
            Primary   dp  = (Primary)Enum.Parse(typeof(Primary), theme.DarkPrimary.ToString());
            Primary   lp  = (Primary)Enum.Parse(typeof(Primary), theme.LightPrimary.ToString());
            Accent    acc = (Accent)Enum.Parse(typeof(Accent), theme.Accent.ToString());
            TextShade ts  = (TextShade)Enum.Parse(typeof(TextShade), theme.TextShade.ToString());

            cbPrimary.SelectedIndex      = Array.IndexOf(Enum.GetValues(p.GetType()), p);
            cbDarkPrimary.SelectedIndex  = Array.IndexOf(Enum.GetValues(dp.GetType()), dp);
            cbLightPrimary.SelectedIndex = Array.IndexOf(Enum.GetValues(lp.GetType()), lp);

            cbAccent.SelectedIndex    = Array.IndexOf(Enum.GetValues(acc.GetType()), acc);
            cbTextShade.SelectedIndex = Array.IndexOf(Enum.GetValues(ts.GetType()), ts);

            if (MaterialSkinManager.Instance.Theme != (MaterialSkinManager.Themes)theme.Mode) //changing theme to the same theme is still expensive
            {
                MaterialSkinManager.Instance.Theme = (MaterialSkinManager.Themes)theme.Mode;
            }

            currentSelectedTheme = theme;
            Settings set = BLLocalDatabase.Setting.Settings;

            set.CurrentTheme = theme.Id;
            BLLocalDatabase.Setting.UpdateSettings(set);

            GC.Collect();
        }
Exemplo n.º 2
0
        public override ActionEnum Action(List <Element> elements, float angleToCenter, bool inZone, ref float xdelta, ref float ydelta, ref float angle)
        {
            // check if last action failed
            if (LastActionFailed > 0)
            {
                LastActionFailed--;
                xdelta = Xdelta;
                ydelta = Ydelta;
                return(ActionEnum.Move);
            }

            // construct a view of the current world
            var data = new TrainingData()
            {
                // core data
                CenterAngle   = angleToCenter,
                InZone        = inZone,
                Health        = Health,
                Shield        = Shield,
                Z             = Z,
                Primary       = Primary != null?Primary.GetType().Name     : "",
                PrimaryAmmo   = Primary != null ? Primary.Ammo             : 0,
                PrimaryClip   = Primary != null ? Primary.Clip             : 0,
                Secondary     = Secondary != null?Secondary.GetType().Name : "",
                SecondaryAmmo = Secondary != null ? Secondary.Ammo         : 0,
                SecondaryClip = Secondary != null ? Secondary.Clip         : 0
            };

            data.Proximity = AITraining.ComputeProximity(this, elements).Values.ToList();

            // use the model to predict its actions
            var modeldataset = data.AsModelDataSet();
            int iAction      = 0;

            {
                iAction = (int)Math.Round(ActionModel.Predict(modeldataset));
                angle   = AngleModel.Predict(modeldataset);
                XYModel.Predict(modeldataset, out xdelta, out ydelta);
            }

            // do some sanity checking...
            if (iAction < 0 || iAction >= (int)ActionEnum.COUNT)
            {
                iAction = (int)ActionEnum.Move;
            }
            if (Math.Abs(xdelta) + Math.Abs(ydelta) > 1.00001)
            {
                throw new Exception("xdelta and ydelta are invalid");
            }
            if (angle < 0)
            {
                angle += 360;
            }
            if (angle > 360)
            {
                angle -= 360;
            }
            if (angle < 0 || angle > 360)
            {
                throw new Exception("Invalid angle: " + angle);
            }

            return((ActionEnum)iAction);
        }
Exemplo n.º 3
0
        public override ActionEnum Action(List <Element> elements, float angleToCenter, bool inZone, ref float xdelta, ref float ydelta, ref float zdelta, ref float angle)
        {
            // check if last action failed
            if (LastActionFailed > 0)
            {
                LastActionFailed--;
                xdelta = Xdelta;
                ydelta = Ydelta;
                return(ActionEnum.Move);
            }

            // construct a view of the current world
            var pname = "";
            var pammo = 0;
            var pclip = 0;
            var sname = "";
            var sammo = 0;
            var sclip = 0;

            if (Primary != null && Primary is RangeWeapon)
            {
                pname = Primary.GetType().Name;
                pammo = (Primary as RangeWeapon).Ammo;
                pclip = (Primary as RangeWeapon).Clip;
            }
            if (Secondary != null && Secondary.Length == 1 && Secondary[0] != null && Secondary[0] is RangeWeapon)
            {
                sname = Secondary.GetType().Name;
                sammo = (Secondary[0] as RangeWeapon).Ammo;
                sclip = (Secondary[0] as RangeWeapon).Clip;
            }
            var data = new TrainingData()
            {
                // core data
                CenterAngle   = angleToCenter,
                InZone        = inZone,
                Health        = Health,
                Shield        = Shield,
                Z             = Z,
                Primary       = pname,
                PrimaryAmmo   = pammo,
                PrimaryClip   = pclip,
                Secondary     = sname,
                SecondaryAmmo = sammo,
                SecondaryClip = sclip
            };

            data.Proximity = AITraining.ComputeProximity(this, elements).Values.ToList();

            // use the model to predict its actions
            var modeldataset = data.AsModelDataSet();
            int iAction      = 0;

            {
                iAction = (int)Math.Round(ActionModel.Predict(modeldataset));
                angle   = AngleModel.Predict(modeldataset);
                XYModel.Predict(modeldataset, out xdelta, out ydelta);
            }

            // do some sanity checking...
            if (iAction < 0 || iAction >= (int)ActionEnum.COUNT)
            {
                iAction = (int)ActionEnum.Move;
            }
            if (Math.Abs(xdelta) + Math.Abs(ydelta) > 1.00001)
            {
                throw new Exception("xdelta and ydelta are invalid");
            }
            while (angle < 0)
            {
                angle += 360;
            }
            while (angle >= 360)
            {
                angle -= 360;
            }
            if (angle < 0 || angle >= 360)
            {
                throw new Exception("Invalid angle: " + angle);
            }

            return((ActionEnum)iAction);
        }