Ejemplo n.º 1
0
        public EvolutionDreamer(ItemOptionsArco itemOptions, BotShellColorsDNA shellColors, int numTrackedBots)
        {
            _itemOptions = itemOptions;
            _shellColors = shellColors;

            _mutateArgs = GetMutateArgs(itemOptions);

            _dreamWorld = new OfflineWorld(BOUNDRYSIZE, itemOptions);

            _trackedBots = new TrackedBot[numTrackedBots];
            for (int cntr = 0; cntr < numTrackedBots; cntr++)
            {
                _trackedBots[cntr] = new TrackedBot(_lock);
            }

            _timer           = new System.Timers.Timer();
            _timer.AutoReset = false;
            _timer.Interval  = 250;
            _timer.Elapsed  += Timer_Elapsed;
            _timer.Start();

            _ruleTimer           = new System.Timers.Timer();
            _ruleTimer.AutoReset = false;
            _ruleTimer.Interval  = 50;
            _ruleTimer.Elapsed  += RuleTimer_Elapsed;
            _ruleTimer.Start();

            _ruleElapsed = _ruleTimer.Interval / 1000d;
        }
Ejemplo n.º 2
0
        private static Model3D GetModel(out BotShellColorsDNA backdropColors, PortalVisualType portalType, double radius)
        {
            switch (portalType)
            {
            case PortalVisualType.Shop:
                return(GetModel_Shop(out backdropColors, radius));

            default:
                throw new ApplicationException("Unknown PortalVisualType: " + portalType.ToString());
            }
        }
Ejemplo n.º 3
0
        private static Model3D GetModel_Shop(out BotShellColorsDNA backdropColors, double radius)
        {
            Model3DGroup retVal = new Model3DGroup();

            backdropColors = new BotShellColorsDNA();
            backdropColors.DiffuseDrift  = 0;
            backdropColors.EmissiveColor = "00000000";

            #region Plate

            backdropColors.InnerColorDiffuse = "554A3A";

            // Material
            MaterialGroup material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(backdropColors.InnerColorDiffuse))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40958265")), 20d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material     = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .1);

            retVal.Children.Add(geometry);

            #endregion

            #region Gold Mineral

            // Get gold's color
            backdropColors.Light = Mineral.GetSettingsForMineralType(MineralType.Gold).DiffuseColor.ToHex();

            // Get the model of a gold mineral
            Model3D model = Mineral.GetNewVisual(MineralType.Gold);

            // Figure out the scale
            Rect3D aabb     = model.Bounds;
            double halfSize = Math1D.Max(aabb.SizeX, aabb.SizeY, aabb.SizeZ) / 2d;

            double scale = (radius * .66d) / halfSize;
            model.Transform = new ScaleTransform3D(scale, scale, scale);

            retVal.Children.Add(model);

            #endregion

            return(retVal);
        }
