ID:154180
 
Here's the basics of the problem. The player can specify a % of ants to take care of the eggs, queen, and larvae. I want it to be a large enough benefit so they will usually assign 10-30% depending on what problems their colony is facing, but of course it is there choice. The problem is that if I make it a large benefit at 10-30% then it is a HUGE benefit at the upper percents (80-100%), too large in fact. If I lower the benefit then 10% becomes virtually worthless and has relatively no noticeable effect.

I've been trying to come up with equations to produce a fairly steep slope at the beginning, then decrease the slope as the percentage gets higher. These are the equations I've come up with so far (they have to accept a domain of 0 <= x <= 100 and produce a range of 0 <= y <= 1):

y = sqrt(x)/10
y = log(x + 1)/(2.00432)
y = sin(sqrt(x)*Pi/20)

The most promising seems to be equation number one but all of them are too steep at the beginning. An x of 4 would give 20% of the total possible benefit (y). It will work but I could use any ideas you can give me :)
English wrote:
Here's the basics of the problem. The player can specify a % of ants to take care of the eggs, queen, and larvae. I want it to be a large enough benefit so they will usually assign 10-30% depending on what problems their colony is facing, but of course it is there choice. The problem is that if I make it a large benefit at 10-30% then it is a HUGE benefit at the upper percents (80-100%), too large in fact. If I lower the benefit then 10% becomes virtually worthless and has relatively no noticeable effect.

Why not let the players choose a difficulty level? If it is easy, then make it give that large benefit, if difficult then do the lower benefit.

That's my input.
In response to Loduwijk
I'd still have the same problem though. If they choose a high benefit then it will get out of control at 100%. If they choose a hard setting 10% will do virtually nothing. That is why I need a better curve. The first equation I showed should do that but the lowest percentages were too effective.

Maybe I'll just put an if statement in there like this:

if(% <= 5)
effectiveness /= 2

That won't make the curve pretty but it should be close to my desired effect.
English wrote:
Here's the basics of the problem. The player can specify a % of ants to take care of the eggs, queen, and larvae. I want it to be a large enough benefit so they will usually assign 10-30% depending on what problems their colony is facing, but of course it is there choice. The problem is that if I make it a large benefit at 10-30% then it is a HUGE benefit at the upper percents (80-100%), too large in fact. If I lower the benefit then 10% becomes virtually worthless and has relatively no noticeable effect.

I think a key to this is that in real life, the reason assigning too many is counterproductive is that 1) too few are available for other tasks, and 2) they'd just get in each other's way without doing more work. What you need to do is establish some ideal workers/larvae ratio where effectiveness is at its best, and make effectiveness drop off from there. The slope should be gradual for higher numbers.

I've been trying to come up with equations to produce a fairly steep slope at the beginning, then decrease the slope as the percentage gets higher. These are the equations I've come up with so far (they have to accept a domain of 0 <= x <= 100 and produce a range of 0 <= y <= 1):

y = sqrt(x)/10
y = log(x + 1)/(2.00432)
y = sin(sqrt(x)*Pi/20)

The most promising seems to be equation number one but all of them are too steep at the beginning. An x of 4 would give 20% of the total possible benefit (y). It will work but I could use any ideas you can give me :)

The last equation is probably close to your best; the only problems are that scrunching the sine wave also increases the slope, as you no doubt noticed, and that sqrt(x) makes the slope vertical to start. Why not try that with just a regular x instead of sqrt(x)?

y=sin(x*pi*2/3)
y'=pi*2/3*cos(x*pi*2/3)

When x=0, y=0, y'=pi*2/3 (about 2.1; steep)
When x=1/4, y=1/2, y'=pi/sqrt(3) (about 1.8)
When x=3/4, y=1, y'=0
When x=1, y=pi/sqrt(3), y'=-pi/3 (about -1)

This graph is a sine wave from 0 to 120 degrees as x goes from 0 to 1. It maxes out at the 90 degree mark, when x=75%.
But this probably isn't what you want, because you only run at about half efficiency and the slope is still rising strongly. But it's a good place to start.

The sine wave is actually a little too symmetrical for your purposes here; how about this instead: We reverse the graph above so it goes from 120 degrees to 0. This starts y at pi/sqrt(3) when x=0, though, so we'd need to taper it. I tried multiplying by x, but that shifts the maximum over past x>0.5 again. (I'm not sure exactly where; the equation isn't easy to solve, and may not be possible to solve.) How about sqrt(x)?

y=sqrt(x)*sin((1-x)*pi*2/3)
y'=sin((1-x)*pi*2/3)/2sqrt(x)-sqrt(x)*pi*2/3*cos((1-x)*pi*2/ 3)

The max of the equation now is where y'=0. Unfortunately, I'm still at a loss to determine precisely where it is. This equation, which works out to x*pi*2/3=tan((1-x)*pi*2/3)/2, is just as hard to solve for x. (The math required to isolate x is above any level I've ever learned.) The maximum works out to somewhere not far under 50%.

Probably your best approach is to create a formula for the slope. I'd start with this:

y'=g(x)*cos((3x+1)*pi/2)

This slope is rising up to x=1/3, then falls past that. g(x) isn't defined; you have to find something that will work. It's there to scale your cosine function. The reason is, just the cosine will give you a slope that falls more than it rises. Its fall should be gradual, however, and the initial slope (1) should be steeper. g(x)=k^(1-3x) wouldn't be a bad choice; it's equal to k when x=0, 1 when x=1/3, and about 1/k^2 when x=1. Just choose the right k; the equation can be solved without knowing it right away.

The equation for this is a little horrific:
y=k^(1-3x)[-2ln(k)*cos((3x+1)*pi/2)+pi*sin((3x+1)*pi/ 2)-2k*ln(k)]/[3(ln(k)^2+pi^2/4)]

Another approach you might try is y'=k^(1-3x)-1. This will yield a drastically simpler equation: y=(k-k^(1-3x))/3ln(k)-x.
Or, you can try y'=a^(1-3x)-b^(1-3x), where a>b. This will give you y=(b^(1-3x)-b)/3ln(b)+(a-a^(1-3x))/3ln(a).

Lummox JR
In response to Lummox JR
I think a key to this is that in real life, the reason assigning too many is counterproductive is that 1) too few are available for other tasks, and 2) they'd just get in each other's way without doing more work. What you need to do is establish some ideal workers/larvae ratio where effectiveness is at its best, and make effectiveness drop off from there. The slope should be gradual for higher numbers.

