コード例 #1
0
        public virtual ShipDNA GetNewDNA()
        {
            // Create dna for each part using that part's current stats
            List <ShipPartDNA> dnaParts = new List <ShipPartDNA>();

            foreach (PartBase part in _parts.AllPartsArray)
            {
                ShipPartDNA dna = part.GetNewDNA();

                if (_neuronLinks != null && part is INeuronContainer)
                {
                    NeuralUtility.PopulateDNALinks(dna, (INeuronContainer)part, _neuronLinks);
                }

                dnaParts.Add(dna);
            }

            // Build the ship dna
            return(ShipDNA.Create(_dna, dnaParts));
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private static ShipDNA GetDefaultDNA(bool addHomingSensor)
        {
            // Create bot dna (remember the unique ID of the brainneat part)
            var parts = new List <ShipPartDNA>();

            #region misc

            // If there are more than one, give each a unique guid to know which to train (only want to train one at a time)
            parts.Add(new BrainNEATDNA()
            {
                PartType    = BrainNEAT.PARTTYPE,
                Position    = new Point3D(0, 0, 0),
                Orientation = Quaternion.Identity,
                Scale       = new Vector3D(1, 1, 1)
            });

            parts.Add(new ShipPartDNA()
            {
                PartType    = MotionController2.PARTTYPE,
                Position    = new Point3D(0, 0, -.65),
                Orientation = Quaternion.Identity,
                Scale       = new Vector3D(.75, .75, .75)
            });

            #endregion

            #region cargo parts

            // These go in a ring around the brain

            const double RING_Z = 0;

            Point3D[] positions_cargo = Math3D.GetRandomVectors_Circular_EvenDist(3, .66).
                                        Select(o => o.ToPoint3D(RING_Z)).
                                        ToArray();

            Point3D pointTo = new Point3D(0, 0, RING_Z);

            // Make the cargo bay long, because it's storing pole arms
            Vector3D cargo_vect  = pointTo - positions_cargo[0];
            Vector3D cargo_vectX = Vector3D.CrossProduct(cargo_vect, new Vector3D(0, 1, 0));
            Vector3D cargo_vectY = pointTo - positions_cargo[0];

            parts.Add(new ShipPartDNA()
            {
                PartType    = CargoBay.PARTTYPE,
                Position    = positions_cargo[0],
                Orientation = Math3D.GetRotation(new DoubleVector(1, 0, 0, 0, 1, 0), new DoubleVector(cargo_vectX, cargo_vectY)),       // need a double vector because the cargo bay is a box.  The other two are cylinders, so it doesn't matter which way the orth vector is pointing
                Scale       = new Vector3D(.35, .15, 1.35)
            });

            parts.Add(new ShipPartDNA()
            {
                PartType    = EnergyTank.PARTTYPE,
                Position    = positions_cargo[1],
                Orientation = Math3D.GetRotation(new Vector3D(0, 0, 1), pointTo - positions_cargo[1]),
                Scale       = new Vector3D(.6, .6, .15)
            });

            parts.Add(new ShipPartDNA()
            {
                PartType    = PlasmaTank.PARTTYPE,
                Position    = positions_cargo[2],
                Orientation = Math3D.GetRotation(new Vector3D(0, 0, 1), pointTo - positions_cargo[2]),
                Scale       = new Vector3D(.6, .6, .15)
            });

            #endregion

            #region sensors

            int sensorCount = 2;
            if (addHomingSensor)
            {
                sensorCount++;
            }

            Point3D[] positions_sensor = Math3D.GetRandomVectors_Cone_EvenDist(sensorCount, new Vector3D(0, 0, 1), 40, 1.1, 1.1).
                                         Select(o => o.ToPoint() + new Vector3D(0, 0, -.3)).
                                         ToArray();

            // Vision Far
            parts.Add(new SensorVisionDNA()
            {
                PartType     = SensorVision.PARTTYPE,
                Position     = positions_sensor[0],
                Orientation  = Quaternion.Identity,
                Scale        = new Vector3D(1, 1, 1),
                SearchRadius = 60,
                Filters      = new[]
                {
                    SensorVisionFilterType.Nest,
                    SensorVisionFilterType.Bot_Family,
                    SensorVisionFilterType.Bot_Other,
                    SensorVisionFilterType.TreasureBox,
                    SensorVisionFilterType.Weapon_FreeFloating,
                },
            });

            // Vision Near
            parts.Add(new SensorVisionDNA()
            {
                PartType     = SensorVision.PARTTYPE,
                Position     = positions_sensor[1],
                Orientation  = Quaternion.Identity,
                Scale        = new Vector3D(1, 1, 1),
                SearchRadius = 12,
                Filters      = new[]
                {
                    SensorVisionFilterType.Bot_Family,
                    SensorVisionFilterType.Bot_Other,
                    SensorVisionFilterType.Weapon_Attached_Personal,
                    SensorVisionFilterType.Weapon_Attached_Other,
                },
            });

            // Homing
            if (addHomingSensor)
            {
                parts.Add(new ShipPartDNA()
                {
                    PartType    = SensorHoming.PARTTYPE,
                    Position    = positions_sensor[2],
                    Orientation = Quaternion.Identity,
                    Scale       = new Vector3D(1, 1, 1)
                });
            }


            //new ShipPartDNA() { PartType = SensorVision.PARTTYPE, Position = new Point3D(0, 0, 1.5), Orientation = Quaternion.Identity, Scale = new Vector3D(1, 1, 1) },
            //new ShipPartDNA() { PartType = SensorCollision.PARTTYPE, Position = new Point3D(-sensorXY, sensorXY, sensorZ), Orientation = new Quaternion(halfSqrt2,0,0,halfSqrt2), Scale = new Vector3D(1, 1, 1) },
            //new ShipPartDNA() { PartType = SensorHoming.PARTTYPE, Position = new Point3D(-sensorXY, -sensorXY, sensorZ), Orientation = new Quaternion(halfSqrt2,0,0,halfSqrt2), Scale = new Vector3D(1, 1, 1) },
            //new ShipPartDNA() { PartType = SensorVelocity.PARTTYPE, Position = new Point3D(sensorXY, -sensorXY, sensorZ), Orientation = new Quaternion(halfSqrt2,0,0,halfSqrt2), Scale = new Vector3D(1, 1, 1) },

            // gravity is constant, so the only reason it would be needed is if the bot spins around
            //new ShipPartDNA() { PartType = SensorGravity.PARTTYPE, Position = new Point3D(sensorXY, sensorXY, sensorZ), Orientation = new Quaternion(halfSqrt2,0,0,halfSqrt2), Scale = new Vector3D(1, 1, 1) },

            // SensorPain

            #endregion

            return(ShipDNA.Create("ArcBot2", parts));
        }
コード例 #4
0
        private void SetBot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int numThrusters;
                if (!int.TryParse(txtNumThrusters.Text, out numThrusters))
                {
                    MessageBox.Show("Couldn't parse the number of thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                else if (numThrusters < 2)
                {
                    MessageBox.Show("Must have at least two thrusters", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                #region DNA

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

                parts.Add(new ShipPartDNA()
                {
                    PartType = EnergyTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, 0.283735185991315), Scale = new Vector3D(2.05963659008885, 2.05963659008885, 0.301082085094996)
                });

                parts.Add(new ShipPartDNA()
                {
                    PartType = FuelTank.PARTTYPE, Orientation = Quaternion.Identity, Position = new Point3D(0, 0, -0.490401090473184), Scale = new Vector3D(1.92697281805995, 1.92697281805995, 1.1591130722673)
                });

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

                parts.AddRange(GetRandomThrusters(numThrusters, chkRandRotateThrusters.IsChecked.Value, (ThrusterTypeValues)cboThrusterTypes.SelectedItem, chkSomeDestroyed.IsChecked.Value));

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

                #endregion

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

                BotConstruction_Result seed = BotConstructor.ConstructBot(dna, core);
                ControlledThrustBot    bot  = new ControlledThrustBot(seed);

                SetBot(bot);

                // Start looking for a solution immediately
                if (chkBalanceThrusters.IsChecked.Value)
                {
                    BalanceBot_Forward(_bot);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }