예제 #1
0
        public void testColonyCost()
        {
            // @todo
            // test for humans on earth

            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
        }
예제 #2
0
        public void testColonyTemperatureCost()
        {
            Entity tempPlanet;
            double idealTemp;
            double tempRange;
            double expected;

            tempPlanet = setEarthPlanet();

            List <Entity> species = new List <Entity>();

            species.Add(_lowTempSpecies);
            species.Add(_highTempSpecies);
            species.Add(_humanSpecies);

            // Check each species - more can be added above
            foreach (Entity spec in species)
            {
                idealTemp = spec.GetDataBlob <SpeciesDB>().BaseTemperature;
                tempRange = spec.GetDataBlob <SpeciesDB>().TemperatureToleranceRange;

                // Check a wide variety of temperatures
                for (float temp = -200; temp < 500; temp++)
                {
                    tempPlanet.GetDataBlob <SystemBodyInfoDB>().BaseTemperature = temp;
                    expected = Math.Abs((idealTemp + 273.15) - (temp + 273.15)) / tempRange;
                    expected = Math.Max(1.0, expected);
                    Assert.AreEqual(expected, SpeciesProcessor.ColonyCost(tempPlanet, spec.GetDataBlob <SpeciesDB>()));
                }
            }

            //throw (new NotImplementedException());
            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
        }
예제 #3
0
        private Dictionary <Entity, long> calcGrowthIteration(Entity colony, Dictionary <Entity, long> lastPop)
        {
            // Get current population
            Dictionary <Entity, long> returnPop = new Dictionary <Entity, long>();
            Entity colonyPlanet    = colony.GetDataBlob <ColonyInfoDB>().PlanetEntity;
            var    instancesDB     = colony.GetDataBlob <ComponentInstancesDB>();
            var    popSupportTypes = instancesDB.GetDesignsByType(typeof(PopulationSupportAtbDB));


            long popSupportValue = 0;

            foreach (var design in popSupportTypes)
            {
                var designValue = design.GetAttribute <PopulationSupportAtbDB>().PopulationCapacity;
                var numberOf    = instancesDB.GetNumberOfComponentsOfDesign(design.Guid);
                popSupportValue = designValue * numberOf;
            }


            returnPop.Clear();


            long needsSupport = 0;

            foreach (KeyValuePair <Entity, long> kvp in lastPop)
            {
                // count the number of different population groups that need infrastructure support
                if (SpeciesProcessor.ColonyCost(colonyPlanet, kvp.Key.GetDataBlob <SpeciesDB>()) > 1.0)
                {
                    needsSupport++;
                }
            }

            foreach (KeyValuePair <Entity, long> kvp in lastPop.ToArray())
            {
                double colonyCost = SpeciesProcessor.ColonyCost(colonyPlanet, kvp.Key.GetDataBlob <SpeciesDB>());
                long   maxPopulation;
                long   newPop;

                if (colonyCost > 1.0)
                {
                    maxPopulation = popSupportValue / needsSupport;
                }
                else
                {
                    maxPopulation = -1;
                }

                newPop = calcNewPop(kvp.Value, maxPopulation);

                returnPop.Add(kvp.Key, newPop);
            }

            return(returnPop);
        }
예제 #4
0
        public void testColonyGasCost()
        {
            Entity testPlanet;
            double expected;
            float  oRatio;

            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    if (i + j > 40) // pressure too high, would fail the pressure test
                    {
                        continue;
                    }

                    AtmosphereDB testAtmosphereDB;
                    atmoGasses.Clear();

                    atmoGasses.Add(_gasDictionary["N"], i * 0.1f);
                    atmoGasses.Add(_gasDictionary["O"], j * 0.1f);

                    testAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                    testPlanet       = setAtmosphere(testAtmosphereDB);

                    if (i + j == 0)
                    {
                        oRatio = 0.0f;
                    }
                    else
                    {
                        oRatio = j * 1.0f / (i + j);
                    }

                    if (j < 1 || j > 3)
                    {
                        expected = 2.0;
                    }
                    else if (oRatio <= 0.30f && j >= 1)
                    {
                        expected = 1.0;
                    }
                    else
                    {
                        expected = 2.0;
                    }

                    Assert.AreEqual(expected, SpeciesProcessor.ColonyCost(testPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
                }
            }

            //throw (new NotImplementedException());
        }
