Пример #1
0
        //TODO: Make a static method off of Ship, and don't rely on world: public static Visual3D CreateVisual(ShipDNA dna, bool isDesign)
        private void RenderShipAsync(NewtonDynamics.World world)
        {
            ShipExtraArgs args = new ShipExtraArgs()
            {
                RunNeural           = false,
                RepairPartPositions = false,
            };

            //using (Ship ship = await Ship.GetNewShipAsync(this.ShipDNA, world, 0, null, args))
            using (Bot bot = new Bot(BotConstructor.ConstructBot(this.ShipDNA, new ShipCoreArgs()
            {
                World = world
            }, args)))
            {
                if (bot.PhysicsBody.Visuals != null)            // this will never be null
                {
                    // The model coords may not be centered, so move the ship so that it's centered on the origin
                    Point3D minPoint, maxPoint;
                    bot.PhysicsBody.GetAABB(out minPoint, out maxPoint);
                    Vector3D offset = (minPoint + ((maxPoint - minPoint) / 2d)).ToVector();

                    bot.PhysicsBody.Position = (-offset).ToPoint();

                    // Add the visuals
                    foreach (Visual3D visual in bot.PhysicsBody.Visuals)
                    {
                        _viewport.Children.Add(visual);
                    }

                    // Pull the camera back to a good distance
                    _camera.Position = (_camera.Position.ToVector().ToUnit() * (bot.Radius * 2.1d)).ToPoint();
                }
            }
        }
Пример #2
0
 public EditShipTransfer(Player player, SpaceDockPanel spaceDock, Editor editor, EditorOptions editorOptions, World world, int material_Ship, Map map, ShipExtraArgs shipExtra)
 {
     _player        = player;
     _spaceDock     = spaceDock;
     _editor        = editor;
     _editorOptions = editorOptions;
     _world         = world;
     _material_Ship = material_Ship;
     _map           = map;
     _shipExtra     = shipExtra;
 }
Пример #3
0
 public EditShipTransfer(Player player, SpaceDockPanel spaceDock, Editor editor, EditorOptions editorOptions, World world, int material_Ship, Map map, ShipExtraArgs shipExtra)
 {
     _player = player;
     _spaceDock = spaceDock;
     _editor = editor;
     _editorOptions = editorOptions;
     _world = world;
     _material_Ship = material_Ship;
     _map = map;
     _shipExtra = shipExtra;
 }
Пример #4
0
        public TrainingSession(ShipDNA dna, ShipExtraArgs shipExtraArgs, int inputCount, int outputCount, Func <WorldAccessor, TrainingRoom, IPhenomeTickEvaluator <IBlackBox, NeatGenome> > getNewEvaluator, int roomCount = 25, double roomSize = ROOMSIZE)
        {
            DNA           = dna;
            ShipExtraArgs = shipExtraArgs;

            double roomMargin = roomSize / 10;

            Arena = new ArenaAccessor(roomCount, roomSize, roomMargin, false, false, new Type[] { typeof(Bot) }, new Type[] { typeof(Bot) }, shipExtraArgs.NeuralPoolManual, (.1, .25));
            Arena.WorldCreated += Arena_WorldCreated;

            foreach (var(room, _) in Arena.AllRooms)
            {
                room.Evaluator = getNewEvaluator(Arena.WorldAccessor, room);
            }

            #region experiment args

            ExperimentInitArgs experimentArgs = new ExperimentInitArgs()
            {
                Description    = "Trains an individual BrainNEAT part",
                InputCount     = inputCount,
                OutputCount    = outputCount,
                IsHyperNEAT    = false,
                PopulationSize = roomCount,        // may want to do a few more than rooms in case extra are made
                SpeciesCount   = Math.Max(2, (roomCount / 4d).ToInt_Ceiling()),
                Activation     = GetActivationFunctionArgs(),
                Complexity_RegulationStrategy = ComplexityCeilingType.Absolute,
                Complexity_Threshold          = 200,
            };

            #endregion

            Experiment = new ExperimentNEATBase();

            // Use the overload that takes the tick phenome
            Experiment.Initialize("BrainNEAT Trainer", experimentArgs, Arena.AllRooms.Select(o => o.room.Evaluator).ToArray(), Arena.WorldAccessor.RoundRobinManager, Arena.WorldAccessor.UpdateWorld);

            EA = Experiment.CreateEvolutionAlgorithm();

            // look in AnticipatePositionWindow for an example.  The update event just displays stats
            //ea.UpdateEvent += EA_UpdateEvent;
            //ea.PausedEvent += EA_PausedEvent;
        }
