Beispiel #1
0
        private static LandType Classify(IField2d <BrownianTree.Availability> field, int x, int y, int sensitivity, float shoreThreshold)
        {
            if (field[y, x] == BrownianTree.Availability.Available)
            {
                return(LandType.Land);
            }

            Point2d pos      = new Point2d(x, y);
            float   landNum  = 0f;
            float   totalNum = 0f;

            for (int j = (int)Math.Max(0, y - sensitivity); j < Math.Min(field.Height, y + sensitivity + 1); j++)
            {
                for (int i = (int)Math.Max(0, x - sensitivity); i < Math.Min(field.Width, x + sensitivity + 1); i++)
                {
                    if (Point2d.SqDist(new Point2d(i, j), pos) < sensitivity * sensitivity)
                    {
                        if (field[j, i] == BrownianTree.Availability.Available)
                        {
                            landNum++;
                        }
                        totalNum++;
                    }
                }
            }

            if (landNum / totalNum > shoreThreshold)
            {
                return(LandType.Shore);
            }

            return(LandType.Ocean);
        }
Beispiel #2
0
        private bool IsLegal(Point2d pos, int sensitivity)
        {
            int x = (int)pos.x;
            int y = (int)pos.y;

            // Determine that we aren't off the field.
            if (x < 0 || y < 0 || x >= this.Width || y >= this.Height)
            {
                return(false);
            }

            // Determine that this value is available.
            if (this[y, x] == Availability.Unavailable)
            {
                return(false);
            }

            // Determine that we are not too close to an illegal areas, which repel placement.
            // TODO: pre-process map to find illegal placements upfront, then compare against those instead.
            for (int j = (int)Math.Max(0, y - sensitivity); j < Math.Min(this.Height, y + sensitivity + 1); j++)
            {
                for (int i = (int)Math.Max(0, x - sensitivity); i < Math.Min(this.Width, x + sensitivity + 1); i++)
                {
                    if (Point2d.SqDist(new Point2d(i, j), pos) < sensitivity * sensitivity && this[j, i] == Availability.Illegal)
                    {
                        return(false);
                    }
                }
            }

            // Placement is legal.
            return(true);
        }
Beispiel #3
0
        // TODO: This was ported from the old implementation.  It might be the most inefficient thing ever.
        private bool ShouldStop(Point2d pos, int sensitivity, System.Random random, ref Point2d ret)
        {
            List <Point2d> candidates = new List <Point2d>();

            // Assume placement is legal, then check to see if there are any values close enough to draw lines to.
            for (int j = (int)Math.Max(0, pos.y - sensitivity); j < Math.Min(this.Height, pos.y + sensitivity + 1); j++)
            {
                for (int i = (int)Math.Max(0, pos.x - sensitivity); i < Math.Min(this.Width, pos.x + sensitivity + 1); i++)
                {
                    Point2d pt = new Point2d(i, j);
                    if (Point2d.SqDist(pt, pos) < sensitivity * sensitivity && this[j, i] == Availability.Unavailable)
                    {
                        candidates.Add(pt);
                    }
                }
            }

            // If there are many candidates, choose the nearest.  Otherwise, return nothing.
            if (candidates.Count > 0)
            {
                ret = candidates[0];
                float dist = Point2d.SqDist(ret, pos);

                for (int idx = 1; idx < candidates.Count; idx++)
                {
                    float newDist = Point2d.SqDist(candidates[idx], pos);
                    if (newDist < dist)
                    {
                        ret  = candidates[idx];
                        dist = newDist;
                    }
                }

                return(true);
            }
            return(false);
        }