public void Tick(IForest forest) { var moves = 0; var gridContents = forest.GridContents(Location); while (moves < 3 && CheckGridAtLocationFor <ITree>(gridContents)) { var spotPossibilities = GetAdjacentSpots(forest.Bound); var desiredSpot = spotPossibilities[_numberGeneratorService.GetNextRandomOfBound(spotPossibilities.Count - 1)]; Location = desiredSpot; moves++; gridContents = forest.GridContents(Location); } if (gridContents == null) { return; } var trees = gridContents.Where(o => o is ITree).ToList(); if (trees.Any()) { CutDown(forest, (ITree)trees.First()); } }
public override void Tick(IForest forest) { var moves = 0; var gridContents = forest.GridContents(Location); while (moves < 5 && CheckGridAtLocationFor <ILumberJack>(gridContents)) { var spotPossibilities = GetAdjacentSpots(forest.Bound); var desiredSpot = spotPossibilities[NumberGeneratorService.GetNextRandomOfBound(spotPossibilities.Count - 1)]; Location = desiredSpot; moves++; gridContents = forest.GridContents(Location); } if (gridContents != null) { var lumberJacks = gridContents.Where(o => o is ILumberJack).ToList(); if (lumberJacks.Any()) { Maul(forest, (ILumberJack)lumberJacks.First()); } } }