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); }
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); }
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); }
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; } } } } }
public ATree(ATree tree) : base(tree) { Life = tree.Life; }