Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5] 6 7 ... 31

Author Topic: Proceedurally Generated RTS  (Read 57042 times)

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #60 on: January 10, 2011, 01:12:24 pm »

The problem with pulling out the stops and letting stats go "arbitrarily high" is that there is a max value I can pull back from Math.random().

So the possibility of a max-health, max-damage, max-armor, max-speed, max-range ship is non-zero.  There are in fact, at current, only 4 calls to the RNG.  1-5, 0-6, 2-9, and [0-1 squared]*6.  Lets say, roughly 0.05%.  But that's absolute max in all categories.  Near-max is greater than that, easily 1.5%.  While the balance of these units can be controlled with the resource cost to build them, it's not truly balanced, as there are not units that can kill it without swamping them with sheer numbers--this is what I detest with AI War: Fleet Command right now.  The AI only fleets units that are worth 30 of yours, and the way to kill them is to throw your fleetblob at it and build a new fleet.

But I think what I can do is generate 12 sets of random numbers, sort them, then plug them in to a function.   Eg.

GenUnit(a,b,c,d) where a, b, c, and d are in place of the RNG calls I'm making now.  So then I can do GenUnit(A, B, c, d), GenUnit(A, b, C, d), etc. (where A represent a high RNG result and a is a low RNG result).

I'd get back 12 units, one that's High HP/High Armor, one that's High HP/High Damage, one that's High HP/High Speed, etc.
« Last Edit: January 10, 2011, 01:14:26 pm by Draco18s »
Logged

Armok

  • Bay Watcher
  • God of Blood
    • View Profile
Re: Proceedurally Generated RTS
« Reply #61 on: January 10, 2011, 01:42:57 pm »

Fine, be a pedant then. By arbitrarily high I mean the max value is thousands of times higher than will plausibly occur even if you generates thousands of units. It just means a distribution with a very long tail.

And no, don't do what you said in that last post, just regen and test until you get the BEHAVIOUR you want in an actual test. Looking at the numbers directly is cheating.
Logged
So says Armok, God of blood.
Sszsszssoo...
Sszsszssaaayysss...
III...

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #62 on: January 10, 2011, 02:24:32 pm »

And no, don't do what you said in that last post, just regen and test until you get the BEHAVIOUR you want in an actual test. Looking at the numbers directly is cheating.

The problem is that I would like to run fewer tests.  If the "top unit" is a kiter, then a slow unit isn't ever going to beat it.  Not even with max HP and max Armor, so I need to weight the RNG values so that the two best results are given towards speed/range.  I'm not looking at the values I'm saying "I need a unit weighted towards speed" and using RNG calls that end up with speed.

All I'm doing is passing the Math.random() through the sort, not the Math.floor(Math.random()*Max)+Min because the range is always different.  I still have four random values, but rather than using them in the order I get them, I'm using them in the order I would like to use them.  It'd be like D&D trying to build a Ranger and putting your highest dice-roll into Dex because you need dexterity vs. rolling 3d6 for strength (16), 3d6 for con (13), 3d6 for dex (8 )...and going, "shit, this would make a crappy ranger" and starting over.

So I'm trying to short-cut the "generate until it wins" and instead "generate a probable winner."

Fine, be a pedant then. By arbitrarily high I mean the max value is thousands of times higher than will plausibly occur even if you generates thousands of units. It just means a distribution with a very long tail.

This is also difficult.  RNGs return an even distribution of floating point numbers between 0 and 1.  A "distribution with a very long tail" requires that I square, cube, or even worse the RNG to get values closer and closer to 0, then multiply by some huge number.  Which I'm already doing for NumShots.  The problem is that "very long tale" creates a sequence like this:

1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,5,5,6,7,9,11,14,18,24,33,44,59,75,100.

The "long tail" generates increasingly large values as your base multiplier gets larger (so that your minimum value still returns 1).

