Rock paper scissors one of the most balanced games that exists, every option has equal possibilities to win, loose or draw. The rps system is implemented in many games and hidden with many fancy names like elements, weak points and strong point and others. The good thing about this is that it can be used in strategies once you know your enemies, while giving you the option to grow in one without being the weakest nor the strongest. But now I would like to propose a more complex system. Lets include the rps in a circle, the angle between each point is 120. So lets take any position in a circle and say its stronger point its that position + 120 and its weakest point its that position + 128. Now lets make a bonus system out of that and the closer you are to the stronger point you get a 100% bonus while the closer you are to the weakest point you get -100%. This leave us with two arks. one arc has a length of 120 and goes from 120 to 240 from 100% in 120 to 0 in 180 to -100% in 240. And we also have an arc of 240, this arc goes from -180 in 240, to 0 in 0 as it starts the circle again and finally 100% in 120. Now to put it in code let me explain my float modulus formula.
float fmodulus(float a,int b)
{
return ((a/b)-floor(a/b))*b;
}
this formula behaves like modulus. In other words it returns the residual of a division but with the difference that the first number can be a float and not an integer.
now for the formula to calculate the bonus we have this. It can be made better but lets use this for explanation.
float huebonus(float a,float p)
{
a = fmodulus(a,360); //first we clean the atacking point so its between 0 and 360;
float b = fmodulus(a+120,360); //then we get the strong point and we also put it between 0 and 360
float c = b + 120; // then we need the weak point
float d = fmodulus(c,360); //then we get the weak point and make sure its in the circle
float e = d + 240; //then we get the strong point again this time from the weakpoint
p = fmodulus(p,360); //we put the defending point in the circle
if((b<=p)&&(p<c)) //first we check if its between a+120 and a+240
return (60 - p + b)/60;
else if ((c>360)&&(0<=p)&&(p<d)) then if a+240 is larger than 0 then we check from 0 to the correct point
return (b - p - 300)/60;
else if((d<=p)&&(p<e))//then we check from a+240 and from that point +240 (the weak point)
return (p - 120 - d)/120;
else //once again if its larger than 360 we check from 0 to that point
return (240 + p - d)/120;
}
great now how can we make this pretty. just use color hues!.
thats for today back to the code.
Tuesday, April 1, 2008
Lets Play Rock Paper Scissors
Subscribe to:
Post Comments (Atom)


























No comments:
Post a Comment