public Software()
        {
            /*
             * Initializes a software system with random values.
             * The order of the CompleteChromosome matters.
             * It is the following:
             * 1) MoveTowardsEnd chromosome
             * 2) MoveAwayFromEnd chromosome
             * 3) MoveToPassableTerrain chromosome
             * 4) MoveToNonPassableTerrain chromosome
             * 5) SpendTheLessEnergy chromosome
             * 6) SpendTheMostEnergy chromosome
             * 7) SpendNormalEnergy chromosome
             */
            var minValue = Constants.GenotypeMinvalue;
            var maxValue = Constants.GenotypeMaxValue;

            MoveTowardsEnd = MathematicalOperations.RandomIntegerInRange(minValue, maxValue);
            var moveTowardsEndChromosome = MathematicalOperations.ConvertIntToBinaryString(MoveTowardsEnd);

            MoveAwayFromEnd       = (Constants.GenotypeMaxValue - 1) - MoveTowardsEnd;
            MoveToPassableTerrain = MathematicalOperations.RandomIntegerInRange(minValue, maxValue);
            var moveToPassableTerrainChromosome = MathematicalOperations.ConvertIntToBinaryString(MoveToPassableTerrain);

            MoveToNonPassableTerrain = (Constants.GenotypeMaxValue - 1) - MoveToPassableTerrain;
            SpendTheLessEnergy       = MathematicalOperations.RandomIntegerInRange(minValue, maxValue);
            var spendTheLessEnergyChromosome = MathematicalOperations.ConvertIntToBinaryString(SpendTheLessEnergy);

            SpendTheMostEnergy = (Constants.GenotypeMaxValue - 1) - SpendTheLessEnergy;
            SpendNormalEnergy  = MathematicalOperations.RandomIntegerInRange(minValue, maxValue);
            var spendNormalEnergyChromosome = MathematicalOperations.ConvertIntToBinaryString(SpendNormalEnergy);

            CompleteChromosome = moveTowardsEndChromosome + moveToPassableTerrainChromosome + spendTheLessEnergyChromosome + spendNormalEnergyChromosome;
        }
        private static HardwareModel GenerateHardwareModel(Hardware pHardware)
        {
            HardwareModel model = new HardwareModel
            {
                CameraRange       = pHardware.Camera.Range,
                CameraGenotype    = pHardware.CameraGenotype,
                CameraChromosome  = MathematicalOperations.ConvertIntToBinaryString(pHardware.CameraGenotype),
                EngineCapacity    = pHardware.Engine.MaxTerrainDifficulty,
                EngineGenotype    = pHardware.EngineGenotype,
                EngineChromosome  = MathematicalOperations.ConvertIntToBinaryString(pHardware.EngineGenotype),
                BatteryEnergy     = pHardware.Battery.Energy,
                BatteryGenotype   = pHardware.BatteryGenotype,
                BatteryChromosome = MathematicalOperations.ConvertIntToBinaryString(pHardware.BatteryGenotype)
            };

            return(model);
        }
Пример #3
0
        public Hardware()
        {
            /*
             * Initializes a hardware system with random initial values.
             */

            CameraGenotype  = MathematicalOperations.RandomIntegerInRange(Constants.GenotypeMinvalue, Constants.GenotypeMaxValue);
            BatteryGenotype = MathematicalOperations.RandomIntegerInRange(Constants.GenotypeMinvalue, Constants.GenotypeMaxValue);;
            EngineGenotype  = MathematicalOperations.RandomIntegerInRange(Constants.GenotypeMinvalue, Constants.GenotypeMaxValue);;

            string batteryChromosome = MathematicalOperations.ConvertIntToBinaryString(BatteryGenotype);
            string cameraChromosome  = MathematicalOperations.ConvertIntToBinaryString(CameraGenotype);
            string engineChromosome  = MathematicalOperations.ConvertIntToBinaryString(EngineGenotype);

            // IMPORTANT: The order of the chromosomes in the complete chromosome must stay the same !!!
            CompleteChromosome = batteryChromosome + cameraChromosome + engineChromosome;

            InitializeFields();
        }
        private static SoftwareModel GenerateSoftwareModel(Software pSoftware)
        {
            SoftwareModel model = new SoftwareModel
            {
                MoveTowardsEnd                     = pSoftware.MoveTowardsEnd,
                MoveAwayFromEnd                    = pSoftware.MoveAwayFromEnd,
                MoveToPassableTerrain              = pSoftware.MoveToPassableTerrain,
                MoveToNonPassableTerrain           = pSoftware.MoveToNonPassableTerrain,
                SpendTheLessEnergy                 = pSoftware.SpendTheLessEnergy,
                SpendTheMostEnergy                 = pSoftware.SpendTheMostEnergy,
                SpendNormalEnergy                  = pSoftware.SpendNormalEnergy,
                MoveTowardsEndChromosome           = MathematicalOperations.ConvertIntToBinaryString(pSoftware.MoveTowardsEnd),
                MoveAwayFromEndChromosome          = MathematicalOperations.ConvertIntToBinaryString(pSoftware.MoveAwayFromEnd),
                MoveToPassableTerrainChromosome    = MathematicalOperations.ConvertIntToBinaryString(pSoftware.MoveToPassableTerrain),
                MoveToNonPassableTerrainChromosome = MathematicalOperations.ConvertIntToBinaryString(pSoftware.MoveToNonPassableTerrain),
                SpendTheLessEnergyChromosome       = MathematicalOperations.ConvertIntToBinaryString(pSoftware.SpendTheLessEnergy),
                SpendTheMostEnergyChromosome       = MathematicalOperations.ConvertIntToBinaryString(pSoftware.SpendTheMostEnergy),
                SpendNormalEnergyChromosome        = MathematicalOperations.ConvertIntToBinaryString(pSoftware.SpendNormalEnergy)
            };

            return(model);
        }