Ejemplo n.º 4
0
        public static Tuple<BotDNA, WeaponDNA> GetRandomDNA(BotShellColorsDNA shellColors = null, WeaponDNA weapon = null)
        {
            Random rand = StaticRandom.GetRandomForThread();

            BotDNA bot = new BotDNA()
            {
                UniqueID = Guid.NewGuid(),
                Lineage = Guid.NewGuid().ToString(),
                Generation = 0,
                DraggingMaxVelocity = rand.NextPercent(5, .25),
                DraggingMultiplier = rand.NextPercent(20, .25),
            };

            #region Parts

            List<ShipPartDNA> parts = new List<ShipPartDNA>();

            double partSize;

            // Homing
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA() { PartType = SensorHoming.PARTTYPE, Position = new Point3D(0, 0, 2.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) });

            // Vision
            //TODO: Support filtering by type
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA() { PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) });

            // Brains
            int numBrains = 1 + Convert.ToInt32(rand.NextPow(5, 1d) * 4);

            for (int cntr = 0; cntr < numBrains; cntr++)
            {
                partSize = rand.NextPercent(1, .5);

                Point3D position = new Point3D(0, 0, 0);
                if (numBrains > 1)
                {
                    position = Math3D.GetRandomVector_Circular(1).ToPoint();
                }

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Position = position, Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) });
            }

            // MotionController_Linear - always exactly one of these
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA() { PartType = MotionController_Linear.PARTTYPE, Position = new Point3D(0, 0, -1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize) });

            // Store it
            bot.Parts = parts.ToArray();

            #endregion

            if (shellColors == null)
            {
                bot.ShellColors = BotShellColorsDNA.GetRandomColors();
            }
            else
            {
                bot.ShellColors = shellColors;
            }

            #region Weapon

            WeaponDNA weaponActual = null;
            if (weapon == null)
            {
                if (rand.NextDouble() < .95d)
                {
                    WeaponHandleMaterial[] weaponMaterials = new WeaponHandleMaterial[] { WeaponHandleMaterial.Soft_Wood, WeaponHandleMaterial.Hard_Wood };

                    weaponActual = new WeaponDNA()
                    {
                        UniqueID = Guid.NewGuid(),
                        Handle = WeaponHandleDNA.GetRandomDNA(weaponMaterials[StaticRandom.Next(weaponMaterials.Length)])
                    };
                }
            }
            else
            {
                weaponActual = weapon;
            }

            #endregion

            return Tuple.Create(bot, weaponActual);
        }
Ejemplo n.º 5
0
        public EvolutionDreamer(ItemOptionsArco itemOptions, BotShellColorsDNA shellColors, int numTrackedBots)
        {
            _shellColors = shellColors;

            _mutateArgs = GetMutateArgs(itemOptions);

            _dreamWorld = new OfflineWorld(BOUNDRYSIZE, itemOptions);

            _trackedBots = new TrackedBot[numTrackedBots];
            for (int cntr = 0; cntr < numTrackedBots; cntr++)
            {
                _trackedBots[cntr] = new TrackedBot(_lock);
            }

            _timer = new System.Timers.Timer();
            _timer.AutoReset = false;
            _timer.Interval = 250;
            _timer.Elapsed += Timer_Elapsed;
            _timer.Start();

            _ruleTimer = new System.Timers.Timer();
            _ruleTimer.AutoReset = false;
            _ruleTimer.Interval = 50;
            _ruleTimer.Elapsed += RuleTimer_Elapsed;
            _ruleTimer.Start();

            _ruleElapsed = _ruleTimer.Interval / 1000d;
        }
Ejemplo n.º 6
0
        private static Model3D GetModel_Shop(out BotShellColorsDNA backdropColors, double radius)
        {
            Model3DGroup retVal = new Model3DGroup();

            backdropColors = new BotShellColorsDNA();
            backdropColors.DiffuseDrift = 0;
            backdropColors.EmissiveColor = "00000000";

            #region Plate

            backdropColors.InnerColorDiffuse = "554A3A";

            // Material
            MaterialGroup material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex(backdropColors.InnerColorDiffuse))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40958265")), 20d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            geometry.Geometry = UtilityWPF.GetSphere_LatLon(6, radius, radius, radius * .1);

            retVal.Children.Add(geometry);

            #endregion

            #region Gold Mineral

            // Get gold's color
            backdropColors.Light = Mineral.GetSettingsForMineralType(MineralType.Gold).DiffuseColor.ToHex();

            // Get the model of a gold mineral
            Model3D model = Mineral.GetNewVisual(MineralType.Gold);

            // Figure out the scale
            Rect3D aabb = model.Bounds;
            double halfSize = Math1D.Max(aabb.SizeX, aabb.SizeY, aabb.SizeZ) / 2d;

            double scale = (radius * .66d) / halfSize;
            model.Transform = new ScaleTransform3D(scale, scale, scale);

            retVal.Children.Add(model);

            #endregion

            return retVal;
        }
Ejemplo n.º 7
0
        private static Model3D GetModel(out BotShellColorsDNA backdropColors, PortalVisualType portalType, double radius)
        {
            switch (portalType)
            {
                case PortalVisualType.Shop:
                    return GetModel_Shop(out backdropColors, radius);

                default:
                    throw new ApplicationException("Unknown PortalVisualType: " + portalType.ToString());
            }
        }
