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 static void RaiseFoodLevelToConstantWithAddFood(FoodMatrix eatMatrix, Point point, int constant) { var counter = 0; while (counter < constant) { eatMatrix.AddFood(point); counter += FoodMatrixConstants.AddedFoodLevel; } }
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); } } } } }