예제 #5
0
        private Dictionary <Entity, long> calcGrowthIteration(Entity colony, Dictionary <Entity, long> lastPop)
        {
            // Get current population
            Dictionary <Entity, long> returnPop = new Dictionary <Entity, long>();
            Entity colonyPlanet = colony.GetDataBlob <ColonyInfoDB>().PlanetEntity;
            var    instancesDB  = colony.GetDataBlob <ComponentInstancesDB>();
            List <KeyValuePair <Entity, List <Entity> > > infrastructure = EntityStoreHelpers.GetComponentsOfType <PopulationSupportAtbDB>(instancesDB.SpecificInstances);
            //colony.GetDataBlob<ComponentInstancesDB>().SpecificInstances.Where(item => item.Key.HasDataBlob<PopulationSupportAtbDB>()).ToList();
            long popSupportValue;

            //  Pop Cap = Total Population Support Value / Colony Cost
            // Get total popSupport
            popSupportValue = 0;

            returnPop.Clear();

            foreach (var installation in infrastructure)
            {
                popSupportValue += installation.Key.GetDataBlob <PopulationSupportAtbDB>().PopulationCapacity;
            }

            long needsSupport = 0;

            foreach (KeyValuePair <Entity, long> kvp in lastPop)
            {
                // count the number of different population groups that need infrastructure support
                if (SpeciesProcessor.ColonyCost(colonyPlanet, kvp.Key.GetDataBlob <SpeciesDB>()) > 1.0)
                {
                    needsSupport++;
                }
            }

            foreach (KeyValuePair <Entity, long> kvp in lastPop.ToArray())
            {
                double colonyCost = SpeciesProcessor.ColonyCost(colonyPlanet, kvp.Key.GetDataBlob <SpeciesDB>());
                long   maxPopulation;
                long   newPop;

                if (colonyCost > 1.0)
                {
                    maxPopulation = popSupportValue / needsSupport;
                }
                else
                {
                    maxPopulation = -1;
                }

                newPop = calcNewPop(kvp.Value, maxPopulation);

                returnPop.Add(kvp.Key, newPop);
            }

            return(returnPop);
        }
예제 #6
0
        public void testColonyPressureCost()
        {
            Entity testPlanet;
            double idealPressure;
            double maxPressure;
            double expected;
            float  totalPressure;

            idealPressure = _humanSpecies.GetDataBlob <SpeciesDB>().BasePressure;
            maxPressure   = _humanSpecies.GetDataBlob <SpeciesDB>().MaximumPressureConstraint;

            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            for (float i = 0.3f; i < 10.0; i += 0.1f)
            {
                AtmosphereDB testAtmosphereDB;
                atmoGasses.Clear();

                // Keep atmosphere breathable
                atmoGasses.Add(_gasDictionary["N"], (float)(2.0f * i));
                totalPressure = 2.0f * i;
                atmoGasses.Add(_gasDictionary["O"], 0.1f);
                totalPressure += 0.1f;



                testAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                testPlanet       = setAtmosphere(testAtmosphereDB);

                if (totalPressure > 4.0)
                {
                    expected = 2.0;
                }
                else
                {
                    expected = 1.0;
                }
                Assert.AreEqual(expected, SpeciesProcessor.ColonyCost(testPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
            }


            // Check with pressure from just one gas and multiple gases


            //throw (new NotImplementedException());
            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
        }
예제 #7
0
        public void testColonyGravityIsHabitable()
        {
            // @todo: set up two nested loops - one for list of species, one for list of gravities
            // test a large number of different inputs

            // set _earthPlanet to have earth gravity (1.0)
            _earthPlanet.GetDataBlob <SystemBodyInfoDB>().Gravity = 1.0;

            // test for humans on a planet with low gravity
            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_lowGravPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));

            // test for humans on a planet with high gravity
            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_highGravPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));

            // similar tests as above, but for a species with high and low ideal gravity
            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _lowGravSpecies.GetDataBlob <SpeciesDB>()));
            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_highGravPlanet, _lowGravSpecies.GetDataBlob <SpeciesDB>()));
            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_lowGravPlanet, _lowGravSpecies.GetDataBlob <SpeciesDB>()));

            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _highGravSpecies.GetDataBlob <SpeciesDB>()));
            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_highGravPlanet, _highGravSpecies.GetDataBlob <SpeciesDB>()));
            Assert.AreEqual(-1.0, SpeciesProcessor.ColonyCost(_lowGravPlanet, _highGravSpecies.GetDataBlob <SpeciesDB>()));
        }