Пример #5
0
        /// <summary>
        /// This only needs to be called once for an arcanorum world.  All bots can be handed this same class
        /// </summary>
        public static ShipExtraArgs GetArgs_Extra()
        {
            //TODO: Adjust neuron count ratios so that there are enough neurons in the brain

            ShipExtraArgs extra = new ShipExtraArgs()
            {
                Options = new EditorOptions(),

                ItemOptions = new ItemOptionsArco()
                {
                    VisionSensor_NeuronDensity    = 50,
                    BrainNEAT_NeuronDensity_Input = 400,
                },
            };

            extra.Gravity = new GravityFieldUniform()
            {
                Gravity = new Vector3D(0, -((ItemOptionsArco)extra.ItemOptions).Gravity, 0)
            };

            return(extra);
        }
Пример #6
0
        public static PartBase InstantiateUnknownPart_Standard(ShipPartDNA dna, ShipCoreArgs core, ShipExtraArgs extra, BotConstruction_Containers containers, object[] botObjects)
        {
            ItemOptionsArco itemOptions = (ItemOptionsArco)extra.ItemOptions;

            var constructProps = botObjects?.FirstOrDefault(o => o is ArcBot2_ConstructionProps) as ArcBot2_ConstructionProps;

            if (constructProps == null)
            {
                throw new ApplicationException("ArcBot2_ConstructionProps needs to be given to the bot constructor in the botObjects param");
            }

            double botRadius = itemOptions.RadiusAtLevel[constructProps.Level];

            switch (dna.PartType)
            {
            case MotionController2.PARTTYPE:
                //if (MotionController.Count > 0)
                //{
                //    throw new ApplicationException("There can be only one plate writer in a bot");
                //}

                AIMousePlate mousePlate = new AIMousePlate(constructProps.DragPlane);
                mousePlate.MaxXY = botRadius * 20;
                mousePlate.Scale = 1;

                return(new MotionController2(extra.Options, itemOptions, dna, mousePlate));

            case SensorVision.PARTTYPE:
                if (dna is SensorVisionDNA sensorVisionDNA)
                {
                    return(new SensorVision(extra.Options, itemOptions, (SensorVisionDNA)dna, core.Map));
                }
                else
                {
                    throw new ApplicationException($"SensorVision requires SensorVisionDNA: {dna.GetType()}");
                }

            default:
                throw new ApplicationException($"Unknown PartType: {dna.PartType}");
            }
        }
Пример #7
0
        /// <summary>
        /// This will return a constructed arcbot (arcbots have hardcoded dna)
        /// </summary>
        public static BotConstruction_Result GetConstruction(int level, ShipCoreArgs core, ShipExtraArgs extra, DragHitShape dragPlane, bool addHomingSensor)
        {
            BotConstructor_Events events = new BotConstructor_Events
            {
                InstantiateUnknownPart_Standard = InstantiateUnknownPart_Standard,
            };

            object[] botObjects = new object[]
            {
                new ArcBot2_ConstructionProps()
                {
                    DragPlane = dragPlane,
                    Level     = level,
                },
            };

            ShipDNA dna = GetDefaultDNA(addHomingSensor);

            return(BotConstructor.ConstructBot(dna, core, extra, events, botObjects));
        }
        private async Task<Bean> AddBeanAsync(ShipDNA dna)
        {
            ShipCoreArgs core = new ShipCoreArgs()
            {
                //Map = _map,       // this wasn't passed in when it was a ship
                Material_Ship = _material_Bean,
                World = _world,
            };

            ShipExtraArgs args = new ShipExtraArgs()
            {
                Options = _editorOptions,
                ItemOptions = _itemOptions,
                Material_Projectile = _material_Projectile,
                Radiation = _radiation,
                Gravity = _options.GravityField,
            };

            //Bean retVal = await Bean.GetNewBeanAsync(dna, _world, _material_Bean, args, _options);
            var seed = BotConstructor.ConstructBot(dna, core, args);
            Bean retVal = new Bean(seed, _options);

            //retVal.PhysicsBody.AngularDamping = new Vector3D(1, 1, 1);
            retVal.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Bean_ApplyForceAndTorque);
            retVal.Dead += new EventHandler<DeadBeanArgs>(Bean_Dead);

            if (_options.NewBeanRandomOrientation)
            {
                retVal.PhysicsBody.Rotation = Math3D.GetRandomRotation();
            }

            if (_options.NewBeanRandomSpin)
            {
                Vector3D angularVelocity = Math3D.GetRandomVector_Spherical_Shell(1d);
                angularVelocity *= _options.AngularVelocityDeath * .5d;

                retVal.PhysicsBody.AngularVelocity = angularVelocity;
            }

            if (retVal.Energy != null)
            {
                retVal.Energy.QuantityCurrent = retVal.Energy.QuantityMax;
            }
            if (retVal.Fuel != null)
            {
                retVal.Fuel.QuantityCurrent = retVal.Fuel.QuantityMax;
            }
            retVal.RecalculateMass();

            Vector3D position = Math3D.GetRandomVector_Circular(TERRAINRADIUS * .5d);
            retVal.PhysicsBody.Position = new Point3D(position.X, position.Y, STARTHEIGHT);

            _map.AddItem(retVal);
            _beans.Add(retVal);

            _options.TotalBeans++;
            this.TotalBeansText = _options.TotalBeans.ToString("N0");

            return retVal;
        }
