Exemple #1
0
        private static NeuronLayer[] CreateNeurons_Layers(SensorVisionDNA dna, ItemOptionsArco itemOptions)
        {
            if (dna.Filters == null || dna.Filters.Length == 0)
            {
                throw new ApplicationException("This method requires filters to be populated");
            }

            var count = GetNeuronCount(dna.Scale, itemOptions.Sensor_NeuronGrowthExponent, itemOptions.VisionSensor_NeuronDensity);

            //TODO: SensorVisionFilterType.Bot will need two layers
            var neuronZs = GetNeuron_Zs(dna.Filters.Length, count.radius);

            Point3D[] staticPositions = new Point3D[] { new Point3D(0, 0, 0) };

            Point3D[] singlePlate = null;
            if (dna.Neurons != null && dna.Neurons.Length > 0)
            {
                var byLayer = NeuralUtility.DivideNeuronLayersIntoSheets(dna.Neurons, neuronZs.z, count.neuronCount);

                // Just use one of the layer's positions to re evenly distribute (first layer with the correct number of neurons - or closest number).
                // Could try to find the nearest between each layer and use the average of each set, but that's a lot of expense with very little payoff
                singlePlate = GetBestNeuronSheet(byLayer, count.neuronCount);
            }

            // Make sure there is a correct number of neurons and apply an even distribution
            singlePlate = NeuralUtility.GetNeuronPositions_Circular_Even(singlePlate, staticPositions, 1d, count.neuronCount, count.radius).
                          Select(o => o.ToPoint()).
                          ToArray();

            // Use the location of neurons in this single layer for all layers.  By making sure that each neuron represents the same point in each
            // layer (and the index of that neuron is the same in each layer), position logic in each tick can be optimized
            return(Enumerable.Range(0, dna.Filters.Length).
                   Select(o => new NeuronLayer()
            {
                FilterType = dna.Filters[o],
                Z = neuronZs.z[o],
                Neurons = singlePlate.
                          Select(p => new Neuron_SensorPosition(new Point3D(p.X, p.Y, neuronZs.z[o]), true, true)).
                          ToArray(),
            }).
                   ToArray());
        }
Exemple #2
0
        public MotionController2(EditorOptions options, ItemOptionsArco itemOptions, ShipPartDNA dna, AIMousePlate mousePlate)
            : base(options, dna, itemOptions.MotionController_Damage.HitpointMin, itemOptions.MotionController_Damage.HitpointSlope, itemOptions.MotionController_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _mousePlate  = mousePlate;

            this.Design = new MotionController2Design(options, true);
            this.Design.SetDNA(dna);

            GetMass(out _mass, out double volume, out double radius, out _scaleActual, dna, itemOptions);

            this.Radius = radius;

            var neurons = CreateNeurons(dna, itemOptions);

            _neuron_rotate_direction_speed = neurons.rot_dirspeed;
            _neuron_rotate_radius          = neurons.rot_radius;
            _neurons_linear = neurons.linear;
            _neurons_all    = UtilityCore.Iterate <Neuron_SensorPosition>(_neuron_rotate_direction_speed, _neuron_rotate_radius, _neurons_linear).ToArray();
        }
Exemple #3
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}");
            }
        }
Exemple #4
0
        public MotionController_Linear_obsolete(EditorOptions options, ItemOptionsArco itemOptions, ShipPartDNA dna, AIMousePlate mousePlate)
            : base(options, dna, itemOptions.MotionController_Damage.HitpointMin, itemOptions.MotionController_Damage.HitpointSlope, itemOptions.MotionController_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _mousePlate  = mousePlate;

            this.Design = new MotionController_LinearDesign_obsolete(options, true);
            this.Design.SetDNA(dna);

            double radius, volume;

            MotionController2.GetMass(out _mass, out volume, out radius, out _scaleActual, dna, itemOptions);

            this.Radius = radius;

            _neurons = SensorVision.CreateNeurons(dna, itemOptions, itemOptions.MotionController_Linear_NeuronDensity, false, false);

            BuildTerrain();

            _distanceMult = _mousePlate.MaxXY / _neurons.Max(o => o.PositionLength);
        }
Exemple #5
0
        public SensorVision(EditorOptions options, ItemOptionsArco itemOptions, SensorVisionDNA dna, Map map)
            : base(options, dna, itemOptions.VisionSensor_Damage.HitpointMin, itemOptions.VisionSensor_Damage.HitpointSlope, itemOptions.VisionSensor_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _map         = map;

            Design = new SensorVisionDesign(options, true);
            Design.SetDNA(dna);

            double radius, volume;

            SensorGravity.GetMass(out _mass, out volume, out radius, out _scaleActual, dna, itemOptions);

            Radius = radius;

            if (dna.Filters == null || dna.Filters.Length == 0)
            {
                _neurons      = CreateNeurons(dna, itemOptions, itemOptions.VisionSensor_NeuronDensity, true, true);
                _neuronLayers = null;
                _allNeurons   = _neurons;

                var distances = GetNeuronAvgDistance(_neurons.Select(o => o.Position.ToPoint2D()).ToArray());
                _neuronDistBetween = distances.distBetween;
                _neuronMaxRadius   = distances.maxRadius;
            }
            else
            {
                _neuronLayers = CreateNeurons_Layers(dna, itemOptions);
                _neurons      = null;
                _allNeurons   = _neuronLayers.
                                SelectMany(o => o.Neurons).
                                ToArray();

                var distances = GetNeuronAvgDistance(_neuronLayers[0].Neurons.Select(o => o.Position.ToPoint2D()).ToArray());     // all the layers have neurons in the same place
                _neuronDistBetween = distances.distBetween;
                _neuronMaxRadius   = distances.maxRadius;
            }

            SearchRadius = dna.SearchRadius;       // need to set this last, because it populates _distProps
        }
