public void BuildTest() { var frequency = 10; var eatMatrix = new FoodMatrix(2, 2, new FillingOfEntireFieldStrategy(frequency)); var creatures = new bool[2, 2]; for (int k = 0; k < 10; k++) { if (k != 9 && FoodMatrixConstants.AddedFoodLevel <= FoodMatrixConstants.MaxFoodLevel) { eatMatrix.Build(creatures); for (int i = 0; i < eatMatrix.Length; i++) for (int j = 0; j < eatMatrix.Height; j++) Assert.IsFalse(eatMatrix.HasMaxFoodLevel(new Point(i, j))); } if (k == 9) { FrequentlyUsedMethods.RaiseFoodLevelToConstantWithBuild(eatMatrix, creatures, FoodMatrixConstants.MaxFoodLevel, frequency); for (int i = 0; i < eatMatrix.Length; i++) for (int j = 0; j < eatMatrix.Height; j++) Assert.IsTrue(eatMatrix.HasMaxFoodLevel(new Point(i, j))); } } }
private void Build( bool[,] creaturesMatrix, int pointX, int pointY, FoodMatrix eatMatrix) { int length = eatMatrix.Length; int height = eatMatrix.Height; var stack = new Stack<Point>(); var visitedCells = new bool[length, height]; stack.Push(new Point(pointX, pointY)); while (stack.Count != 0) { var current = stack.Pop(); visitedCells[current.X, current.Y] = true; if (CommonMethods.IsValid(current, length, height) && !creaturesMatrix[current.X, current.Y]) { if (!eatMatrix.HasMaxFoodLevel(current)) eatMatrix.AddFood(current); foreach (var point in CommonMethods.GetPoints(current)) { if(CommonMethods.IsValid(point, length, height) && !visitedCells[point.X, point.Y]) stack.Push(point); } } } }
public void BuildIsFullTest() { var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy()); var creatures = new bool[2, 2]; eatMatrix.Build(creatures); for (int i = 0; i < eatMatrix.Length; i++) for (int j = 0; j < eatMatrix.Height; j++) Assert.IsTrue(eatMatrix.HasMaxFoodLevel(new Point(i, j)), "Your MaxFoodLevel constant exceeds AddedFoodLevel multiplied by 4"); }
public void BuildWithOneFreeCellTest() { var eatMatrix = new FoodMatrix(2, 2, new FillingFromCornersByWavesStrategy()); var creatures = new bool[2, 2]; creatures[0, 0] = true; creatures[0, 1] = true; creatures[1, 0] = true; FrequentlyUsedMethods.RaiseFoodLevelToConstantWithBuild(eatMatrix, creatures, FoodMatrixConstants.MaxFoodLevel, 1); Assert.IsTrue(eatMatrix.HasMaxFoodLevel(new Point(1, 1))); }
public void Build(bool[,] creatures, FoodMatrix eatMatrix) { for (int i = 0; i < eatMatrix.Length; i++) { for (int j = 0; j < eatMatrix.Height; j++) { if (!creatures[i, j] && !eatMatrix.HasMaxFoodLevel(new Point(i, j)) && _random.Next(100) % _frequency == 0) { eatMatrix.AddFood(new Point(i, j)); } } } }
public void Build(bool[,] creatures, FoodMatrix eatMatrix) { _counterOfTurns++; if(_counterOfTurns % _frequency != 0) return; for (int i = 0; i < eatMatrix.Length; i++) { for (int j = 0; j < eatMatrix.Height; j++) { if (!creatures[i, j] && !eatMatrix.HasMaxFoodLevel(new Point(i, j))) { eatMatrix.AddFood(new Point(i, j)); } } } }
public void Build(bool[,] creatures, FoodMatrix eatMatrix) { _counterOfTurns++; if (_counterOfTurns % _frequency != 0) { return; } for (int i = 0; i < eatMatrix.Length; i++) { for (int j = 0; j < eatMatrix.Height; j++) { if (!creatures[i, j] && !eatMatrix.HasMaxFoodLevel(new Point(i, j))) { eatMatrix.AddFood(new Point(i, j)); } } } }
private void Build( bool[,] creaturesMatrix, int pointX, int pointY, FoodMatrix eatMatrix) { int length = eatMatrix.Length; int height = eatMatrix.Height; var stack = new Stack <Point>(); var visitedCells = new bool[length, height]; stack.Push(new Point(pointX, pointY)); while (stack.Count != 0) { var current = stack.Pop(); visitedCells[current.X, current.Y] = true; if (CommonMethods.IsValid(current, length, height) && !creaturesMatrix[current.X, current.Y]) { if (!eatMatrix.HasMaxFoodLevel(current)) { eatMatrix.AddFood(current); } foreach (var point in CommonMethods.GetPoints(current)) { if (CommonMethods.IsValid(point, length, height) && !visitedCells[point.X, point.Y]) { stack.Push(point); } } } } }