ID:1840736
 
Code:

Problem description:

While creating some probability algorithms for the Diplomacy AI I got stuck in a simple math problem. And I don't even know why I keep getting stuck in these simple problems...

So I have 3 variables, PowerA, PowerB and Balance.
PowerA and Power B are positive numbers while Balance ranges from -1 to +1

I want +1 to mean that PowerA is double than PowerB and -1 to mean the opposite
I don't fully understand.
What I interpreted though was this.

var
PowerA
PowerB
Balance

proc/Balance()
switch(Balance)
if(1)PowerA = PowerB * 2
if(-1)PowerA = -(PowerB)
return Balance
I gather that perhaps victor is instead looking for something like:
var
PowerA = 3; // these values are just for the sake of example
PowerB = 10; // ^ likewise
Balance;

proc/ModeratePower()
Balance = rand(-1,1) //... you get the drill
if(!Balance == 0)
Balance > 0 ? PowerA = PowerB*2 : PowerB = PowerA*2;
world << "Powers A and B are [PowerA] and [PowerB] respectively when Balance = [Balance]." // this can be ignored, just put in there by habit, in case also you might want to test this out.

Unless of course, Victorqr, the fact that you said you're balance 'ranges' between -1 and 1 is important, as in it can do this in fractional increments/decrements?

In that case i'd suppose your difficulty with the task would instead lie in how to correctly scale the value of balance to a relevant multiplication to be applied to either PowerA or PowerB depending on Balance's sign?
Firstly thanks to all of you for your time, but GatewayRa got the solution right.
I thought I posted some examples in a 2nd post, might have been an internet connection. Sorry if I was not precise enough.
That's a very good implementation GatewayRa never thought about min/max.
Thanks again for your help :)
In response to Victorqr
Ah, alright, cool.
I was thinking that some elaboration, perhaps in the form of a mock system showing the essence of what you were going for might have been helpful -which i guess you intended to provide within the phantom post, haha :D- but no worries all the same, happy to offer assistance.

Btw, is the project this is being used in some kind of empire conquest type game? If so, that'd be sweet :o
Anyway eventually I came up with another approach in that matter, it is based on that though.

Turboskill yeah we are creating an empire conquest game with some rpg elements, big armies, destructable environment, quests and other stuff. I hope we have it ready by summer...
Heh, interesting. Another thing i might keep an eye out for.