Exemple #6
0
        public SensorHoming2D(EditorOptions options, ItemOptionsArco itemOptions, ShipPartDNA dna, Map map, Point3D homePoint, double homeRadius)
            : base(options, dna, itemOptions.HomingSensor_Damage.HitpointMin, itemOptions.HomingSensor_Damage.HitpointSlope, itemOptions.HomingSensor_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _map         = map;

            _homePoint  = homePoint;
            _homeRadius = homeRadius;

            Design = new SensorHoming2DDesign(options, true);
            Design.SetDNA(dna);

            SensorGravity.GetMass(out _mass, out double volume, out double radius, out _scaleActual, dna, itemOptions);

            Radius = radius;

            _neurons = CreateNeurons(dna, itemOptions, itemOptions.HomingSensor_NeuronDensity, true);

            double scale = homeRadius / _neurons.Max(o => o.PositionLength);

            NeuronWorldPositions = _neurons.Select(o => (o.PositionUnit.Value * (o.PositionLength * scale)).ToPoint()).ToArray();
        }
Exemple #7
0
        private readonly double _volume;        // this is used to calculate energy draw

        #endregion

        #region Constructor

        public SensorArcbotWeapon(EditorOptions options, ItemOptionsArco itemOptions, ShipPartDNA dna, IContainer energyTanks)
            : base(options, dna, itemOptions.Sensor_Damage.HitpointMin, itemOptions.Sensor_Damage.HitpointSlope, itemOptions.Sensor_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _energyTanks = energyTanks;

            Design = new SensorArcbotWeaponDesign(options, true);
            Design.SetDNA(dna);

            SensorGravity.GetMass(out _mass, out _volume, out double radius, out _scaleActual, dna, itemOptions);

            Radius = radius;

            _neurons = CreateNeurons(dna, itemOptions, itemOptions.SensorArcbotWeapon_NeuronDensity, true);


            //TODO: Need to know:
            //      the size of the bot --- might just assume a hardcoded value
            //      size of the weapons --- might also just hardcode
            //      access to the bot's weapon, or lack of
            //      access to the current drag plane so that the circle of neurons is accurate
        }
Exemple #8
0
 public ArcBotNPC(BotDNA dna, int level, Point3D position, World world, Map map, KeepItems2D keepItems2D, MaterialIDs materialIDs, Viewport3D viewport, EditorOptions editorOptions, ItemOptionsArco itemOptions, IGravityField gravity, DragHitShape dragPlane, Point3D homingPoint, double homingRadius, bool runNeural, bool repairPartPositions)
     : base(dna, level, position, world, map, keepItems2D, materialIDs, viewport, editorOptions, itemOptions, gravity, dragPlane, homingPoint, homingRadius, runNeural, repairPartPositions)
 {
 }
Exemple #9
0
        private static (Neuron_SensorPosition rot_dirspeed, Neuron_SensorPosition rot_radius, Neuron_SensorPosition[] linear) CreateNeurons(ShipPartDNA dna, ItemOptionsArco itemOptions)
        {
            #region ring - linear

            // Figure out how many to make
            //NOTE: This radius isn't taking SCALE into account.  The other neural parts do this as well, so the neural density properties can be more consistent
            double radius = (dna.Scale.X + dna.Scale.Y) / (2d * 2d);            // XY should always be the same anyway (not looking at Z for this.  Z is just to keep the sensors from getting too close to each other)
            double area   = Math.Pow(radius, itemOptions.MotionController2_NeuronGrowthExponent);

            int neuronCount = (area * itemOptions.MotionController2_NeuronDensity).ToInt_Ceiling();
            neuronCount += 2;       // manually add two for the rotation neruons

            if (neuronCount < 7)
            {
                neuronCount = 7;
            }

            var neuronPositions = SplitNeuronPositions(dna.Neurons);

            // Place them evenly around the perimiter of a circle.
            Vector3D[] linearPositions = NeuralUtility.GetNeuronPositions_CircularShell_Even(neuronPositions?.linear, neuronCount, radius);

            Neuron_SensorPosition[] linearNeurons = linearPositions.
                                                    Select(o => new Neuron_SensorPosition(o.ToPoint(), true, false)).
                                                    ToArray();

            #endregion

            #region interior - rotation

            Neuron_SensorPosition rotateDirSpeed = new Neuron_SensorPosition(new Point3D(-.25, 0, 0), false, false);
            Neuron_SensorPosition rotateRadius   = new Neuron_SensorPosition(new Point3D(.25, 0, 0), true, false);

            #endregion

            return
                (
                rotateDirSpeed,
                rotateRadius,
                linearNeurons
                );
        }