예제 #1
0
        private void InitHatas(ResponseObservation observation)
        {
            FindBaseLocations(observation);
            SetBasePosionsByMinerals();

            var hatas = observation.Observation.RawData.Units.Where(d => d.UnitType == UnitTypes.HATCHERY && d.Alliance == Alliance.Self).ToList();

            if (hatas.Count() != Bases.Where(b => b.Taken).Count())
            {
                foreach (var h in hatas)
                {
                    foreach (var b in Bases)
                    {
                        if (Dist.Distance(b.Position, h.Pos) < 5)
                        {
                            b.Taken    = true;
                            b.Position = h.Pos;
                            b.BaseId   = h.Tag;
                        }
                    }
                }
            }

            if (MainBase == 0 && hatas != null)
            {
                MainBase = hatas.FirstOrDefault().Tag;
            }

            //if (hatas.Count() > 1 || hatas.Count() == 0)
            //    return;

            var minDist = float.MaxValue;
            var bas     = Bases[0];

            foreach (var b in Bases)
            {
                var dist = Dist.Distance(b.Position, hatas[0].Pos);
                if (dist < minDist)
                {
                    minDist = dist;
                    bas     = b;
                }
            }

            bas.BaseId = hatas[0].Tag;

            foreach (var b in Bases)
            {
                if (b.BaseId == MainBase)
                {
                    continue;
                }

                b.DistanceToMain = Dist.Distance(hatas[0].Pos, b.Position);
            }
        }
예제 #2
0
        public static float MinDistToMineral(Point p, List <Unit> minerals)
        {
            var minDistToMineral = float.MaxValue;

            foreach (var m in minerals)
            {
                var d = Dist.Distance(p, m.Pos);
                if (d < minDistToMineral)
                {
                    minDistToMineral = d;
                }
            }

            return(minDistToMineral);
        }
예제 #3
0
        public static Point TryCutDistXY(float x, float y, int incX, int incY, List <Unit> minerals)
        {
            var result = new Point {
                X = x, Y = y
            };

            foreach (var m in minerals)
            {
                if (Dist.Distance(m.Pos, new Point {
                    X = x, Y = y
                }) < 50)
                {
                    return(result);
                }
            }

            result.X += incX;
            result.Y += incY;

            return(result);
        }
예제 #4
0
        public static List <Unit> FindOutsideMinerals(List <Unit> minerals)
        {
            var max1    = minerals[0];
            var max2    = minerals[1];
            var maxDist = 0f;

            foreach (var m1 in minerals.Where(u => u.UnitType == UnitTypes.MINERAL_FIELD).ToList())
            {
                foreach (var m2 in minerals)
                {
                    var dist = Dist.Distance(m1.Pos, m2.Pos);
                    if (dist > maxDist)
                    {
                        max1    = m1;
                        max2    = m2;
                        maxDist = dist;
                    }
                }
            }

            return(new List <Unit> {
                max1, max2
            });
        }
예제 #5
0
 private bool IsNeightbors(Unit min1, Unit min2)
 {
     return(Dist.Distance(min1.Pos, min2.Pos) < 20);
 }