• Create Account

## Help calculate this easyer, or more efficient way

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1BaneTrapper  Members

1493
Like
0Likes
Like

Posted 02 April 2013 - 07:42 AM

Hello.

Reason:

Currently i am balancing the game i am working on.

What i want to achieve:

i am trying to find a formula that will be more efficient then this peace of code

/* Example values
int calcRT = 0;
int statRT = 9;
*/
int tax = 0;
for(unsigned int n = 0; n < unit.statRT; n++)

{

unit.calcRT -= 100 - tax;

tax += 5;

}


What i want is for each statRT to reduce calcRT by 100, but each one after that to give by 5 less so.

If statRT = 1, calcRT = -100;(100)

if statRT = 2, calcRT = -195;(100 + 95)

If statRT = 3, calcRT = -285;(100 + 95 + 90)

if statRT = 10, calcRT = - ;(100 + 95 + 90... + 65 + 60 + 55)

What syntax i am looking for

/* Example values
int calcRT = 0;
int statRT = 9;
*/
calcRT = statRT * (100 - (5 * statRT));


### #2Waterlimon  Members

4370
Like
0Likes
Like

Posted 02 April 2013 - 07:50 AM

calcRT = max(statRT - 1, 0)*5-statRT*100

perhaps

EDIT:

You might want to set an upper bound for statRT inside the max, because else it would go like ...+ 65 + 60 + 55... + 5 + 0 -5 which you probably dont want to happen.

EDIT2:

Oh wait that doesnt seem to work... :c

Edited by Waterlimon, 02 April 2013 - 08:30 AM.

o3o

### #3Álvaro  Members

20235
Like
1Likes
Like

Posted 02 April 2013 - 07:54 AM

Are you looking for a formula that gives the same results?
calcRT = -100 * statRT + 5 * statRT * (statRT - 1) / 2;

Edited by Álvaro, 02 April 2013 - 07:56 AM.

### #4BaneTrapper  Members

1493
Like
0Likes
Like

Posted 02 April 2013 - 08:25 AM

Are you looking for a formula that gives the same results?

calcRT = -100 * statRT + 5 * statRT * (statRT - 1) / 2;

Well that reproduces the values / value i am looking for.

Much respect, thank you for this.

calcRT = max(statRT - 1, 0)*5-statRT*100

perhaps

EDIT:

You might want to set an upper bound for statRT inside the max, because else it would go like ...+ 65 + 60 + 55... + 5 + 0 -5 which you probably dont want to happen.

EDIT2:

Oh wait that doesnt seem to work...

Its ... not ... correct

Edited by BaneTrapper, 02 April 2013 - 08:29 AM.

5832
Like
0Likes
Like

Posted 02 April 2013 - 08:26 AM

Use Alvaro's formula (although watch out for the behaviour when statRT is bigger than 20, may want to cap it instead of going negative).

The pattern is -100, -200 + 5, -300 + (5 + 10), -400 + (5 + 10 + 15), ...

which is -100 * statRT + 5 * (Sum (0 to (statRT-1)))

And since Sum(0 to X) is 0.5 * X * (X+1), Sum(0 to (startRT-1)) = 0.5 * statRT * (statRT - 1)

which gives Alvaro's formula

EDIT: You probably don't want to cap anything when statRT is > 20, since the formula gives a nice (parabolic) curve.

Edited by Paradigm Shifter, 02 April 2013 - 08:34 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

5832
Like
0Likes
Like

Posted 02 April 2013 - 08:45 AM

And here's something about how the maths for the sum works...

What is the area of an N * (N+1) rectangle?

XXXXXXX

XXXXXXX

XXXXXXX

XXXXXXX

XXXXXXX

XXXXXXX

if N = 6, area is 6 * 7 = 42.

What use is that?

What is the area of this shape?

X

XX

XXX

XXXX

XXXXX

XXXXXX

Answer: if you rotate a copy of it 180 degrees and line it up it forms a 7 * 6 rectangle (using O for the copy of the shape)

XOOOOOO
XXOOOOO
XXXOOOO
XXXXOOO
XXXXXOO
XXXXXXO


Which works for any size N, so the area of the shape is 0.5 * N * (N+1)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #7irreversible  Members

2587
Like
0Likes
Like

Posted 02 April 2013 - 08:49 AM

If your step and limits are fixed, couldn't you simply use a look-up table? Just calculate it once and you're done.

5832
Like
0Likes
Like

Posted 02 April 2013 - 08:53 AM

Lookup table vs. simple formula? Simple formula for the win...

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #9Álvaro  Members

20235
Like
0Likes
Like

Posted 02 April 2013 - 11:46 AM

Lookup table vs. simple formula? Simple formula for the win...

I am not sure. If you can make the table visible to a game designer, he can tweak it any way he wants.

5832
Like
0Likes
Like

Posted 02 April 2013 - 12:02 PM

I suppose...

If I was living in some magical world in which designers actually tweaked values ;) (And not, hey that ends with a 7, that doesn't look neat, make it end with a zero instead, for no apparent reason).

Anyway you gave the correct answer and I explained some of the maths so we both win! Would probably help if we knew what the values were meant to represent in the game.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #11BaneTrapper  Members

1493
Like
0Likes
Like

Posted 03 April 2013 - 03:25 AM

Lookup table vs. simple formula? Simple formula for the win...

I am not sure. If you can make the table visible to a game designer, he can tweak it any way he wants.

Also it would allot bigger depth for the system.

But, it would also require more time to manage witch i lack sadly.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.