Snippet A nice math function...

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Well, "nice"... no idea what to call this.
or if there even is any kind of need...

Anyway, ever wanted something like
do 5 damage on level 1,
do 8 damage on level 2,
do 12 damage on level 3,
do 17 damage on level 4,
...

Only to sit there and try to come up with a formula instead of "if level == 1 then ..."?

So,
5, 8, 12, 17, 23
take the differences from one to the next:
3, 4, 5, 6
take the differences from one to the next:
1, 1, 1
The line is constant!
Given it was the second, the most common case,
our damage can be calculated with this formula:
damage = a * level * level + b * level + c

But... what are a, b and c?

That's where this function comes to the rescue:

JASS:
function solve takes real y1,real y2,real y3 returns nothing
    local real a = 0.5 * (y3 - 2 * y2 + y1)
    local real b = y2 - y1 - 3 * a
    local real c = y1 - a - b
    local string s1 = "+"
    local string s2 = "+"
    if b < 0 then
        set s1 = "-"
        set b = -b
    endif
    if c < 0 then
        set s2 = "-"
        set c = -c
    endif
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, R2S(a) + " * level * level " + s1 + " " + R2S(b) + " * level " + s2 + " " + R2S(c))
endfunction


Examples:
call solve(5, 8, 12) (always call with the expected values on levels 1 to 3)
Which will say
0.5 * level * level + 1.5 * level + 3

Or,
call solve(10, 18, 34):
4 * level * level - 4 * level + 10


Of course, this could be improved by telling it to simplify
4 * level * level - 4 * level + 10
to
4 * level * (level - 1) + 10
but, then again, that would be the famous "exercise for the interested reader" :p


Just because it's fun, here's an online version that runs in your browser:
Formula finder
 

SerraAvenger

Cuz I can
Reaction score
234
Pretty cool idea (even though having to test the map just to get the values would be annoying :p)

Exactly. Doing this in JASS is like trying to teach a squirrel fly.

Also, wouldn't this require to have the graph of the damage increase have a certain shape?
The line is constant!
Don't make it too easy for yourself. That was just "randomly" true ( actually I believe you designed the sequence like that :p ).
You can't draw a 3rd degree polynomial through ALL sets of points.


So, why not ( Damien will hate me for this :evilgrin: ) do an executable of it with something easy like Python2Exe ^.-
Python comes here quite handy; You don't need no call for MAXXXXEFFICIENCYY!!!!, so you also needn't call for Perl ( oO ).
Anyway, just choose a language that
+ knows regex ( for an input like a;b;c;d )
+ can handle higher degree polynomials
+ has a lightweight + nice GUI toolkit ( like PythonQT for python )
+ dynamically allocates arrays

And code a similiar function there. Perhaps I'll do it some sleepless weekend :p
Best regards, Davey
 

DrEvil

FCRI Associate!
Reaction score
111
If i was to use this system ( which i probably wont )

How would i get [ real y1 , real y2 and real y3 ] ?

JASS:
function solve takes real y1,real y2,real y3 returns nothing


Sorry to ask im just trying to get used to using JASS functions taking stuff in [ Somehow , i dont know ]

Thanks for answering {[( In future post's )]}
 

DrEvil

FCRI Associate!
Reaction score
111
So
Code:
call solve (5, 6, 8)

Would call the function solve giving ?
real y1 = 5
real y2 = 6
real y3 = 8

EDIT : call solve ( 5, 6, 8) { Would be a gui custom script ? Calling frm a spell cast maybe ? }
 

DrEvil

FCRI Associate!
Reaction score
111
Nice system you got there Ace :thup:

Yes , Thanks for helping me understand Flare .

Offtopic

And for other functions i could use like getting x,y coordinates and returning for a spell ?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Almost pointless post?

Basic Derivatives, or algebra, depending on how you look at it :p:

damage = a * level * level + b * level + c

ax² + bx + c is the basic quadratic equation.

You basically wrote a guide on how to get a formula when you already know the intervals. Basically, it's finding the derivative of an equation you don't know.

The reverse derivative (being able to find the output from any level):

X is the level.
Y is the damage amount.
Y' is the difference of damage between one level and the next.
Y'' is how much Y' changes every level.

Y'' = c __ c is a constant number. Since Acehart solved the difference in difference in damage (Y'') to being 1, we can just plug in 1 for c.

Y' = cx + d __ d is an unknown constant. In this case, you can substitute 3, 4, 5, 6 for difference in damage (Y'), making d become 2.

Y = c x²/2 + dx + e __ e is an unknown constant. in this case, we can plug in 5, 8, 12, 17, 23 for damage (Y) and solve for e.

c = 1 :
Y'' = 1
Y' = x + d
Y = X²/2 + dx + e

(1) + d = 3

c = 1, d = 2:

Y'' = 1
Y' = x + 2
Y = X²/2 + 2x + e

(1)²/2 + 2(1) + e = 5

c = 1, d = 2, e = 2.5

Y'' = 1
Y' = x + 2
Y = X²/2 + 2x + 2.5

Now you can calculate the amount of damage dealt to any level using Y = X²/2 + 2x + 3

*Work in Progress Post, the formula is not quite working out as I intended. Sorry to post it incomplete, but I have a class to be at. :S*

See? Calculus is useful! :p
 
Reaction score
456
(The title of the thread fights against all those title writing rules.)

Why did you let this drop? It's awesome!

(you should return to the chat, so I could bomb you at my random questions)
 

UndeadDragon

Super Moderator
Reaction score
447
Wow, that formula finder is useful :thup:
 

Furby

Current occupation: News poster
Reaction score
144
Just an idea

What about some function like this:

Code:
...
set value = GetValue(a,b,c,level)
...


which takes a,b,c like in your first post and returns value for level taken in function?

I think it will be more helpfull like this because if i want to find formula I will go to some page with the Formula Finder. I think no one will use it by map if he know where the formula finder is. :rolleyes:
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Another interesting thing would be to know the equations for the x^3 and x^4 coefficients in the formula finder (since I'm too lazy to figure them out myself).
 

emjlr3

Change can be a good thing
Reaction score
395
you sure that thing works..
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top