|
 |
|

October 8th, 2008, 03:35 PM
|
 |
Your Friendly Neighborhood Admin
|
|
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
|
|
|
A nice math function...
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"
Just because it's fun, here's an online version that runs in your browser:
Formula finder
Last edited by AceHart; February 17th, 2009 at 06:31 AM.
Reason: Added link to Formula Finder
|

October 8th, 2008, 03:37 PM
|
 |
Drown the fury and swallow the fire
|
|
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
|
|
Pretty cool idea (even though having to test the map just to get the values would be annoying  )
|

October 8th, 2008, 03:55 PM
|
 |
http://www.thehelper.net/forums/showthread.php?t=1
|
|
Join Date: Mar 2007
Location: Whereever I am needed
Posts: 1,997
|
|
Quote:
Originally Posted by Flare
Pretty cool idea (even though having to test the map just to get the values would be annoying  )
|
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?
Don't make it too easy for yourself. That was just "randomly" true ( actually I believe you designed the sequence like that  ).
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 
Best regards, Davey
|

October 8th, 2008, 04:04 PM
|
 |
You may call me 'Danny the Lone Wolf'
|
|
Join Date: Sep 2008
Location: UK
Posts: 574
|
|
If i was to use this system ( which i probably wont )
How would i get [ real y1 , real y2 and real y3 ] ?
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 )]}
|

October 8th, 2008, 04:05 PM
|
 |
Drown the fury and swallow the fire
|
|
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
|
|
Let's say you wanted to get a formula for
Level 1: 5
Level 2: 6
Level 3: 8
Jass:
call solve (5, 6, 8)
y1/2/3 are the particular values you have for the associated level of the ability
|

October 8th, 2008, 04:06 PM
|
 |
You may call me 'Danny the Lone Wolf'
|
|
Join Date: Sep 2008
Location: UK
Posts: 574
|
|
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 ? }
|

October 8th, 2008, 04:08 PM
|
 |
Drown the fury and swallow the fire
|
|
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
|
|
|
Ye (assuming I understand what you're asking) - you want to know how/where you get the values you pass to the function (y1, y2, y3), right?
|

October 8th, 2008, 04:11 PM
|
 |
You may call me 'Danny the Lone Wolf'
|
|
Join Date: Sep 2008
Location: UK
Posts: 574
|
|
Nice system you got there Ace
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 ?
|

October 8th, 2008, 04:23 PM
|
 |
is actually programming!
|
|
Join Date: Sep 2005
Location: Boston
Posts: 3,973
|
|
|
Almost pointless post?
Basic Derivatives, or algebra, depending on how you look at it  :
Quote:
|
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!
__________________
Fly like a butterfly and sting like a shotgun blast to the face
|

October 8th, 2008, 04:53 PM
|
 |
Veteran Scripter
|
|
Join Date: Jun 2007
Posts: 311
|
|
|
|

October 9th, 2008, 01:23 PM
|
 |
Your Friendly Neighborhood Admin
|
|
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
|
|
|
|

October 17th, 2008, 07:59 AM
|
|
|
|
Join Date: Aug 2005
Posts: 3,687
|
|
|
(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)
|

October 17th, 2008, 08:31 AM
|
 |
Your Friendly Neighborhood Admin
|
|
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
|
|
Drop?
I wrote "The Amazing Formula Finder by AceHart"(tm) and put it online... what more can you ask for?
Link:
Formula Finder
|

October 17th, 2008, 12:20 PM
|
 |
Lorem Ipsum Dolor Sit.
|
|
Join Date: Aug 2007
Location: England (GMT +0)
Posts: 3,818
|
|
Wow, that formula finder is useful
|

November 24th, 2008, 09:29 AM
|
 |
Currently addicted to Lucia buns, A.I and SC2
|
|
Join Date: Dec 2006
Location: Home, sweet home!
Posts: 614
|
|
You just made my homework LOTS easier. Thanks!
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|