예제 #8
0
        public void testColonyToxicityCost()
        {
            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true
            };
            NameDB earthNameDB = new NameDB("Earth");
            double expectedCost;
            string gasSym;

            Dictionary <string, AtmosphericGasSD> lowToxicGases, highToxicGases, benignGases;
            AtmosphericGasSD oxygenGas;

            lowToxicGases  = new Dictionary <string, AtmosphericGasSD>();
            highToxicGases = new Dictionary <string, AtmosphericGasSD>();
            benignGases    = new Dictionary <string, AtmosphericGasSD>();
            oxygenGas      = new AtmosphericGasSD();

            //Separate all the gases into the lists above
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp in _gasDictionary)
            {
                gasSym = kvp.Key;
                if (gasSym == "H2" || gasSym == "CH4" || gasSym == "NH3" || gasSym == "CO" || gasSym == "NO" || gasSym == "H2S" || gasSym == "NO2" || gasSym == "SO2")
                {
                    lowToxicGases.Add(gasSym, kvp.Value);
                }
                else if (gasSym == "Cl2" || gasSym == "F2" || gasSym == "Br2" || gasSym == "I2")
                {
                    highToxicGases.Add(gasSym, kvp.Value);
                }
                else if (gasSym == "O")
                {
                    oxygenGas = kvp.Value;
                }
                else
                {
                    benignGases.Add(gasSym, kvp.Value);
                }
            }

            // @todo: set up two nested loops - one for list of species, one for list of gases
            // test a large number of different inputs
            AtmosphereDB weirdAtmosphereDB;
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            // Test the "low" toxic gases (colony cost 2.0 minimum
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp in lowToxicGases)
            {
                expectedCost = 2.0;
                gasSym       = kvp.Key;
                atmoGasses.Clear();
                atmoGasses.Add(_gasDictionary[gasSym], 0.1f);
                weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
            }

            // Test the "high" toxic gases (colony cost 3.0 minimum)
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp in highToxicGases)
            {
                expectedCost = 3.0;
                gasSym       = kvp.Key;
                atmoGasses.Clear();
                atmoGasses.Add(_gasDictionary[gasSym], 0.1f);
                weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
            }

            // Test the "benign" toxic gases (no affect on colony cost, but no oxygen means 2.0)
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp in lowToxicGases)
            {
                expectedCost = 2.0;
                gasSym       = kvp.Key;
                atmoGasses.Clear();
                atmoGasses.Add(_gasDictionary[gasSym], 0.1f);
                weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
            }

            // test with atmposheres composed of two toxic gases that have the same colony cost
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in lowToxicGases)
            {
                foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in lowToxicGases)
                {
                    expectedCost = 2.0;
                    string gasSym1 = kvp1.Key;
                    string gasSym2 = kvp2.Key;
                    if (gasSym1 == gasSym2)
                    {
                        continue;
                    }

                    atmoGasses.Clear();
                    atmoGasses.Add(lowToxicGases[gasSym1], 0.1f);
                    atmoGasses.Add(lowToxicGases[gasSym2], 0.1f);
                    weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                    _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                    Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
                }
            }

            // test with atmposheres composed of two toxic gases that have the same colony cost
            foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in highToxicGases)
            {
                foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in highToxicGases)
                {
                    expectedCost = 3.0;
                    string gasSym1 = kvp1.Key;
                    string gasSym2 = kvp2.Key;
                    if (gasSym1 == gasSym2)
                    {
                        continue;
                    }

                    atmoGasses.Clear();
                    atmoGasses.Add(highToxicGases[gasSym1], 0.1f);
                    atmoGasses.Add(highToxicGases[gasSym2], 0.1f);
                    weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                    _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                    Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
                }
            }

            // test with atmospheres composed of two toxic gases that have different colony costs

            foreach (KeyValuePair <string, AtmosphericGasSD> kvp1 in lowToxicGases)
            {
                foreach (KeyValuePair <string, AtmosphericGasSD> kvp2 in highToxicGases)
                {
                    expectedCost = 3.0;
                    string gasSym1 = kvp1.Key;
                    string gasSym2 = kvp2.Key;
                    if (gasSym1 == gasSym2)
                    {
                        continue;
                    }

                    atmoGasses.Clear();
                    atmoGasses.Add(lowToxicGases[gasSym1], 0.1f);
                    atmoGasses.Add(highToxicGases[gasSym2], 0.1f);
                    weirdAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?
                    _weirdatmosPlanet = setAtmosphere(weirdAtmosphereDB);

                    Assert.AreEqual(expectedCost, SpeciesProcessor.ColonyCost(_weirdatmosPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
                }
            }


            //Toxic Gasses(CC = 2): Hydrogen(H2), Methane(CH4), Ammonia(NH3), Carbon Monoxide(CO), Nitrogen Monoxide(NO), Hydrogen Sulfide(H2S), Nitrogen Dioxide(NO2), Sulfur Dioxide(SO2)
            //Toxic Gasses(CC = 3): Chlorine(Cl2), Florine(F2), Bromine(Br2), and Iodine(I2)
            //Toxic Gasses at 30% or greater of atm: Oxygen(O2) *


            Assert.AreEqual(1.0, SpeciesProcessor.ColonyCost(_earthPlanet, _humanSpecies.GetDataBlob <SpeciesDB>()));
        }
예제 #9
0
        public async Task <SpeciesModel> SpeciesSearch(string url)
        {
            SpeciesModel res = await SpeciesProcessor.GetStarWarsSpeciesInfo(url);

            return(res);
        }