A a "cube a RNG" and multiply by N, 10% of the time you'll get a value of 0.72 * N or greater 10% of the time.  RNG^5 returns a value 0.6*N or greater 10% of the time, but you'll also get 0.00001*N 10% of the time, so N would need to be 1000 just to account for it, making 0.6N equal to 600.  10% of your units have a "stat" of 1, while 10% of them have a stat of 600 or more.
« Last Edit: January 10, 2011, 02:36:10 pm by Draco18s »
Logged

Armok

  • Bay Watcher
  • God of Blood
    • View Profile
Re: Proceedurally Generated RTS
« Reply #63 on: January 10, 2011, 04:45:03 pm »

Make a function that generates numbers according to a Gaussian distribution, then pretend you no longer have the original rand, should work.
Logged
So says Armok, God of blood.
Sszsszssoo...
Sszsszssaaayysss...
III...

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #64 on: January 10, 2011, 05:03:42 pm »

Make a function that generates numbers according to a Gaussian distribution, then pretend you no longer have the original rand, should work.

The problem there lies in the simplicity of implementing such a RNG, or rather, the lack there-of.  The simplest method still generates a hard upper and lower bound:
Quote
An easy to program approximate approach, that relies on the central limit theorem, is as follows: generate 12 uniform U(0,1) deviates, add them all up, and subtract 6 — the resulting random variable will have approximately standard normal distribution. In truth, the distribution will be Irwin–Hall, which is a 12-section eleventh-order polynomial approximation to the normal distribution. This random deviate will have a limited range of (−6, 6).

The "Most straightforward method" appears to be anything but (is that a sum of an infinite series I see?)

The remaining methods I don't even understand.
Logged

Azkanan

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #65 on: January 10, 2011, 05:13:26 pm »

This project requires funding from EA Games!

No, wait, they'll tell you to dumb it down so 2 year olds can play it. Let's not bring them into this. >_>
Logged
A pool of Dwarven Ale.
WHO IS RESPONSIBLE FOR THIS ?

Armok

  • Bay Watcher
  • God of Blood
    • View Profile
Re: Proceedurally Generated RTS
« Reply #66 on: January 10, 2011, 05:41:17 pm »

I through there was an easy approximation you could do with tan if you had a distribution from 0 to 1?

*Fiddles around in python for 30 min*
Here, have a look at this:
Code: [Select]
for i in range(100):
   print int(math.tan(((random.random())+0.5)*math.pi)*100)
Logged
So says Armok, God of blood.
Sszsszssoo...
Sszsszssaaayysss...
III...

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #67 on: January 10, 2011, 05:43:05 pm »

Thanks Armok, I'll try playing around with it.  What's its "reasonable" lower/upper bounds?
(i.e. 3 standard deviations)
Logged

Armok

  • Bay Watcher
  • God of Blood
    • View Profile
Re: Proceedurally Generated RTS
« Reply #68 on: January 10, 2011, 06:06:04 pm »

dunno, run it 10 000 times and see what the 100 largest values are, that should be a good indicator.
Logged
So says Armok, God of blood.
Sszsszssoo...
Sszsszssaaayysss...
III...

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #69 on: January 10, 2011, 06:14:36 pm »

Min/max from 4 10,000 runs:

Min: -1,549,3319
Max: 1,175,156

Min/max from a 1million run:

Min: -49,390,554
Max: 11,879,827

I....am going to need a more robust method to determining the mean/average/"bounds" than trying to push results into an array.

*Sighs and digs up FusionCharts and attempts to graph the RNGs*

Edit:
<Expletive deleted>
I simply CANNOT track values in any meaningful fashion in an attempt to count them.  Also, here's the output of 10 calls:
71
12
50
-140
-1848
-226
-25
6485
38
-32

