public void ApplyInfluenceToMap_AppliesStrengthToNearbyCells_FromRolloffAndApplierFunctions()
        {
            var center = BuildCell();

            MockGrid.Setup(grid => grid.GetCellsInRing(center, 1)).Returns(new List <IHexCell>()
            {
                BuildCell()
            });
            MockGrid.Setup(grid => grid.GetCellsInRing(center, 2)).Returns(new List <IHexCell>()
            {
                BuildCell(), BuildCell()
            });
            MockGrid.Setup(grid => grid.GetCellsInRing(center, 3)).Returns(new List <IHexCell>()
            {
                BuildCell()
            });

            var map = new float[] { 1f, 2f, 3f, 4f, 5f };

            InfluenceRolloff rolloff = (strength, distance) => strength * distance;
            InfluenceApplier applier = (previous, calculated) => previous + calculated + 2;

            var influenceApplier = Container.Resolve <InfluenceMapApplier>();

            influenceApplier.ApplyInfluenceToMap(10f, map, center, 3, rolloff, applier);

            CollectionAssert.AreEqual(
                new float[] { 13f, 14f, 25f, 26f, 37f }, map
                );
        }
        public void ApplyToMaps_AppliesStrengthOfForeignUnitsAtWarWithCiv_ToEnemyPresence()
        {
            var domesticCiv   = BuildCiv();
            var foreignCivOne = BuildCiv();
            var foreignCivTwo = BuildCiv();

            MockWarCanon.Setup(canon => canon.AreAtWar(foreignCivOne, domesticCiv)).Returns(true);
            MockWarCanon.Setup(canon => canon.AreAtWar(domesticCiv, foreignCivOne)).Returns(true);
            MockWarCanon.Setup(canon => canon.AreAtWar(foreignCivTwo, domesticCiv)).Returns(true);
            MockWarCanon.Setup(canon => canon.AreAtWar(domesticCiv, foreignCivTwo)).Returns(true);

            var cellOne   = BuildCell();
            var cellTwo   = BuildCell();
            var cellThree = BuildCell();
            var cellFour  = BuildCell();

            BuildUnit(cellOne, domesticCiv, 10f);
            BuildUnit(cellTwo, foreignCivOne, 20f);
            BuildUnit(cellThree, domesticCiv, 30f);
            BuildUnit(cellFour, foreignCivTwo, 40f);

            InfluenceRolloff rolloff = (a, b) => 0f;
            InfluenceApplier applier = (a, b) => 0;

            MockInfluenceMapApplier.Setup(mapApplier => mapApplier.PowerOfTwoRolloff).Returns(rolloff);
            MockInfluenceMapApplier.Setup(mapApplier => mapApplier.ApplySum).Returns(applier);

            MockAIConfig.Setup(config => config.UnitMaxInfluenceRadius).Returns(3);

            var maps = new InfluenceMaps()
            {
                AllyPresence = new float[] { 1f }, EnemyPresence = new float[] { 1f, 2f }
            };

            var influenceSource = Container.Resolve <UnitInfluenceSource>();

            influenceSource.ApplyToMaps(maps, domesticCiv);

            MockInfluenceMapApplier.Verify(
                mapApplier => mapApplier.ApplyInfluenceToMap(10f, maps.EnemyPresence, cellOne, 3, rolloff, applier),
                Times.Never, "Influence unexpectedly applied on CellOne"
                );

            MockInfluenceMapApplier.Verify(
                mapApplier => mapApplier.ApplyInfluenceToMap(20f, maps.EnemyPresence, cellTwo, 3, rolloff, applier),
                Times.Once, "Influence not applied on CellTwo as expected"
                );

            MockInfluenceMapApplier.Verify(
                mapApplier => mapApplier.ApplyInfluenceToMap(30f, maps.EnemyPresence, cellThree, 3, rolloff, applier),
                Times.Never, "Influence unexpectedly applied on CellThree"
                );

            MockInfluenceMapApplier.Verify(
                mapApplier => mapApplier.ApplyInfluenceToMap(40f, maps.EnemyPresence, cellFour, 3, rolloff, applier),
                Times.Once, "Influence not applied on CellFour as expected"
                );
        }
Beispiel #3
0
        public void ApplyInfluenceToMap(
            float strength, float[] map, IHexCell center, int maxDistance,
            InfluenceRolloff rolloff, InfluenceApplier applier
            )
        {
            map[center.Index] = applier(map[center.Index], strength);

            for (int i = 1; i <= maxDistance; i++)
            {
                foreach (var cellInRing in Grid.GetCellsInRing(center, i))
                {
                    float effectiveStrength = rolloff(strength, i);

                    map[cellInRing.Index] = applier(map[cellInRing.Index], effectiveStrength);
                }
            }
        }
        public void ApplyInfluenceToMap_AppliesFullStrengthToCenter_WithApplierFunction()
        {
            var center = BuildCell();

            MockGrid.Setup(grid => grid.GetCellsInRing(center, It.IsAny <int>())).Returns(new List <IHexCell>());

            var map = new float[2] {
                3f, 3f
            };

            InfluenceRolloff rolloff = (strength, distance) => 0;
            InfluenceApplier applier = (previous, calculated) => previous + calculated + 2f;

            var influenceApplier = Container.Resolve <InfluenceMapApplier>();

            influenceApplier.ApplyInfluenceToMap(20f, map, center, 2, rolloff, applier);

            CollectionAssert.AreEqual(new float[2] {
                25f, 3f
            }, map);
        }
        public void ApplyToMaps_DoesNothingWithForeignUnitsNotAtWarWithCiv()
        {
            var domesticCiv   = BuildCiv();
            var foreignCivOne = BuildCiv();
            var foreignCivTwo = BuildCiv();

            var cellOne   = BuildCell();
            var cellTwo   = BuildCell();
            var cellThree = BuildCell();
            var cellFour  = BuildCell();

            BuildUnit(cellOne, foreignCivOne, 10f);
            BuildUnit(cellTwo, foreignCivTwo, 20f);
            BuildUnit(cellThree, foreignCivOne, 30f);
            BuildUnit(cellFour, foreignCivTwo, 40f);

            InfluenceRolloff rolloff = (a, b) => 0f;
            InfluenceApplier applier = (a, b) => 0;

            MockInfluenceMapApplier.Setup(mapApplier => mapApplier.PowerOfTwoRolloff).Returns(rolloff);
            MockInfluenceMapApplier.Setup(mapApplier => mapApplier.ApplySum).Returns(applier);

            MockAIConfig.Setup(config => config.UnitMaxInfluenceRadius).Returns(3);

            var maps = new InfluenceMaps()
            {
                AllyPresence = new float[] { 1f }, EnemyPresence = new float[] { 1f, 2f }
            };

            var influenceSource = Container.Resolve <UnitInfluenceSource>();

            influenceSource.ApplyToMaps(maps, domesticCiv);

            MockInfluenceMapApplier.Verify(
                mapApplier => mapApplier.ApplyInfluenceToMap(
                    It.IsAny <float>(), It.IsAny <float[]>(), It.IsAny <IHexCell>(), It.IsAny <int>(),
                    It.IsAny <InfluenceRolloff>(), It.IsAny <InfluenceApplier>()
                    ), Times.Never
                );
        }