Search Unity

Randomized Distribution In Circle + Additional Rules

Discussion in 'Scripting' started by AlwaysSunny, Feb 16, 2015.

  1. AlwaysSunny

    AlwaysSunny

    Joined:
    Sep 15, 2011
    Posts:
    260
    Seeking improved solution to achieve the result depicted in the topmost figures. Bottommost figures indicate desired end result and rule enforcement principles. This is for the map genny in the game I'm working on.

    N territories must be placed in a circle whose center is world origin
    N > 10 && N < 30
    Their mean distance from their nearest neighbors D
    should, (much more often than not), be such that
    D < r1 - r1 is the distance at which connections to neighbors are allowed
    D > r2 - r2 is the minimum distance, since territories need breathing room

    The maximum magnitude of any point is fixed to lie within original circle.
    The circle's radius, desired D, r1, and r2 must not change.
    fig1.jpg

    My current method works 99% of the time on small maps,
    and about 94% of the time on large maps, where N = ~30.

    This fail+retry rate feels unacceptable to me, although perhaps it's not unheard of? We're talking about milliseconds, after all.

    At any rate, I feel I might really benefit from some fresh ideas, and who knows, cool patterns might emerge through a different approach.

    Thank you for your time, and for any suggestions for alternative ideas. I would really like to see this aspect of my game stronger and less temperamental. Perhaps even with greater variety?

    Current method described below:
    RETRY:
    Plot N points randomly in circle whose center is world origin
    For 3 iterations...
    ...For all N points p...
    ......Reduce magnitude of p - compresses map, iterations / coefficients found experimentally
    ......Move p away from all others, factor weighted by distance - achieves separation, iterations / coefficients found experimentally
    goto RETRY if any points violate the rules.
     
    Last edited: Feb 16, 2015