예제 #1
0
        private HighestLowest CalculateTarget(List <DbscanPoint> points, double heightAdjusted)
        {
            List <HighestLowest> highestLowestList = new List <HighestLowest>();
            var clusterCount = DbscanAlgorithm.Dbscan(points.ToArray(), 45, 2);

            if (clusterCount == 0)
            {
                return(null);
            }

            for (var i = 0; i <= clusterCount - 1; i++)
            {
                highestLowestList.Add(new HighestLowest {
                    Id = i
                });
            }

            int clusterIdClosestToMiddle       = 0;
            int clusterClosestToMiddleDistance = int.MaxValue;
            var castSettings = ((PixelClickerPrototype.Settings)Settings);

            foreach (var pointLoopVariable in points)
            {
                var point = pointLoopVariable;
                if (point.ClusterId == null || point.IsNoise)
                {
                    continue;
                }

                if (point.X < highestLowestList[(int)(point.ClusterId - 1)].HighestPoint.X)
                {
                    highestLowestList[(int)(point.ClusterId - 1)].HighestPoint.X = point.X;
                }

                if (point.Y < highestLowestList[(int)(point.ClusterId - 1)].HighestPoint.Y)
                {
                    highestLowestList[(int)(point.ClusterId - 1)].HighestPoint.Y = point.Y;
                }

                if (point.X > highestLowestList[(int)(point.ClusterId - 1)].LowestPoint.X)
                {
                    highestLowestList[(int)(point.ClusterId - 1)].LowestPoint.X = point.X;
                }

                if (point.Y > highestLowestList[(int)(point.ClusterId - 1)].LowestPoint.Y)
                {
                    highestLowestList[(int)(point.ClusterId - 1)].LowestPoint.Y = point.Y;
                }

                int dis = DistanceBetween(new Point(Settings.SearchArea.Width / 2, (int)(Settings.SearchArea.Height / 2 * heightAdjusted)), new Point(point.X + castSettings.XOffset, point.Y + castSettings.YOffset));

                if (dis < clusterClosestToMiddleDistance)
                {
                    clusterClosestToMiddleDistance = dis;
                    clusterIdClosestToMiddle       = (int)(point.ClusterId - 1);
                }

                highestLowestList[(int)(point.ClusterId - 1)].Points.Add(new Point(point.X, point.Y));
            }

            return(highestLowestList[clusterIdClosestToMiddle]);
        }