Пример #9
0
        private void AddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TODO: Implement:
                //  ConverterMatterToFuel
                //  ConverterMatterToEnergy

                //_itemOptions.CameraColorRGBNeuronDensity = 160 * 3;

                #region DNA

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

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 1.43121944558768), Scale = new Vector3D(2.7969681248785, 2.7969681248785, 0.754175785992705)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.617709955450103, 0, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-2.16134944924876E-05, -0.60985890545398, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.00387496389974934, 0.618396858731443, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.624666220599071, 0.00100528924605325, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0), Scale = new Vector3D(1, 1, 1)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.850947345148112, -0.0019217800299223, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00589599969475301, 0.850929089078933, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00522521361558187, -0.850933472485232, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.850949515219971, 0, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToFuel.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.232899395582397, -0.238935114546265, 0.773100284172734), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.22797553388197, 0.226717979419686, 0.775967026847012), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.262933776282848, 0.240405245709603, 0.755961022082205), Scale = new Vector3D(1, 1, 1)
                });
                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.250217552102507, -0.280865739393283, 0.743561713316594), Scale = new Vector3D(0.399083346950047, 0.399083346950047, 0.236501125779081)
                });                                                                                                                                                                                                                                                                         // This is just a placeholder for a future sensor (need to put something here so mass is balanced)

                parts.Add(new ShipPartDNA()
                {
                    PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00208559296997747, 0, 2.00222812584528), Scale = new Vector3D(1, 1, 1)
                });

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00137913748707474, 0, -1.20661030017992), Scale = new Vector3D(1.29260597488229, 1.29260597488229, 1.29260597488229), ThrusterType = ThrusterType.One
                });

                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(-0.623025498564933, -0.775855164007238, -0.0622612340741654, 0.0775340657568128), Position = new Point3D(0.189965645143804, -0.859019870524953, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.948585651195026, -0.300495041099996, 0.0947956598959211, 0.0300295768554372), Position = new Point3D(-0.719304806310003, 0.506559650891123, 0.883258802478371), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });
                parts.Add(new ThrusterDNA()
                {
                    PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.304146575685315, -0.947421167104513, 0.0303944881633535, 0.0946792887093452), Position = new Point3D(0.715381156965589, 0.512085817563994, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One
                });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new GameItems.ShipCoreArgs()
                {
                    Map           = _map,
                    Material_Ship = _material_Bot,
                    World         = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options             = _editorOptions,
                    ItemOptions         = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Radiation           = _radiation,
                    CameraPool          = _cameraPool,
                };

                //Swimbot bot = await Swimbot.GetNewSwimbotAsync(dna, _world, _material_Bot, _map, extra);
                Swimbot bot = new Swimbot(BotConstructor.ConstructBot(dna, core, extra));
                bot.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(Bot_ApplyForceAndTorque);

                bot.PhysicsBody.Rotation = Math3D.GetRandomRotation();
                bot.PhysicsBody.Position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .5d).ToPoint();

                //bot.PhysicsBody.Position = new Point3D(0, 0, BOUNDRYSIZEHALF * -.75d);

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax * .5d;
                }
                if (bot.Fuel != null)
                {
                    bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax * .5d;
                }
                bot.RecalculateMass();

                _map.AddItem(bot);
                _bots.Add(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void btnShipWackyFlyer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(3, 3, 1) });

                ThrusterType thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, 1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, -1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                ShipDNA shipDNA = ShipDNA.Create(parts);

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region DNA

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

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.44329742616787, -2.22044604925031E-16, -0.750606111984116), Scale = new Vector3D(.65, .65, .65) });

                parts.Add(new ShipPartDNA() { PartType = AmmoBox.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.44329742616787, -2.22044604925031E-16, -0.839035218662306), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = ProjectileGun.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.139350859269598, -2.22044604925031E-16, 0.0736057604093046), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.443930484830668, -2.22044604925031E-16, -0.0296267373083678), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(1.17108888679796, 2.22044604925031E-16, -0.787190712968899), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new BrainRGBRecognizerDNA() { PartType = BrainRGBRecognizer.PARTTYPE, Orientation = new Quaternion(3.91881768803066E-16, -0.264772715428398, 1.07599743798686E-16, 0.964310846752577), Position = new Point3D(0.977003177386146, 0, -0.204027736848604), Scale = new Vector3D(1, 1, 1), Extra = GetBrainRGBRecognizerExtra() });

                parts.Add(new ShipPartDNA() { PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.812435730367477, 0, -1.83945537515666), Scale = new Vector3D(1, 1, 1) });

                //parts.Add(new ShipPartDNA() { PartType = ConverterMatterToAmmo.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.724059461163413, 0, -1.57962039018549), Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.127736487867665, 0, -1.58633876430099), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = PlasmaTank.PARTTYPE, Orientation = new Quaternion(0, -0.706641960456376, 0, 0.707571296564784), Position = new Point3D(-0.406755692018177, 0, -2.20579025132833), Scale = new Vector3D(1, 1, 1) });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    CameraPool = _cameraPool,
                    IsPhysicsStatic = true,
                };

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core, extra);
                DefenseBot bot = new DefenseBot(seed);
                bot.PhysicsBody.Position = new Point3D(0, 0, -12);

                bot.ShouldLearnFromLifeEvents = false;

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax;
                }
                if (bot.Ammo != null)
                {
                    bot.Ammo.QuantityCurrent = bot.Ammo.QuantityMax;
                }
                if (bot.Plasma != null)
                {
                    bot.Plasma.QuantityCurrent = bot.Plasma.QuantityMax;
                }

                bot.ShouldLearnFromLifeEvents = true;

                SetBot(bot);

                #region save to file

                //dna = bot.GetNewDNA();

                ////C:\Users\<username>\AppData\Roaming\Asteroid Miner\MissileCommand0D\
                //string foldername = UtilityCore.GetOptionsFolder();
                //foldername = System.IO.Path.Combine(foldername, FOLDER);
                //System.IO.Directory.CreateDirectory(foldername);

                //string filename = DateTime.Now.ToString("yyyyMMdd HHmmssfff") + " - bot";
                //filename = System.IO.Path.Combine(foldername, filename);

                //UtilityCore.SerializeToFile(filename, dna);

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public SpaceDockPanel(EditorOptions editorOptions, ItemOptions itemOptions, Map map, int material_Ship, ShipExtraArgs shipExtra)
        {
            InitializeComponent();

            _editorOptions = editorOptions;
            _itemOptions = itemOptions;
            _map = map;
            _material_Ship = material_Ship;
            _shipExtra = shipExtra;
        }