Ejemplo n.º 8
0
        public static (BotDNA bot, WeaponDNA weapon) GetRandomDNA(ItemOptionsArco itemOptions, BotShellColorsDNA shellColors = null, WeaponDNA weapon = null)
        {
            Random rand = StaticRandom.GetRandomForThread();

            BotDNA bot = new BotDNA()
            {
                UniqueID            = Guid.NewGuid(),
                Lineage             = Guid.NewGuid().ToString(),
                Generation          = 0,
                DraggingMaxVelocity = rand.NextPercent(5, .25),
                DraggingMultiplier  = rand.NextPercent(20, .25),
            };

            #region Parts

            List <ShipPartDNA> parts = new List <ShipPartDNA>();

            double partSize;

            // Homing
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA()
            {
                PartType = SensorHoming.PARTTYPE, Position = new Point3D(0, 0, 2.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
            });

            // Vision
            //TODO: Support filtering by type
            partSize = rand.NextPercent(1, .5);
            parts.Add(new SensorVisionDNA()
            {
                PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize), SearchRadius = itemOptions.VisionSensor_SearchRadius
            });

            // Brains
            int numBrains = 1 + Convert.ToInt32(rand.NextPow(5, 1d) * 4);

            for (int cntr = 0; cntr < numBrains; cntr++)
            {
                partSize = rand.NextPercent(1, .5);

                Point3D position = new Point3D(0, 0, 0);
                if (numBrains > 1)
                {
                    position = Math3D.GetRandomVector_Circular(1).ToPoint();
                }

                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Position = position, Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
                });
            }

            // MotionController - always exactly one of these
            partSize = rand.NextPercent(1, .5);
            parts.Add(new ShipPartDNA()
            {
                PartType = MotionController2.PARTTYPE, Position = new Point3D(0, 0, -1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(partSize, partSize, partSize)
            });

            // Store it
            bot.Parts = parts.ToArray();

            #endregion

            if (shellColors == null)
            {
                bot.ShellColors = BotShellColorsDNA.GetRandomColors();
            }
            else
            {
                bot.ShellColors = shellColors;
            }

            #region Weapon

            WeaponDNA weaponActual = null;
            if (weapon == null)
            {
                if (rand.NextDouble() < .95d)
                {
                    WeaponHandleMaterial[] weaponMaterials = new WeaponHandleMaterial[] { WeaponHandleMaterial.Soft_Wood, WeaponHandleMaterial.Hard_Wood };

                    weaponActual = new WeaponDNA()
                    {
                        UniqueID = Guid.NewGuid(),
                        Handle   = WeaponHandleDNA.GetRandomDNA(weaponMaterials[StaticRandom.Next(weaponMaterials.Length)])
                    };
                }
            }
            else
            {
                weaponActual = weapon;
            }

            #endregion

            return(bot, weaponActual);
        }
Ejemplo n.º 9
0
        public NPCNest(NPCNestDNA dna, double radius, World world, Map map, KeepItems2D keepItems2D, MaterialIDs materialIDs, Viewport3D viewport, EditorOptions editorOptions, ItemOptionsArco itemOptions, IGravityField gravity, DragHitShape dragPlane)
        {
            // Store stuff
            _world = world;
            _map = map;
            _keepItems2D = keepItems2D;
            _materialIDs = materialIDs;
            _viewport = viewport;
            _editorOptions = editorOptions;
            _itemOptions = itemOptions;
            _gravity = gravity;
            _dragPlane = dragPlane;

            // DNA
            NPCNestDNA fixedDNA = GetFinalDNA(dna);
            _shellColors = fixedDNA.ShellColors;
            _botDNA = fixedDNA.BotDNA;
            _weaponDNA = fixedDNA.WeaponDNA;

            //TODO: Hand this a winner list, and filter criteria
            _dreamer = new EvolutionDreamer(_itemOptions, _shellColors, 4);     //TODO: Num bots should come from item options
            _dreamer.WeaponDNA = EvolutionDreamer.GetRandomDNA().Item2;

            #region WPF Model

            var models = GetModel(_shellColors, radius);
            this.Model = models.Item1;
            _eggModels = models.Item2;

            _rotateTransform = new QuaternionRotation3D();
            _translateTransform = new TranslateTransform3D();

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(_rotateTransform));
            transform.Children.Add(_translateTransform);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Transform = transform;
            visual.Content = this.Model;

            this.Visuals3D = new Visual3D[] { visual };

            #endregion

            // Energy tank
            _energy = new Container();
            _energy.QuantityMax = _itemOptions.Nest_Energy_Max * radius;
            _energy.QuantityCurrent = _energy.QuantityMax * .5d;

            // Finish
            this.Token = TokenGenerator.NextToken();
            this.Radius = radius;
            this.CreationTime = DateTime.UtcNow;
        }
