My current coding challenge. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My current coding challenge.

I have a function I need to spit out a number between 16 and 10,000. Context: HP damage. Given that it accepts inputs x, y, z. x will never be below 1 or above 99. y will be between 15 and 255. z same rules as y. ie. (levelX + 2*atkY) - defZ = 16; // Here's the low end Getting from there to the high end is the problem. With this formula, 594 is the top. Which I could use, but I would have to scale my ideas down. (99 + 510) - 15 Any bright ideas?

15th Jul 2017, 11:25 PM
Russel Reeder
Russel Reeder - avatar
12 Answers
+ 1
Oh I made a mistake, sorry ! You have to do : /(MaxOfCurrentRange - MinOfCurrentRange) instead of /MaxOfCurrentRange
17th Jul 2017, 8:08 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 4
I'm a game programmer. I see that you have a function to calculate damage output, but I don't quite understand your issue. Are the numbers outside of the range that you were anticipating?
16th Jul 2017, 2:49 AM
Keto Z
Keto Z - avatar
+ 3
Thanks for the response. Seems legit if I plug in proper top end values. Hmm.
16th Jul 2017, 9:34 PM
Russel Reeder
Russel Reeder - avatar
+ 2
ok, not my piece of cake, good luck
16th Jul 2017, 4:41 PM
Skipper
Skipper - avatar
+ 2
If I'm understanding. Top end result, for example. (594 - 16)/594 * (10000-16) + 16 = (578 / 594 * 9984) + 16 = 9731.07 repeating... did I do something wrong? Seemed so legit at first Plug in low end. (0 * 9984) + 16 = 16, that works.
16th Jul 2017, 10:43 PM
Russel Reeder
Russel Reeder - avatar
+ 1
i would just do hitValue%maxHit if it is 20x greater than your ideal range.
16th Jul 2017, 11:07 AM
tom
tom - avatar
+ 1
@tom, your suggestion imply behaviors not wanted in a game. If the player has an attack and a level which makes the operation go to a multiple of maxHit+1, it will do 0 damage, but with just one level less, it will do maximum of damage You should do : (result - MinOfActualRange)/MaxOfActualRange*(MaxRangeWanted - MinRangeWanted) + MinRangeWanted With this formula, the result will be a projection of the old range in the new (like converting the reduction of a price from % to actual money)
16th Jul 2017, 10:26 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
unclear definition of the problem, as far as I am concerned. is this related to some HP hardware? some detailed illustration would help
16th Jul 2017, 12:35 AM
Skipper
Skipper - avatar
0
Working on a roleplaying game. HP as in Health Points. I can be more specific if u need.
16th Jul 2017, 12:45 AM
Russel Reeder
Russel Reeder - avatar
0
@Tom, can u elaborate a bit?
16th Jul 2017, 6:00 PM
Russel Reeder
Russel Reeder - avatar
0
hitValue = (levelX +2*atkY)-defZ; hitvalue%(maxHit+1);//would always result in a value less than or equal to maxHit
16th Jul 2017, 9:32 PM
tom
tom - avatar
- 1
Yeah, thats the problem @Keto, looking for help making my formula output the right range
16th Jul 2017, 3:45 AM
Russel Reeder
Russel Reeder - avatar