Пример #13
0
        public static ShipPlayer GetNewShip(ShipDNA dna, World world, int material_Ship, Map map, ShipExtraArgs extra)
        {
            ShipDNA rotatedDNA = RotateDNA_FromExternal(dna);

            #region asserts

            //ShipDNA rockedDNA1 = RotateDNA_ToExternal(RotateDNA_FromExternal(dna));
            //ShipDNA rockedDNA2 = RotateDNA_FromExternal(rockedDNA1);

            //var compare1a = dna.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare1b = rockedDNA1.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //var compare2a = rotatedDNA.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare2b = rockedDNA2.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //for(int cntr = 0; cntr < compare1a.Length; cntr++)
            //{
            //    var com1a = compare1a[cntr];
            //    var com1b = compare1b[cntr];

            //    var com2a = compare2a[cntr];
            //    var com2b = compare2b[cntr];

            //    if(!Math3D.IsNearValue(com1a.Position, com1b.Position))
            //    {
            //        int three = 3;
            //    }
            //    if (!Math3D.IsNearValue(com1a.Orientation, com1b.Orientation))
            //    {
            //        int three = 3;
            //    }

            //    if (!Math3D.IsNearValue(com2a.Position, com2b.Position))
            //    {
            //        int four = 4;
            //    }
            //    if (!Math3D.IsNearValue(com2a.Orientation, com2b.Orientation))
            //    {
            //        int four = 4;
            //    }
            //}

            #endregion

            ShipCoreArgs core = new ShipCoreArgs()
            {
                Map           = map,
                Material_Ship = material_Ship,
                World         = world,
            };

            //var construction = await GetNewShipConstructionAsync(options, itemOptions, rotatedDNA, world, material_Ship, material_Projectile, radiation, gravity, cameraPool, map, true, true);
            //var construction = await GetNewShipConstructionAsync(rotatedDNA, world, material_Ship, map, extra);
            var construction = BotConstructor.ConstructBot(rotatedDNA, core, extra);

            return(new ShipPlayer(construction));
        }
        private async void btnLoadShip_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string errMsg;
                ShipDNA shipDNA = ShipEditorWindow.LoadShip(out errMsg);
                if (shipDNA == null)
                {
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        MessageBox.Show(errMsg, this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    return;
                }

                EnsureWorldStarted();

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = chkLoadRepairPositions.IsChecked.Value,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                if (_bot.Fuel != null)
                {
                    _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                }
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void btnShipBoston_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                //TODO: Let the user choose a file
                ShipDNA shipDNA = (ShipDNA)XamlServices.Load(@"C:\Users\charlie.rix\AppData\Roaming\Asteroid Miner\Ships\Beans\2013-05-17 13.50.46.937 - boston - 137.7.xml");

                DateTime startTime = DateTime.UtcNow;

                for (int cntr = 0; cntr < 100; cntr++)
                {
                    ShipExtraArgs extra = new ShipExtraArgs()
                    {
                        Options = _editorOptions,
                        ItemOptions = _itemOptions,
                        Material_Projectile = _material_Bot,
                        Radiation = _radiation,
                        Gravity = _gravity,
                        RunNeural = true,
                        RepairPartPositions = false,
                    };

                    //using (Ship shipTest = await Ship.GetNewShipAsync(_editorOptions, _itemOptions, shipDNA, _world, _material_Ship, _radiation, _gravity, null, true, true)) { }
                    //using (Ship shipTest = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra)) { }          // BAAAAAAAAAD
                    //using (Ship shipTest = await Ship.GetNewShipAsync(_editorOptions, _itemOptions, shipDNA, _world, _material_Ship, _radiation, _gravity, null, false, true)) { }        // GOOD
                }

                TimeSpan elapsed = DateTime.UtcNow - startTime;

                //using (Ship shipTest = await Ship.GetNewShipAsync(_editorOptions, _itemOptions, shipDNA, _world, _material_Ship, _radiation, _gravity, null, true, false)) { }          // BAAAAAAAAAD

                ClearCurrent();

                //_shipDNA = shipDNA;
                //_ship = ship;

                //_ship.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                //_thrustController = new ThrustController(_ship, _viewport, _itemOptions);

                ////double mass = _ship.PhysicsBody.Mass;

                //_ship.Fuel.QuantityCurrent = _ship.Fuel.QuantityMax;
                //_ship.RecalculateMass();
                //_thrustController.MassChanged();

                //if (chkShipDebugVisuals.IsChecked.Value)
                //{
                //    _thrustController.DrawDebugVisuals_Pre();
                //}

                ////mass = _ship.PhysicsBody.Mass;

                //_map.AddItem(_ship);

                grdViewPort.Focus();

                MessageBox.Show(elapsed.TotalMilliseconds.ToString("N0"), this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void btnShipChallenge2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.611527511599856, 0, 0.0153375982352619), Orientation = new Quaternion(0, -0.706493084706277, 0, 0.707719945502605), Scale = new Vector3D(4.70545346938791, 4.70545346938791, 1.04748080326409) });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1.48216852903668, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1.65021551755816, 1.65021551755816, 1.65021551755816), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60730396412872, 1.18811621237628, -0.0147591913688635), Orientation = new Quaternion(0, 0, -0.846976393198269, 0.531630500784946), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60721450068017, -1.18828382189838, -0.0147591913688617), Orientation = new Quaternion(0, 0, -0.496864090131338, 0.867828367788216), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });

                ShipDNA shipDNA = ShipDNA.Create(parts);

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #17
0
        //TODO: Make a static method off of Ship, and don't rely on world: public static Visual3D CreateVisual(ShipDNA dna, bool isDesign)
        private async Task RenderShipAsync(NewtonDynamics.World world)
        {
            ShipExtraArgs args = new ShipExtraArgs()
            {
                RunNeural = false,
                RepairPartPositions = false,
            };

            //using (Ship ship = await Ship.GetNewShipAsync(this.ShipDNA, world, 0, null, args))
            using (Bot bot = new Bot(BotConstructor.ConstructBot(this.ShipDNA, new ShipCoreArgs() { World = world }, args)))
            {
                if (bot.PhysicsBody.Visuals != null)		// this will never be null
                {
                    // The model coords may not be centered, so move the ship so that it's centered on the origin
                    Point3D minPoint, maxPoint;
                    bot.PhysicsBody.GetAABB(out minPoint, out maxPoint);
                    Vector3D offset = (minPoint + ((maxPoint - minPoint) / 2d)).ToVector();

                    bot.PhysicsBody.Position = (-offset).ToPoint();

                    // Add the visuals
                    foreach (Visual3D visual in bot.PhysicsBody.Visuals)
                    {
                        _viewport.Children.Add(visual);
                    }

                    // Pull the camera back to a good distance
                    _camera.Position = (_camera.Position.ToVector().ToUnit() * (bot.Radius * 2.1d)).ToPoint();
                }
            }
        }
