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


C# Unit.move方法代码示例

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


在下文中一共展示了Unit.move方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: go

 //Returns false if there's no pieces left to move.
 public bool go()
 {
     //If it's the move phase, move the strongest unit that hasn't moved yet towards
     //the enemy with the highest attack to HP ratio.
     if (phase == Phase.MOVE) {
         unit = getNextUnit();
         if (unit == null) {
             return true;
         }
         target = getPreferredEnemy();
         if (target == null) {
             return true;
         }
         HexPosition[] path = getPath(unit, target);
         //You can freeze the enemy AI by hiding the desired enemy out of reach. I should fix this eventually,
         //and make it go on to the next target or something. Or try to clear a path to that unit.
         if(path == null) {
             unit.skipMove();
         } else {
             unit.move(path);
         }
         phase = Phase.ATTACK;
         //If it's the attack phase, attack the target, or if you haven't gotten close enough,
         //find the best enemy in range to attack. If nobody is in range, do nothing.
     } else {
         if (unit.Coordinates.dist(target.Coordinates) <= unit.RANGE) {
             unit.attack(target);
             phase = Phase.MOVE;
         } else {
             target = null;
             double score = 0;
             foreach (Unit other_unit in units) {
                 if (other_unit.PLAYER == player || unit.Coordinates.dist(other_unit.Coordinates) > unit.RANGE) {
                     continue;
                 }
                 double new_score = other_unit.STRENGTH / other_unit.HP;
                 if (new_score > score) {
                     score = new_score;
                     target = other_unit;
                 }
             }
             if (target != null) {
                 unit.attack (target);
             }
             phase = Phase.MOVE;
         }
     }
     return false;
 }
开发者ID:imposeren,项目名称:unity-learning-hex,代码行数:50,代码来源:AI.cs

示例3: moveTo

        public void moveTo(Unit u, Position to)
        {

            if (!canMove(to.x, to.y, u.race) || !accessible(to, u) || u.aBouge) { }
            else
            {
                Console.WriteLine("L'unite " + u.name + " bouge de (" + u.pos.x + "," + u.pos.y + ") en (" + to.x + "," + to.y + ")");
                Position from = u.pos;

                //Récupération de l'ancienne liste
                //supression de l'unité
                List<Unit> uList;
                units.TryGetValue(from, out uList);
                uList.Remove(u);
                units.Remove(from);
                units.Add(from, uList);

                //Récupération de la nouvelle liste
                //et ajout de l'unité
                units.TryGetValue(to, out uList);
                uList.Add(u);
                units.Remove(to);
                units.Add(to, uList);
                u.move(to);
            }
        }
开发者ID:Tyzeppelin,项目名称:petitmondetemp,代码行数:26,代码来源:MapImpl.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

示例6: missionTrenchAroundTarget

        private static void missionTrenchAroundTarget(Unit u, BitArray target)
        {
            BitArray adj = BitBoard.GetAdjacency(target);
            if (!u.HasDug)
            {
                Tile minTile = null;
                List<Node> path = null;
                foreach (Tile tile in AI.tiles)
                {
                    if (BitBoard.GetBit(adj, tile.X, tile.Y) && 3 >= Misc.ManhattanDistance(u, tile))
                    {
                        BitArray pos = BitBoard.position[tile.X][tile.Y];
                        BitArray dest = new BitArray(BitBoard.length, false).Or(pos).Or(BitBoard.GetNonDiagonalAdjacency(pos));
                        List<Node> p = AStar.route(u.X, u.Y, dest);
                        if (p.Count == 0 && !BitBoard.GetBit(dest, u.X, u.Y)) continue;

                        if (minTile == null)
                        {
                            minTile = tile;
                            path = p;
                        }

                        if (tile.Depth < minTile.Depth)
                        {
                            minTile = tile;
                            path = p;
                        }
                    }
                }

                if (minTile != null)
                {
                    //									BitArray pos = BitBoard.position[minTile.X][minTile.Y];
                    //									BitArray dest = new BitArray(BitBoard.length, false).Or(pos).Or(BitBoard.GetNonDiagonalAdjacency(pos));
                    //									List<Node> path = AStar.route(u.X, u.Y, dest);
                    //int x = u.X;
                    //int y = u.Y;

                    foreach (Node n in path)
                    {
                        if (u.MovementLeft == 0) break;
                        u.move(n.x, n.y);
                    }

                    if (1 >= Misc.ManhattanDistance(u, minTile))
                    {
                        u.dig(minTile);
                    }
                }
            }

            BitBoard.UpdateAll(); // May cause water to change
        }
开发者ID:austingantner,项目名称:MegaMinerAI12-Mars,代码行数:53,代码来源:CIA.cs

示例7: missionGoToAttack

        private static void missionGoToAttack(Unit u, BitArray b, bool walkThroughWater)
        {
            if (u.MovementLeft == 0 || BitBoard.Equal(b, BitBoard.empty))
            {
                return;
            }

            List<Node> path = AStar.route(u.X, u.Y, b, !walkThroughWater);
            if (path.Count == 0)
            {
                if (BitBoard.GetBit(b, u.X, u.Y))
                {
                    BitArray dest = BitBoard.GetPumpStation(b, u.X, u.Y);
                    dest.And(BitBoard.GetNonDiagonalAdjacency(BitBoard.oppOccupiedTiles));
                    if (!BitBoard.Equal(dest, BitBoard.empty))
                    {
                        path = AStar.route(u.X, u.Y, dest, !walkThroughWater);
                        foreach (Node n in path)
                        {
                            if (u.MovementLeft == 0) break;
                            u.move(n.x, n.y);
                        }
                    }
                }
            }
            foreach (Node n in path)
            {
                bool stop = false;
                if (u.MovementLeft == 0) break;
                //Try to stop once we are close enough to attack
                foreach (Unit unit in AI.units)
                {
                    if (unit.Owner != u.Owner)
                    {
                        if (u.Range >= Misc.ManhattanDistance(u, unit) && unit.Type == (int)AI.Types.Tank)
                        {
                            stop = true;
                            break;
                        }
                    }
                }

                if (stop) break;

                // Try to move
                // if you fail to move,
                // curl up in a ball and cry
                if (!u.move(n.x, n.y))
                {
                    break;
                }

            }
            BitBoard.UpdateUnits();
        }
开发者ID:austingantner,项目名称:MegaMinerAI12-Mars,代码行数:55,代码来源:CIA.cs

示例8: missionGoTo

        //goto should go to the nearest non-occupied square
        //from the target bit board
        private static void missionGoTo(Unit u, BitArray b, bool walkThroughWater)
        {
            if (u.MovementLeft == 0 || BitBoard.Equal(b, BitBoard.empty))
            {
                return;
            }

            List<Node> path = AStar.route(u.X, u.Y, b, !walkThroughWater);
            foreach (Node n in path)
            {
                if (u.MovementLeft == 0) break;

                // Try to move
                // if you fail to move,
                // curl up in a ball and cry
                if (!u.move(n.x, n.y))
                {
                    break;
                }
            }
            BitBoard.UpdateUnits();
        }
开发者ID:austingantner,项目名称:MegaMinerAI12-Mars,代码行数:24,代码来源:CIA.cs


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