Beispiel #1
0
        public static void Pickup(Beaver picker, IEnumerable <Tile> targets, string resource)
        {
            if (!picker.CanAct() || picker.OpenCarryCapacity() == 0)
            {
                return;
            }

            var targettables = targets.Where(t => t.GetCount(resource) > 0 && picker.Tile._HasNeighbor(t));

            if (targettables.Any())
            {
                var target = targettables.MaxByValue(t => t.GetCount(resource));
                picker.Pickup(target, resource, Math.Min(target.GetCount(resource), picker.OpenCarryCapacity()));
            }
        }
Beispiel #2
0
        public static void MoveAndHarvest(Beaver harvester, IEnumerable <Spawner> spawners)
        {
            if (harvester.OpenCarryCapacity() == 0)
            {
                return;
            }

            if (harvester.CanMove())
            {
                var movePoints = spawners
                                 .SelectMany(s => s.Tile.GetNeighbors().Select(n => n.ToPoint()));

                Move(harvester, movePoints);
            }

            Harvest(harvester, spawners);
        }
Beispiel #3
0
        public static void MoveAndPickup(Beaver picker, IEnumerable <Tile> targets, string resource)
        {
            if (!picker.CanAct() || picker.OpenCarryCapacity() == 0)
            {
                return;
            }

            var targetPoints = targets.Where(t => t.GetCount(resource) > 0);

            if (picker.CanMove())
            {
                var movePoints = targetPoints.Concat(targetPoints.SelectMany(t => t.GetNeighbors()))
                                 .Select(n => n.ToPoint());
                Move(picker, movePoints);
            }

            Pickup(picker, targets, resource);
        }
Beispiel #4
0
        public static void Harvest(Beaver harvester, IEnumerable <Spawner> targets)
        {
            if (!harvester.CanAct() || harvester.OpenCarryCapacity() == 0)
            {
                return;
            }

            var targettables = targets.Where(t => t.Health > 0);
            var target       = targettables.FirstOrDefault(t => harvester.Tile._HasNeighbor(t.Tile));

            if (target != null)
            {
                while (harvester.CanAct() && target.Health > 0)
                {
                    harvester.Harvest(target);
                }
            }
        }