Пример #18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                _itemOptions = new ItemOptions();
                _itemOptions.Thruster_StrengthRatio *= 4.5;
                _itemOptions.FuelToThrustRatio *= .03;
                _itemOptions.Projectile_Color = UtilityWPF.ColorFromHex("FFE330");        // using bee/wasp colors, because white looks too much like the stars

                _progressBars = new ShipProgressBarManager(pnlProgressBars);
                _progressBars.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("BBB"));

                #region Init World

                // Set the size of the world to something a bit random (gets boring when it's always the same size)
                double halfSize = 325 + StaticRandom.Next(500);
                //halfSize *= 2;
                _boundryMin = new Point3D(-halfSize, -halfSize, -35);
                _boundryMax = new Point3D(halfSize, halfSize, 35);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                // Draw the lines
                _boundryLines = new ScreenSpaceLines3D(true);
                _boundryLines.Thickness = 1d;
                _boundryLines.Color = WorldColors.BoundryLines;
                _viewport.Children.Add(_boundryLines);

                foreach (Point3D[] line in innerLines)
                {
                    _boundryLines.AddLine(line[0], line[1]);
                }

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Ship
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ship = _materialManager.AddMaterial(material);

                // Exploding Ship
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                _material_ExplodingShip = _materialManager.AddMaterial(material);

                // Space Station (force field)
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                //material.Elasticity = .99d;       // uncomment these if it should be collidable (it's an ellipse, and briefly shows a force field)
                //material.StaticFriction = .02d;
                //material.KineticFriction = .01d;
                _material_SpaceStation = _materialManager.AddMaterial(material);

                //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Asteroid, Collision_SpaceStation);
                //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Mineral, Collision_SpaceStation);

                // Mineral
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .5d;
                material.StaticFriction = .9d;
                material.KineticFriction = .4d;
                _material_Mineral = _materialManager.AddMaterial(material);

                // Asteroid
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .25d;
                material.StaticFriction = .9d;
                material.KineticFriction = .75d;
                _material_Asteroid = _materialManager.AddMaterial(material);

                // Projectile
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .95d;
                _material_Projectile = _materialManager.AddMaterial(material);

                // Swarmbot
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .95d;
                _material_SwarmBot = _materialManager.AddMaterial(material);

                // Collisions
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Mineral, Collision_ShipMineral);
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Asteroid, Collision_ShipAsteroid);
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Projectile, Collision_ShipProjectile);

                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Projectile, Collision_AsteroidProjectile);
                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_SwarmBot, Collision_AsteroidSwarmBot);
                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Asteroid, Collision_AsteroidAsteroid);

                #endregion
                #region Trackball

                //TODO: Only use this when debugging the scene

                //// Trackball
                //_trackball = new TrackBallRoam(_camera);
                //_trackball.KeyPanScale = 15d;
                //_trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                //_trackball.AllowZoomOnMouseWheel = true;
                //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                ////_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                //_trackball.ShouldHitTestOnOrbit = true;

                #endregion
                #region Map

                _map = new Map(_viewport, null, _world);
                //_map.SnapshotFequency_Milliseconds = 250;     // just use the map's default values
                //_map.SnapshotMaxItemsPerNode = 13;
                _map.ShouldBuildSnapshots = true;
                _map.ShouldShowSnapshotLines = false;
                _map.ShouldSnapshotCentersDrift = true;

                _map.ItemRemoved += new EventHandler<MapItemArgs>(Map_ItemRemoved);

                #endregion
                #region Radiation

                //TODO: Make radiation sources instead of a constant ambient -- sort of mini stars, or something manmade looking
                _radiation = new RadiationField()
                {
                    AmbientRadiation = 1,
                };

                #endregion
                #region UpdateManager

                //TODO: UpdateManager needs to inspect types as they are added to the map (map's ItemAdded event)
                _updateManager = new UpdateManager(
                    new Type[] { typeof(ShipPlayer), typeof(SpaceStation2D), typeof(Projectile), typeof(Asteroid), typeof(SwarmBot1b) },
                    new Type[] { typeof(ShipPlayer), typeof(SwarmBot1b) },
                    _map);

                #endregion
                #region Brush Strokes

                _brushStrokes = new SwarmObjectiveStrokes(_world.WorldClock, _itemOptions.SwarmBay_BirthSize * 4, 6);

                // This would be for drawing the strokes
                //_brushStrokes.PointsChanged += BrushStrokes_PointsChanged;

                #endregion
                #region Player

                _player = new Player();
                _player.Credits = 10;

                _player.ShipChanged += new EventHandler<ShipChangedArgs>(Player_ShipChanged);

                #endregion
                #region Minimap

                _miniMap = new MinimapHelper(_map, _viewportMap);

                #endregion
                #region Camera Helper

                _cameraHelper = new CameraHelper(_player, _camera, _cameraMap, _miniMap);

                #endregion
                #region MapPopulationManager

                _mapPopulationManager = new MapPopulationManager(_map, _world, new Point3D(_boundryMin.X, _boundryMin.Y, 0), new Point3D(_boundryMax.X, _boundryMax.Y, 0), _material_Asteroid, _material_Mineral, GetAsteroidMassByRadius, GetMineralsFromDestroyedAsteroid, ItemOptionsAstMin2D.MINASTEROIDRADIUS);
                _updateManager.AddNonMapItem(_mapPopulationManager, TokenGenerator.NextToken());

                #endregion
                #region MapForcesManager

                _mapForcesManager = new MapForcesManager(_map, _boundryMin, _boundryMax);
                _updateManager.AddNonMapItem(_mapForcesManager, TokenGenerator.NextToken());

                #endregion
                #region BackImageManager

                _backImageManager = new BackImageManager(backgroundCanvas, _player);

                #endregion

                #region Ship Extra

                _shipExtra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Material_SwarmBot = _material_SwarmBot,
                    SwarmObjectiveStrokes = _brushStrokes,
                    RunNeural = false,
                    Radiation = _radiation,
                };

                #endregion

                CreateStars3D();      //TODO: Move this to BackImageManager
                                      //CreateStars3DGrid();
                                      //CreateShip(UtilityCore.GetRandomEnum<DefaultShipType>());

                if (!LoadLatestSession())
                {
                    CreateNewSession();
                }

                CreateAsteroids();
                CreateMinerals();
                //CreateProjectile();

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void ShipBot1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ClearBot_Click(this, e);

                #region DNA

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

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.44329742616787, -2.22044604925031E-16, -0.750606111984116), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = AmmoBox.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.44329742616787, -2.22044604925031E-16, -0.839035218662306), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = ProjectileGun.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.139350859269598, -2.22044604925031E-16, 0.0736057604093046), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.443930484830668, -2.22044604925031E-16, -0.0296267373083678), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(1.17108888679796, 2.22044604925031E-16, -0.787190712968899), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new BrainRGBRecognizerDNA() { PartType = BrainRGBRecognizer.PARTTYPE, Orientation = new Quaternion(3.91881768803066E-16, -0.264772715428398, 1.07599743798686E-16, 0.964310846752577), Position = new Point3D(0.977003177386146, 0, -0.204027736848604), Scale = new Vector3D(1, 1, 1) });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    World = _world,
                    Material_Ship = _material_Bot,
                    Map = _map,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    CameraPool = _cameraPool,
                    IsPhysicsStatic = true,
                };

                //DefenseBot bot = DefenseBot.GetNewDefenseBotAsync(dna, _world, _material_Bot, _map, extra).Result;        // can't directly call result.  it deadlocks this main thread
                //DefenseBot bot = await DefenseBot.GetNewDefenseBotAsync(dna, _world, _material_Bot, _map, extra);
                //bot.PhysicsBody.Position = new Point3D(0, 0, -12);

                //_map.AddItem(bot);
                //_bot = bot;




                BotConstruction_Result result = BotConstructor.ConstructBot(parts, core, extra);
                Bot botNew = new Bot(result);

                botNew.Dispose();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #20
