Beispiel #1
0
 public void TryAttack(Droid attacker)
 {
     if (attacker.AttacksLeft > 0)
     {
         var targetsInRange = attacker.ToPoint().GetPointsInRange(attacker.Range).Where(p => Targets.Contains(p));
         if (targetsInRange.Any())
         {
             var target = targetsInRange.First();
             while (attacker.AttacksLeft > 0)
             {
                 attacker.operate(target.x, target.y);
             }
         }
     }
 }
Beispiel #2
0
    public static void MoveFarthestAndAttack(Droid attacker, BitArray targets)
    {
        if (attacker.AttacksLeft == 0)
        {
            return;
        }

        var liveTargets = targets.ToPoints().Where(p => Bb.DroidLookup[p].HealthLeft > 0);
        Func<Point, bool> patherPassable = p => IsPassable(p) || p.Equals(attacker.ToPoint());

        var movementSearch = new Pather.Search(new Point[] { attacker.ToPoint() }, patherPassable, p => false, (p1, p2) => 1, attacker.MovementLeft);
        var walkables = movementSearch.GScore.Keys.Where(p => movementSearch.GScore[p] <= attacker.MovementLeft);
        var walkablesWithTargets = walkables.Where(p => liveTargets.Any(t => p.IsInRange(attacker.Range, t)));

        Console.WriteLine("MoveFarthestAndAttack " + attacker.ToPoint());
        Console.WriteLine("Walkables: " + walkables.Count());
        Console.WriteLine("WalkablesWithTargets: " + walkablesWithTargets.Count());

        if (walkablesWithTargets.Any())
        {
            var walkTo = walkablesWithTargets.MaxBy(p => movementSearch.GScore[p]);
            var path = Pather.ConstructPath(movementSearch.CameFrom, walkTo);
            foreach (var step in path.Skip(1))
            {
                Console.WriteLine("Move {0} -> {1}", attacker.ToPoint(), step);
                attacker.move(step.x, step.y);
            }
            var target = liveTargets.First(t => attacker.IsInRange(t));
            attacker.operate(target.x, target.y);
        }
    }
Beispiel #3
0
 public static void TryOperate(Droid droid)
 {
     if (droid.AttacksLeft > 0)
     {
         foreach (var p in droid.ToPoint().GetPointsInRange(droid.Range))
         {
             Droid target;
             if (Bb.DroidLookup.TryGetValue(p, out target))
             {
                 if (droid.IsOperatable(target))
                 {
                     while(droid.AttacksLeft > 0)
                     {
                         droid.operate(target.X, target.Y);
                     }
                 }
             }
         }
     }
 }
Beispiel #4
0
    public static void MoveAndAttack(Droid attacker, BitArray targets)
    {
        Bb.ReadBoard();

        if (attacker.AttacksLeft <= 0)
        {
            return;
        }

        BitArray validTargets;
        if ((Unit)attacker.Variant == Unit.HACKER)
        {
            validTargets = targets.ToPoints().Where(t => t.IsHackable()).ToBitArray();
        }
        else if ((Unit)attacker.Variant == Unit.REPAIRER)
        {
            validTargets = targets.ToPoints().Where(t => t.IsRepairable()).ToBitArray();
        }
        else
        {
            validTargets = targets.ToPoints().Where(t => t.IsAttackable()).ToBitArray();
            if (Bb.KillHangerCountDown > 0)
            {
                validTargets = validTargets.ToPoints().Where(t =>
                    {
                        var droid = Bb.DroidLookup[t];
                        return !((Unit)droid.Variant == Unit.HANGAR && droid.HealthLeft <= attacker.Attack);
                    }).ToBitArray();
            }
        }

        Func<Point, bool> patherPassable = p => IsPassable(p) || p.Equals(attacker.ToPoint()) || validTargets.Get(p);

        var path = Pather.AStar(new[] { attacker.ToPoint() }, patherPassable, validTargets.ToFunc());
        if (path == null)
        {
            return;
        }
        if (path.Count() < 2)
        {
            Console.WriteLine("Bad path from attacker " + attacker.Id);
        }

        MoveAndAttack(attacker, path.Skip(1));
    }