예제 #1
0
파일: FindTarget.cs 프로젝트: znsoft/AiCup
        MovingInfo FindTreeTarget(AWizard self)
        {
            var   res       = new MovingInfo(null, int.MaxValue, new FinalMove(new Move()));
            var   trees     = TreesObserver.Trees.Where(t => self.GetDistanceTo(t) <= Game.StaffRange + t.Radius).ToArray();
            var   minTicks  = int.MaxValue;
            ATree selTarget = null;

            foreach (var tree in trees)
            {
                var my    = new AWizard(self);
                var ticks = 0;
                while (Math.Abs(my.GetAngleTo(tree)) > Game.StaffSector / 2)
                {
                    my.MoveTo(null, tree);
                    ticks++;
                }
                if (ticks < minTicks && my.CanStaffAttack(tree))
                {
                    minTicks  = ticks;
                    selTarget = tree;
                }
            }

            if (selTarget == null)
            {
                return(res);
            }

            res.Time     = minTicks;
            res.Target   = selTarget;
            res.TargetId = selTarget.Id;
            if (minTicks == 0)
            {
                res.Move.Action = ActionType.Staff;
            }
            else
            {
                res.Move.MoveTo(null, selTarget);
            }

            return(res);
        }
예제 #2
0
        public static double GetSegmentWeight(Point a, Point b, bool checkStart)
        {
            var   dir  = b - a;
            var   res  = dir.Length;
            ATree prev = null;

            for (var i = (checkStart ? 0 : 1); i <= SegmentDivideParts; i++)
            {
                var p    = dir * (1.0 * i / SegmentDivideParts) + a;
                var tree = TreesObserver.GetNearestTree(p);
                if (tree != null && tree != prev &&
                    Geom.SegmentCircleIntersects(a, b, tree,
                                                 tree.Radius + Const.WizardRadius + MagicConst.RadiusAdditionalEpsilon))
                {
                    res += Math.Ceiling(tree.Life / 12) * MagicConst.TreeObstacleWeight;
                    prev = tree;
                }
            }
            return(res);
        }
예제 #3
0
        public static void Update()
        {
            MyStrategy.TimerStart();

            CellLength = Const.MapSize / GridSize;

            var newState = new Dictionary <long, ATree>();

            NewTrees.Clear();
            DisappearedTrees.Clear();

            foreach (var tree in MyStrategy.World.Trees)
            {
                var a = new ATree(tree);
                if (!_prevState.ContainsKey(tree.Id))
                {
                    // новое дерево
                    NewTrees.Add(a);
                }
                newState[tree.Id] = a;
            }

            foreach (var it in _prevState)
            {
                if (!MyStrategy.IsPointVisible(it.Value))
                {
                    // его не видно, считаем что осталось
                    newState[it.Key] = it.Value;
                }
                else if (!newState.ContainsKey(it.Key))
                {
                    // видно, но исчезло
                    DisappearedTrees.Add(it.Value);
                }
            }

            _prevState = newState;
            _updateGrid();

            MyStrategy.TimerEndLog("Update trees", 1);
        }
예제 #4
0
        private static void _updateGridByTree(ATree tree, ATree value)
        {
            var r      = (tree.Radius + Const.WizardRadius) * 1.1;
            var am     = (int)(r / CellLength) + 1;
            var center = _findNearestCell(tree);

            for (var di = -am; di <= am; di++)
            {
                for (var dj = -am; dj <= am; dj++)
                {
                    var i = di + center.I;
                    var j = dj + center.J;
                    if (i >= 0 && j >= 0 && i <= GridSize && j <= GridSize)
                    {
                        var pt = new Point(i * CellLength, j * CellLength);
                        if (value == null || _nearest[i, j] == null || pt.GetDistanceToCircle(_nearest[i, j]) > pt.GetDistanceToCircle(tree))
                        {
                            _nearest[i, j] = value;
                        }
                    }
                }
            }
        }
예제 #5
0
파일: ATree.cs 프로젝트: znsoft/AiCup
 public ATree(ATree tree) : base(tree)
 {
     Life = tree.Life;
 }