0
        public static ShipPlayer GetNewShip(ShipDNA dna, World world, int material_Ship, Map map, ShipExtraArgs extra)
        {
            ShipDNA rotatedDNA = RotateDNA_FromExternal(dna);

            #region asserts

            //ShipDNA rockedDNA1 = RotateDNA_ToExternal(RotateDNA_FromExternal(dna));
            //ShipDNA rockedDNA2 = RotateDNA_FromExternal(rockedDNA1);

            //var compare1a = dna.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare1b = rockedDNA1.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //var compare2a = rotatedDNA.PartsByLayer.SelectMany(o => o.Value).ToArray();
            //var compare2b = rockedDNA2.PartsByLayer.SelectMany(o => o.Value).ToArray();

            //for(int cntr = 0; cntr < compare1a.Length; cntr++)
            //{
            //    var com1a = compare1a[cntr];
            //    var com1b = compare1b[cntr];

            //    var com2a = compare2a[cntr];
            //    var com2b = compare2b[cntr];

            //    if(!Math3D.IsNearValue(com1a.Position, com1b.Position))
            //    {
            //        int three = 3;
            //    }
            //    if (!Math3D.IsNearValue(com1a.Orientation, com1b.Orientation))
            //    {
            //        int three = 3;
            //    }

            //    if (!Math3D.IsNearValue(com2a.Position, com2b.Position))
            //    {
            //        int four = 4;
            //    }
            //    if (!Math3D.IsNearValue(com2a.Orientation, com2b.Orientation))
            //    {
            //        int four = 4;
            //    }
            //}

            #endregion

            ShipCoreArgs core = new ShipCoreArgs()
            {
                Map = map,
                Material_Ship = material_Ship,
                World = world,
            };

            //var construction = await GetNewShipConstructionAsync(options, itemOptions, rotatedDNA, world, material_Ship, material_Projectile, radiation, gravity, cameraPool, map, true, true);
            //var construction = await GetNewShipConstructionAsync(rotatedDNA, world, material_Ship, map, extra);
            var construction = BotConstructor.ConstructBot(rotatedDNA, core, extra);

            return new ShipPlayer(construction);
        }
        private void btnAddBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //TODO: Implement:
                //  ConverterMatterToFuel
                //  ConverterMatterToEnergy

                //_itemOptions.CameraColorRGBNeuronDensity = 160 * 3;

                #region DNA

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

                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 1.43121944558768), Scale = new Vector3D(2.7969681248785, 2.7969681248785, 0.754175785992705) });

                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.617709955450103, 0, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-2.16134944924876E-05, -0.60985890545398, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.00387496389974934, 0.618396858731443, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.624666220599071, 0.00100528924605325, -1.17934947097654), Scale = new Vector3D(1.27861383329322, 1.27861383329322, 1.2242161981366) });

                parts.Add(new ShipPartDNA() { PartType = CargoBay.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.850947345148112, -0.0019217800299223, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00589599969475301, 0.850929089078933, -0.1657062616585), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00522521361558187, -0.850933472485232, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });
                parts.Add(new ShipPartDNA() { PartType = Brain.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.850949515219971, 0, -0.165706261658499), Scale = new Vector3D(0.730753808122994, 0.730753808122994, 0.730753808122994) });

                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToFuel.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.232899395582397, -0.238935114546265, 0.773100284172734), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713) });
                parts.Add(new ShipPartDNA() { PartType = ConverterMatterToEnergy.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.22797553388197, 0.226717979419686, 0.775967026847012), Scale = new Vector3D(0.903613735551713, 0.903613735551713, 0.903613735551713) });

                parts.Add(new ShipPartDNA() { PartType = SensorSpin.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0.262933776282848, 0.240405245709603, 0.755961022082205), Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.250217552102507, -0.280865739393283, 0.743561713316594), Scale = new Vector3D(0.399083346950047, 0.399083346950047, 0.236501125779081) });       // This is just a placeholder for a future sensor (need to put something here so mass is balanced)

                parts.Add(new ShipPartDNA() { PartType = CameraColorRGB.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00208559296997747, 0, 2.00222812584528), Scale = new Vector3D(1, 1, 1) });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(-0.00137913748707474, 0, -1.20661030017992), Scale = new Vector3D(1.29260597488229, 1.29260597488229, 1.29260597488229), ThrusterType = ThrusterType.One });

                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(-0.623025498564933, -0.775855164007238, -0.0622612340741654, 0.0775340657568128), Position = new Point3D(0.189965645143804, -0.859019870524953, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.948585651195026, -0.300495041099996, 0.0947956598959211, 0.0300295768554372), Position = new Point3D(-0.719304806310003, 0.506559650891123, 0.883258802478371), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = new Quaternion(0.304146575685315, -0.947421167104513, 0.0303944881633535, 0.0946792887093452), Position = new Point3D(0.715381156965589, 0.512085817563994, 0.883258802478369), Scale = new Vector3D(0.522840753255495, 0.522840753255495, 0.522840753255495), ThrusterType = ThrusterType.One });

                ShipDNA dna = ShipDNA.Create(parts);
                dna.ShipLineage = Guid.NewGuid().ToString();

                #endregion

                ShipCoreArgs core = new GameItems.ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Radiation = _radiation,
                    CameraPool = _cameraPool,
                };

                //Swimbot bot = await Swimbot.GetNewSwimbotAsync(dna, _world, _material_Bot, _map, extra);
                Swimbot bot = new Swimbot(BotConstructor.ConstructBot(dna, core, extra));
                bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Bot_ApplyForceAndTorque);

                bot.PhysicsBody.Rotation = Math3D.GetRandomRotation();
                bot.PhysicsBody.Position = Math3D.GetRandomVector_Spherical(BOUNDRYSIZEHALF * .5d).ToPoint();

                //bot.PhysicsBody.Position = new Point3D(0, 0, BOUNDRYSIZEHALF * -.75d);

                if (bot.Energy != null)
                {
                    bot.Energy.QuantityCurrent = bot.Energy.QuantityMax * .5d;
                }
                if (bot.Fuel != null)
                {
                    bot.Fuel.QuantityCurrent = bot.Fuel.QuantityMax * .5d;
                }
                bot.RecalculateMass();

                _map.AddItem(bot);
                _bots.Add(bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void btnShipBasic_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(-.75, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1, 1, 1) });
                parts.Add(new ShipPartDNA() { PartType = EnergyTank.PARTTYPE, Position = new Point3D(.75, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1, 1, 1) });

                ShipDNA shipDNA = ShipDNA.Create(parts);

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Ship, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _map.AddItem(_bot);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }