Exemple #1
0
        public UnitCollection Standardize(UnitCollection units)
        {
            UnitCollection standardized = new UnitCollection();

            Vector <double> mean = CalculateMean(units);
            Vector <double> sd   = CalculateStandardDeviation(units, mean);

            foreach (Unit unit in units.List)
            {
                standardized.Add(((unit.ToVector() - mean) / sd).ToArray());
            }

            return(standardized);
        }
Exemple #2
0
        public void TestShouldTurn()
        {
            UnitCollection collection = new UnitCollection();
            Map            map        = new Map(5, 5);

            Units.Tractor tractor = new Units.Tractor(map, new Coordinates(2, 2));
            Tank          tank    = new Tank(map, new Coordinates(3, 3));
            DefenceTower  tower   = new DefenceTower(map, new Coordinates(5, 5));

            collection.Add(tractor);
            collection.Add(tank);
            collection.Add(tower);

            collection.ExecuteCommand(new MoveForwardCommand());

            Assert.AreEqual((uint)2, tractor.Position.X);
            Assert.AreEqual((uint)3, tractor.Position.Y);

            Assert.AreEqual((uint)3, tank.Position.X);
            Assert.AreEqual((uint)4, tank.Position.Y);

            Assert.AreEqual((uint)5, tower.Position.X);
            Assert.AreEqual((uint)5, tower.Position.Y);
        }
Exemple #3
0
        public static void ParseUnits(XDocument document, Instance instance)
        {
            // parse units and add to instance
            // ix:header/ix:resources/xbrli:unit
            var unitNs         = document.Root.GetNamespaceOfPrefix("xbrli");
            var unitElements   = document.Root.Descendants(unitNs + "unit");
            var unitSerializer = new XmlSerializer(typeof(Unit));
            var units          = new UnitCollection(instance);

            foreach (var unitElement in unitElements)
            {
                var unitReader = unitElement.CreateReader();
                var unit       = (Unit)unitSerializer.Deserialize(unitReader);
                units.Add(unit);
            }
            instance.Units = units;
        }
Exemple #4
0
        private UnitCollection CalculateRazings(UnitCollection sourceUnit, decimal lostPower, ref uint junkAmount)
        {
            if (lostPower <= 0.0m)
            {
                return(UnitCollection.Empty);
            }

            var amounts = sourceUnit.GetAll().Where(u => u.Amount > 0).ToArray();

            // split razings between unit types and randomly deduct
            var powerPerAmount = this.Distribute(lostPower, amounts.Length);

            var razedUnits = new UnitCollection();

            for (int i = 0; i < amounts.Length; i++)
            {
                uint razed = Math.Min(amounts[i].Amount, (uint)Math.Round(powerPerAmount[i] / amounts[i].Unit.Defense, 0));
                razedUnits.Add(new UnitAmount(amounts[i].Unit, razed));
            }

            return(razedUnits);
        }
Exemple #5
0
 public void AddLife(Unit unit)
 {
     m_units.Add(unit);
 }