예제 #1
0
 private void Wander()
 {
     LastTargetBush = null;
     if (_random.NextDouble() < Planet.Config.PopWanderTurnChance ||
         !Planet.IsInBounds(Position + _wanderDirection) ||
         !PositionFree(Position + _wanderDirection))
     {
         var directions = Directions.Where(d => PositionFree(Position + d)).ToList();
         if (directions.Any())
         {
             _wanderDirection = _random.Choose <Point>(directions);
         }
     }
     MoveTowards(Position + _wanderDirection);
 }
예제 #2
0
        public void Step()
        {
            Age++;

            if (Age <= Planet.Config.BushMaxGrowAge && Grown && _random.NextFloat() < Planet.Config.BushBerryGrowChance)
            {
                var fertileTiles = Planet.GetCross(Position)
                                   .Where(p => Planet.IsInBounds(p) && Planet.GetFertility(p) >= Planet.Config.BushBerryGrowCost).ToList();

                if (fertileTiles.Count > 0 && Planet.SpendFertility(_random.Choose <Point>(fertileTiles), Planet.Config.BushBerryGrowCost))
                {
                    Berries++;
                }
                if (Berries > Planet.Config.BushMaxBerries)
                {
                    Berries = Planet.Config.BushMaxBerries;
                    Planet.TrySeedBushCross(Position);
                }
            }
        }
예제 #3
0
 private bool PositionFree(Point target) => Planet.IsInBounds(target) && Planet.Population.All(p => p.Position != target) && Planet.Bushes.All(b => b.Position != target);