Beispiel #1
0
        protected override DirectionEnum GetDirection(FoodMatrix eatMatrix,
                                                      Membrane[,] creatures, Point position, Random random)
        {
            var points = CommonMethods.GetPoints(position);
            var state  = new Dictionary <int, int>();

            foreach (var point in points)
            {
                var direction = DirectionEx.DirectionByPointsWithNumber(position, point);

                if (CommonMethods.IsValidAndFree(point, creatures))
                {
                    state.Add(direction, eatMatrix.HasOneBite(point) ? 4 : 3);
                }

                if (!CommonMethods.IsValid(point, eatMatrix.Length, eatMatrix.Height))
                {
                    state.Add(direction, 1);
                }
                else
                if (!CommonMethods.IsFree(point, creatures))
                {
                    state.Add(direction, 2);
                }
            }

            var result = _executor.Execute(CommandsForGetDirection, new MyExecutorToolset(random, state));

            return(DirectionEx.DirectionByNumber(int.Parse(result)));
        }
Beispiel #2
0
        public void HasOneBiteIsTrueTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());
            var point = new Point(0, 0);

            FrequentlyUsedMethods.RaiseFoodLevelToConstantWithAddFood(eatMatrix, point, CreatureConstants.OneBite);

            Assert.IsTrue(eatMatrix.HasOneBite(point));
        }
Beispiel #3
0
        public void TakeFoodIsTrueTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());
            var point     = new Point(0, 0);

            FrequentlyUsedMethods.RaiseFoodLevelToConstantWithAddFood(eatMatrix, point, CreatureConstants.OneBite);

            Assert.IsTrue(eatMatrix.HasOneBite(point));

            var counter = FoodMatrixConstants.AddedFoodLevel / CreatureConstants.OneBite;

            for (int i = 0; i < counter; i++)
            {
                Assert.IsTrue(eatMatrix.TakeFood(point));
            }

            Assert.IsFalse(eatMatrix.HasOneBite(point));
        }
Beispiel #4
0
        public void AddFoodTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());
            var point     = new Point(0, 0);

            FrequentlyUsedMethods.RaiseFoodLevelToConstantWithAddFood(eatMatrix, point, CreatureConstants.OneBite);

            Assert.IsTrue(eatMatrix.HasOneBite(point));
        }
Beispiel #5
0
        public void HasOneBiteIsFalseTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());

            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    Assert.IsFalse(eatMatrix.HasOneBite(new Point(i, j)));
                }
            }
        }
Beispiel #6
0
        public void HasOneBiteIsFalseTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());

            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    Assert.IsFalse(eatMatrix.HasOneBite(new Point(i, j)));
                }
            }
        }
Beispiel #7
0
        public void BuildIsEmptyTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());
            var creatures = new bool[2, 2];

            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    creatures[i, j] = true;
                }
            }

            eatMatrix.Build(creatures);
            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    Assert.IsFalse(eatMatrix.HasOneBite(new Point(i, j)));
                }
            }
        }
Beispiel #8
0
        protected override DirectionEnum GetDirection(FoodMatrix eatMatrix, Membrane[,] creatures, Point position, Random random)
        {
            var points             = CommonMethods.GetPoints(position);
            var directions         = new List <DirectionEnum>();
            var directionsWithFood = new List <DirectionEnum>();

            foreach (var item in points)
            {
                if (!CommonMethods.IsValidAndFree(item, creatures))
                {
                    continue;
                }
                directions.Add(DirectionEx.DirectionByPoints(position, item));
                if (eatMatrix.HasOneBite(item))
                {
                    directionsWithFood.Add(DirectionEx.DirectionByPoints(position, item));
                }
            }
            if (directions.Count == 0)
            {
                return(DirectionEnum.Stay);
            }
            return(directionsWithFood.Count == 0 ? directions.ElementAt(random.Next(directions.Count)) : directionsWithFood.ElementAt(random.Next(directionsWithFood.Count)));
        }
Beispiel #9
0
        public void TakeFoodIsTrueTest()
        {
            var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy());
            var point = new Point(0, 0);

            FrequentlyUsedMethods.RaiseFoodLevelToConstantWithAddFood(eatMatrix, point, CreatureConstants.OneBite);

            Assert.IsTrue(eatMatrix.HasOneBite(point));

            var counter = FoodMatrixConstants.AddedFoodLevel / CreatureConstants.OneBite;
            for (int i = 0; i < counter; i++)
            {
                Assert.IsTrue(eatMatrix.TakeFood(point));
            }

            Assert.IsFalse(eatMatrix.HasOneBite(point));
        }
Beispiel #10
0
 private bool HasOneBite(FoodMatrix eatMatrix)
 {
     return(eatMatrix.HasOneBite(Position));
 }