Good points. Although I haven't decided which method would fit the game better. Having a negative effect by assigning too many workers to the task would make real world sense but I'm not sure if I want players to have to deal with it on that level. To them I might want it to be a simple, cost benefit analysis where going from 40-50% will help their population grow faster but will limit their other tasks at a higher cost than going from 10-20%. I'll have to think about that one a bit more.

I was trying to think of another way to decrease the original slope of those equations without sacrificing the relatively steeper early slope. (so I have two viable systems to choose from)

This is one solution I came up with:

y = sqrt(x)/10 - 1/(x+1) + .0099
When x=100, y = 1

This gives me the general shape that I want, steep (yet not too steep) at the beginning then flatter towards the end (although the slope is nearly constant when x >= 50). One problem still remains and that is that the values are negative from 0-3 and low at 4 due to the sqrt(x), x, and the x^2 duking it out.

Instead of finding a complicated fix I think I can just make it a piecewise function where from 0 to 4 the equation is:
y = x/100

This is how the values play out:
x 0   1   2   3   4   5   6   8  10  15  20  30  50  75 100
y 0 .01 .02 .03 .04 .07 .11 .18 .23 .33 .40 .52 .69 .86 1.0


As you can see going from 20 to 30 is nearly the same effectiveness as going from 30 to 50 which is the basic effect that I wanted without the beginning being too steep.


y=sqrt(x)*sin((1-x)*pi*2/3)
y'=sin((1-x)*pi*2/3)/2sqrt(x)-sqrt(x)*pi*2/3*cos((1-x)*pi*2/ 3)

If I choose the more realistic route I think I'll use a variation of this, it looks like a good curve that would produce the effect I want.

The max of the equation now is where y'=0. Unfortunately, I'm still at a loss to determine precisely where it is. This equation, which works out to x*pi*2/3=tan((1-x)*pi*2/3)/2, is just as hard to solve for x. (The math required to isolate x is above any level I've ever learned.) The maximum works out to somewhere not far under 50%.

I plugged it into my graphing calculator and it does appear to max out at just before 50%, good call :)

Probably your best approach is to create a formula for the slope. I'd start with this:

y'=g(x)*cos((3x+1)*pi/2)

Although those curves look good, the integrals start to become pretty ugly (as yours demonstrated) unless g(x) is a very simple function which makes it hard to tinker with to get the right result, I think I'll go with your first equation for this reason.

Thanks for all the input! Even if I don't use it for the nursing I'll probably apply them to my spawning algorithms for other creatures based upon their populations :)
I'd say that you shouldn't handle population growth in terms of how many ants are assigned to the nursery job...

No matter how many ants there are...the queen is the bottleneck to the colony's growth... She can only lay a certain number of eggs per breeding period...

So population growth is inherantly limited right off the bat...

Now... Here's where you need to assign ants to take care of those eggs/larvae... However many ants you decide are needed to take adequate care of one egg would be needed as a minumum to keep that egg alive and grow it into adulthood...

Any eggs that don't get the proper number of caregivers die... And any that have sufficient care live on to become adult ants...

So no matter what the percentage is...the total number of new ants is capped at the limit of eggs that the queen can lay... So at huge percentages of ants assigned...the player will see no added benefit and will be wasting resources... Too small of a percentage...and eggs will die and the player will get diminished returns... At just the right balance...everything will run efficiently and the player will get the most for his ant investment...so they'll be encouraged to find just the right balance...

Now... How to make it so larger colonies can reproduce faster? The queen's egg limit can be based on food gathering... More food for the colony/queen equals more eggs for that "season"... And more ants will be needed to care for those eggs to make sure they all survive... So larger colonies won't begin to grow too slowly...and smaller colonies will be encouraged to become more efficient at gathering food to grow their population... And again...a balance will be needed between food gatherers and nursery workers...
In response to Lummox JR
The equation for this is a little horrific:
y=k^(1-3x)[-2ln(k)*cos((3x+1)*pi/2)+pi*sin((3x+1)*pi/ 2)-2k*ln(k)]/[3(ln(k)^2+pi^2/4)]

Another approach you might try is y'=k^(1-3x)-1. This will yield a drastically simpler equation: y=(k-k^(1-3x))/3ln(k)-x.
Or, you can try y'=a^(1-3x)-b^(1-3x), where a>b. This will give you y=(b^(1-3x)-b)/3ln(b)+(a-a^(1-3x))/3ln(a).

I wish someone had tought me to speak math in school.
In response to Foomer
That's differential equations, which is only touched on in high school (and even such, only if you take Calculus). So don't feel too bad that you don't understand it.. it's math that only people who study math know.

-AbyssDragon
In response to AbyssDragon
AbyssDragon wrote:
That's differential equations, which is only touched on in high school (and even such, only if you take Calculus). So don't feel too bad that you don't understand it.. it's math that only people who study math know.

Or in cases like me, math that even people who study math don't know.