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


C# Unit.ToPoint方法代码示例

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


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

示例1: MoveAndDig

    public static bool MoveAndDig(Unit digger, IEnumerable<Point> targets)
    {
        Bb.ReadBoard();
        var passable = Solver.GetPassable();
        var moveTargets = targets.SelectMany(t => Pather.GetNeighbors(t, passable)).ToBitArray();
        moveTargets.And(targets.ToBitArray().Not());

        if (digger.MovementLeft == 0)
        {
            if (Dig(digger, targets, GetDiggableAndUnDug()))
            {
                return true;
            }
            return false;
        }

        var steps = Solver.GetWalkingSteps(digger.ToPoint(), moveTargets);
        if (steps == null)
        {
            return false;
        }
        foreach (var step in steps)
        {
            if (digger.MovementLeft > 0)
            {
                digger.move(step.x, step.y);
            }
        }
        Dig(digger, targets, GetDiggableAndUnDug());
        return true;
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:31,代码来源:Digger.cs

示例2: Attack

 public static bool Attack(Unit attacker, IEnumerable<Unit> targets)
 {
     var target = targets.FirstOrDefault(t => t.HealthLeft > 0 && Manhattan(attacker.ToPoint(), t.ToPoint()) <= attacker.Range);
     if (target != null)
     {
         attacker.attack(target);
         return true;
     }
     return false;
 }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:10,代码来源:Solver.cs

示例3: Dig

 public static bool Dig(Unit digger, IEnumerable<Point> targets, BitArray diggable)
 {
     foreach (var n in Pather.GetNeighbors(digger.ToPoint(), diggable))
     {
         if (targets.Contains(n))
         {
             digger.dig(Bb.tileLookup[n]);
             return true;
         }
     }
     return false;
 }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:12,代码来源:Digger.cs

示例4: MoveAndAttack

    public static void MoveAndAttack(Unit attacker, IEnumerable<Unit> targets, bool ifInRange = false)
    {
        var alive = targets.Where(t => t.HealthLeft > 0);
        if (!alive.Any())
        {
            return;
        }

        if (Attack(attacker, alive))
        {
            return;
        }

        if (attacker.MovementLeft == 0)
        {
            return;
        }

        var steps = GetWalkingSteps(attacker.ToPoint(), alive.Select(t => t.ToPoint()).ToBitArray(), nearbyOk: true);
        if (steps == null)
        {
            return;
        }

        if (ifInRange)
        {
            int simulationMoves = attacker.MovementLeft;
            foreach (var step in steps)
            {
                simulationMoves--;
                if (simulationMoves < 0)
                {
                    return;
                }
                if (alive.Any(t => Manhattan(t.ToPoint(), step) < attacker.Range))
                {
                    break;
                }
            }
        }

        foreach (var step in steps)
        {
            attacker.move(step.x, step.y);
            if (Attack(attacker, alive) || attacker.MovementLeft == 0)
            {
                return;
            }
        }
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:50,代码来源:Solver.cs

示例5: Move

    public static void Move(Unit unit, BitArray goals, bool walkInWater = false)
    {
        var stepCount = unit.MovementLeft;
        if (stepCount == 0)
        {
            return;
        }

        var steps = GetWalkingSteps(unit.ToPoint(), goals, walkInWater);
        if (steps == null)
        {
            return;
        }
        foreach (Point p in steps)
        {
            if (stepCount == 0)
            {
                return;
            }
            unit.move(p.x, p.y);
            stepCount--;
        }
    }
开发者ID:BobBuehler,项目名称:megaminerai12,代码行数:23,代码来源:Solver.cs


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