ranges from negative 2000 to positive 6500.  So the first problem is not having negative numbers (ok, absolute value them).  The second problem is that the negatives are roughly 5 times more likely and 5 times more "big" than positive numbers (so ABS isn't a perfect solution).  The third problem is the fact that they are unbounded (except by MAX_INT, which in Flash is retardedly huge as it will switch data types if you exceed the max value for the one it started with, when you do finally "top out" even their scientific notation datatype it just goes "oh, its infinity") and that makes it freaking impossible to limit things to rational values that humans like to play with.  I can't simply take the result of this function and go "That's hitpoints" because you'll get a value from 2 to 10,000,000 (and then another unit gets 3,000,000 damage, one-shotting any unit that gets anything less in HP).  This isn't conducive to trying to achieve balance.

The only way I could even attempt to measure this function is in powers of 10.

Yeah, that works (10,000 calls):
-10 <------------------> 10
1,0,2,0,7,19,70,166,409,1025,1492,1006,434,184,58,23,10,4,0,0,0

4 results ~= 1 * 10^7.  That's....too many.

1 million runs generates 6 >= 1*10^11.
« Last Edit: January 10, 2011, 06:34:10 pm by Draco18s »
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Proceedurally Generated RTS
« Reply #70 on: January 10, 2011, 06:24:37 pm »

Well duh, of course that won't work, you're looking at the maximum of a Gaussian distribution. What you want to do is calculate the standard deviation of your distribution and use that to set your bounds (for an untransformed and untranslated Gaussian distribution that's 0.682).
Also, if you're afraid of overshooting, you're going to have to use a discrete distribution function because the common continuous distributions all max out at infinity.


Edit: the Raised cosine distribution looks prommissing
« Last Edit: January 10, 2011, 06:37:02 pm by Virex »
Logged

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #71 on: January 10, 2011, 06:36:00 pm »

Thanks for stating the obvious, my problem is I don't know how.  Also, Armok doesn't want them to be bounded.  He wants the RNG calls to be unbounded.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Proceedurally Generated RTS
« Reply #72 on: January 10, 2011, 06:43:07 pm »

If you're going to follow his advice, you don't want to filter out the stupidly high stats ab initio, but instead test them against a base reference and cull anything that overshoots your bounds, which means the large positives don't matter that much because they get culled anyway (the large negatives on the other hand could mean your distribution is skewed).


As for the stats of the fighters, you could indeed put them at 3 standard deviations (which would be 0.6833 = 0.997 for an untransformed and untranslated Gaussian distribution. Post-multiplying these values ought to keep the distribution Gaussian, but I'm not too sure about that. Adding a constant does keep the distribution Gaussian for sure, as long as you stay away from analyzing it at infinity), but that means over 99% of the individual stats of your runs are going to be worse then the reference. I'd at least start with more then 100 test units against 100 fighters to make the guys at the low end of the scale viable as well.
« Last Edit: January 10, 2011, 06:49:14 pm by Virex »
Logged

Draco18s

  • Bay Watcher
    • View Profile
Re: Proceedurally Generated RTS
« Reply #73 on: January 10, 2011, 09:30:20 pm »

Current algorithm has located new best unit:

Speed 2
Range 41
RoF 21
HP 275
Armor 13
Damage 27 x7

Current algorithm fails.  Return to drawing board.

(Kites are so heavily disadvantaged now it's not funny; you take a few points off their max damage and suddenly they are no longer viable)
Logged

Omegastick

  • Bay Watcher
  • Crazy musician man
    • View Profile
Re: Proceedurally Generated RTS
« Reply #74 on: January 11, 2011, 12:09:46 pm »

May I suggest a much simpler method of finding a random number distribution with a very long tail (or head)? If the number generated is over/under a certain limit have a 50/50 chance to re-roll the stat, if it's over/under an even higher/lower limit have a 75/50 chance to re-roll the stat. This wouldn't look amazing on a graph, perhaps, but it would work wonders for video games.
Logged
I make music under the name Flag Red, check me out:
Soundcloud
Youtube
Facebook
Pages: 1 ... 3 4 [5] 6 7 ... 31