Ejemplo n.º 10
0
        private static GeometryModel3D GetEggModel(Point3D position, double radius, BotShellColorsDNA colors)
        {
            // Material
            MaterialGroup material = new MaterialGroup();

            Color baseColor = UtilityWPF.ColorFromHex(colors.InnerColorDiffuse);

            ColorHSV driftedColor = baseColor.ToHSV();
            driftedColor = new ColorHSV(UtilityWPF.GetCappedAngle(driftedColor.H + (colors.DiffuseDrift * StaticRandom.NextDouble(0, 4))), driftedColor.S, driftedColor.V);

            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(driftedColor.ToRGB())));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80FFFFFF")), 20));
            material.Children.Add(new EmissiveMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("20" + colors.EmissiveColor.Substring(colors.EmissiveColor.Length - 6)))));

            // Geometry Model
            GeometryModel3D retVal = new GeometryModel3D();
            retVal.Material = material;
            retVal.BackMaterial = material;

            retVal.Geometry = UtilityWPF.GetSphere_LatLon(5, radius);

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new ScaleTransform3D(new Vector3D(.75d, .75d, 1d)));
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));
            transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            retVal.Transform = transform;

            return retVal;
        }
Ejemplo n.º 11
0
        private static Tuple<Model3DGroup, Model3DGroup> GetModel(BotShellColorsDNA colors, double radius)
        {
            //TODO: Maybe throw some other debris in the nest

            Model3DGroup retVal = new Model3DGroup();

            #region Light

            // Light
            Color lightColor = UtilityWPF.ColorFromHex(colors.Light);
            PointLight pointLight = new PointLight(lightColor, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(pointLight, radius * 2d, .1d);

            retVal.Children.Add(pointLight);

            #endregion

            #region Bowl

            //-------- outer bowl

            // Material
            MaterialGroup material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("8C8174"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("40736355")), 5d));

            // Geometry Model
            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            List<TubeRingBase> rings = new List<TubeRingBase>();
            rings.Add(new TubeRingDome(0, false, 3));
            rings.Add(new TubeRingRegularPolygon(radius * .4, false, radius, radius, false));
            rings.Add(new TubeRingRegularPolygon(radius * .1, false, radius * .9, radius * .9, false));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(20, rings, true, true, new TranslateTransform3D(0, 0, radius * -.3));

            retVal.Children.Add(geometry);


            //-------- inner bowl

            // Material
            material = new MaterialGroup();
            material.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("A6998A"))));
            material.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("80C2A78F")), 2d));

            // Geometry Model
            geometry = new GeometryModel3D();
            geometry.Material = material;
            geometry.BackMaterial = material;

            rings = new List<TubeRingBase>();
            rings.Add(new TubeRingRegularPolygon(0, false, radius * .9, radius * .9, false));
            rings.Add(new TubeRingDome(radius * -.4, false, 5));

            geometry.Geometry = UtilityWPF.GetMultiRingedTube(20, rings, true, false, new TranslateTransform3D(0, 0, (radius * .25) + (radius * -.3)));

            retVal.Children.Add(geometry);

            #endregion

            // Make a bucket to add egg visuals into
            Model3DGroup eggs = new Model3DGroup();
            retVal.Children.Add(eggs);

            return Tuple.Create(retVal, eggs);
        }