当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.ToPoints方法代码示例

本文整理汇总了C#中BitArray.ToPoints方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.ToPoints方法的具体用法?C# BitArray.ToPoints怎么用?C# BitArray.ToPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitArray的用法示例。


在下文中一共展示了BitArray.ToPoints方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWalkingSteps

    public static LinkedList<Point> GetWalkingSteps(Point start, BitArray goals, bool walkInWater = false, bool nearbyOk = false)
    {
        Bb.ReadBoard();

        if (!goals.ToPoints().Any())
        {
            return null;
        }
        Point[] starts = { start };
        var passable = Solver.GetPassable(true);
        var aStarPassable = new BitArray(passable);
        aStarPassable.Set(start, true);
        if (nearbyOk)
        {
            aStarPassable.Or(goals);
        }
        Func<Point, Point, int> cost = (c, n) => (Bb.Water.Get(n) && !walkInWater) ? 10 : 1;
        var route = Pather.AStar(starts, p => goals.Get(p), aStarPassable, cost, p => 0);
        if (route == null)
        {
            return null;
        }
        var steps = new LinkedList<Point>(route);
        steps.RemoveFirst();
        if (steps.Count > 0 && !passable.Get(steps.Last.Value))
        {
            steps.RemoveLast();
        }
        return steps;
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:30,代码来源:Solver.cs

示例2: ReadBoard


//.........这里部分代码省略.........
                OurSpawnSet.Add(point);
            }

            // Their Spawns
            if (tile.Owner == themId && tile.PumpID == -1)
            {
                TheirSpawns[offset] = true;
                TheirSpawnSet.Add(point);
            }

            // Our Pumps
            if (tile.Owner == usId && tile.PumpID != -1)
            {
                OurPumps[offset] = true;
            }

            // Their Pumps
            if (tile.Owner == themId && tile.PumpID != -1)
            {
                TheirPumps[offset] = true;
            }

            // Neutral Pumps
            if (tile.Owner == 2 && tile.PumpID != -1)
            {
                NeutralPumps[offset] = true;
            }
        }

        // Units
        foreach (Unit unit in BaseAI.units)
        {
            Point point = new Point(unit.X, unit.Y);
            int offset = GetOffset(point);

            // Our Units
            if (unit.Owner == usId)
            {
                OurUnits[offset] = true;
                OurUnitsSet.Add(unit);
                switch (unit.Type)
                {
                    case 0: OurWorkersSet.Add(unit); break;
                    case 1: OurScoutsSet.Add(unit); break;
                    case 2: OurTanksSet.Add(unit); break;
                }
            }

            // Their Units
            if (unit.Owner == themId)
            {
                TheirUnits[offset] = true;
                TheirUnitsSet.Add(unit);
                switch (unit.Type)
                {
                    case 0: TheirWorkersSet.Add(unit); break;
                    case 1: TheirScoutsSet.Add(unit); break;
                    case 2: TheirTanksSet.Add(unit); break;
                }
            }
        }

        var pumps = new BitArray(OurPumps).Or(TheirPumps).Or(NeutralPumps);
        var pumpLookup = BaseAI.pumpStations.ToDictionary(p => p.Id);
        foreach (var p in pumps.ToPoints())
        {
            var tile = tileLookup[p];
            if (!pumpLookup.ContainsKey(tile.PumpID))
            {
                continue;
            }
            var ps = pumpLookup[tile.PumpID];
            pumpLookup.Remove(ps.Id);

            var pump = new Pump(ps, p);
            if (pump.station.SiegeAmount > 0)
            {
                UnderSiege[GetOffset(pump.SW.x, pump.SW.y)] = true;
                UnderSiege[GetOffset(pump.NW.x, pump.NW.y)] = true;
                UnderSiege[GetOffset(pump.SE.x, pump.SE.y)] = true;
                UnderSiege[GetOffset(pump.NE.x, pump.NE.y)] = true;
            }
            if (tile.Owner == usId)
            {
                OurPumpSet.Add(pump);
            }
            else if (tile.Owner == themId)
            {
                TheirPumpSet.Add(pump);
            }
            else
            {
                NeutralPumpSet.Add(pump);
            }
        }

        pumpPointLookup = OurPumpSet.Union(TheirPumpSet).Union(NeutralPumpSet)
            .SelectMany(pump => pump.GetPoints().Select(point => new { ump = pump, oint = point }))
            .ToDictionary(a => a.oint, a => a.ump);
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:101,代码来源:Bb.cs

示例3: MoveFarthestAndAttack

    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);
        }
    }
开发者ID:BobBuehler,项目名称:megaminerai13,代码行数:31,代码来源:Solver.cs

示例4: MoveAndAttack

    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));
    }
开发者ID:BobBuehler,项目名称:megaminerai13,代码行数:45,代码来源:Solver.cs

示例5: Reach

    public static IEnumerable<Point> Reach(Point start, BitArray targets, BitArray passable)
    {
        var open = new Queue<Point>();
        open.Enqueue(start);

        var closed = new HashSet<Point>();

        var targetSet = new HashSet<Point>(targets.ToPoints());

        var reach = new HashSet<Point>();

        while (open.Count > 0)
        {
            Point current = open.Dequeue();
            closed.Add(current);

            if (targets.Get(current))
            {
                reach.Add(current);
                if (reach.Count == targetSet.Count)
                {
                    break;
                }
            }

            foreach (var n in GetNeighbors(current, passable))
            {
                if (!closed.Contains(n))
                {
                    open.Enqueue(n);
                }
            }
        }

        return reach;
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:36,代码来源:Pather.cs


注:本文中的BitArray.ToPoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。