The Helper Forums
The Helper offers free technical support for computer games,
computer hardware, and other computer software. Staffed
by volunteer tech support workers, The Helper is highly
regarded as a premium destination for those who are
experiencing technical problems with their computers.
Affiliate Sites
Warcraft 3 World Editor Tutorials - The Greatest Resource for the new Warcraft 3 Mapper
Silkroad Online Forums
Houston Microsoft Access, VBA and Visual Basic Programming
The source for NUON news, information, and games.
Griffonrawl Muay Thai and MMA
Warcraft 3 Modding Site.
Element Tower Defense by Karawasa.
Topaz Games.
Chernobyl Lost Riddles

Able Auto Glass specializes in Houston Auto Glass Replacement as well as windshield repair and replacement services.
Apex Steel Pipe - Buys and sells Used Steel Pipe.

Go Back   The Helper Forums > Warcraft Zone > World Editor Help > Tutorials and Resources > Systems, Triggers and Demo Maps

Reply
 
Thread Tools Display Modes
  #1  
Old October 8th, 2008, 03:35 PM
AceHart's Avatar
AceHart AceHart is offline
Your Friendly Neighborhood Admin
 
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
AceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than TH
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
__________________
Minigame: > Chaos Control
Defense: Defend the Tower II
Must see: Revenge of the Skeletons

Last edited by AceHart; February 17th, 2009 at 06:31 AM. Reason: Added link to Formula Finder
Reply With Quote
  #2  
Old October 8th, 2008, 03:37 PM
Flare's Avatar
Flare Flare is offline
Drown the fury and swallow the fire
 
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)
Pretty cool idea (even though having to test the map just to get the values would be annoying )
__________________
Join the Music Fans group today!
Blind Guardian - A Voice in the Dark | Dream Theater - The Dark Eternal Night
[22:19] <%Romek> Larc's ass was awesome
Reply With Quote
  #3  
Old October 8th, 2008, 03:55 PM
SerraAvenger's Avatar
SerraAvenger SerraAvenger is offline
http://www.thehelper.net/forums/showthread.php?t=1
 
Join Date: Mar 2007
Location: Whereever I am needed
Posts: 1,997
SerraAvenger is climbing the respect ladder even higher (+600)SerraAvenger is climbing the respect ladder even higher (+600)SerraAvenger is climbing the respect ladder even higher (+600)SerraAvenger is climbing the respect ladder even higher (+600)SerraAvenger is climbing the respect ladder even higher (+600)SerraAvenger is climbing the respect ladder even higher (+600)
Quote:
Originally Posted by Flare View Post
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?
Quote:
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 ).
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
Reply With Quote
  #4  
Old October 8th, 2008, 04:04 PM
DrEvil's Avatar
DrEvil DrEvil is offline
You may call me 'Danny the Lone Wolf'
 
Join Date: Sep 2008
Location: UK
Posts: 574
DrEvil seems to have the helping tendency (+150)DrEvil seems to have the helping tendency (+150)
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 )]}
Reply With Quote
  #5  
Old October 8th, 2008, 04:05 PM
Flare's Avatar
Flare Flare is offline
Drown the fury and swallow the fire
 
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)
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
__________________
Join the Music Fans group today!
Blind Guardian - A Voice in the Dark | Dream Theater - The Dark Eternal Night
[22:19] <%Romek> Larc's ass was awesome
Reply With Quote
  #6  
Old October 8th, 2008, 04:06 PM
DrEvil's Avatar
DrEvil DrEvil is offline
You may call me 'Danny the Lone Wolf'
 
Join Date: Sep 2008
Location: UK
Posts: 574
DrEvil seems to have the helping tendency (+150)DrEvil seems to have the helping tendency (+150)
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 ? }
Reply With Quote
  #7  
Old October 8th, 2008, 04:08 PM
Flare's Avatar
Flare Flare is offline
Drown the fury and swallow the fire
 
Join Date: Aug 2006
Location: Ireland
Posts: 7,297
Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)Flare has a reputation beyond repute (+1000)
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?
__________________
Join the Music Fans group today!
Blind Guardian - A Voice in the Dark | Dream Theater - The Dark Eternal Night
[22:19] <%Romek> Larc's ass was awesome
Reply With Quote
  #8  
Old October 8th, 2008, 04:11 PM
DrEvil's Avatar
DrEvil DrEvil is offline
You may call me 'Danny the Lone Wolf'
 
Join Date: Sep 2008
Location: UK
Posts: 574
DrEvil seems to have the helping tendency (+150)DrEvil seems to have the helping tendency (+150)
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 ?
Reply With Quote
  #9  
Old October 8th, 2008, 04:23 PM
Darthfett's Avatar
Darthfett Darthfett is offline
is actually programming!
 
Join Date: Sep 2005
Location: Boston
Posts: 3,973
Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)Darthfett has been here way too long (+2000)
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
Reply With Quote
  #10  
Old October 8th, 2008, 04:53 PM
Strilanc's Avatar
Strilanc Strilanc is offline
Veteran Scripter
 
Join Date: Jun 2007
Posts: 311
Strilanc seems to have the helping tendency (+150)Strilanc seems to have the helping tendency (+150)
Solution for arbitrary degree polynomials:
http://en.wikipedia.org/wiki/Polynomial_interpolation
Reply With Quote
  #11  
Old October 9th, 2008, 01:23 PM
AceHart's Avatar
AceHart AceHart is offline
Your Friendly Neighborhood Admin
 
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
AceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than TH
Formula Finder
__________________
Minigame: > Chaos Control
Defense: Defend the Tower II
Must see: Revenge of the Skeletons
Reply With Quote
  #12  
Old October 17th, 2008, 07:59 AM
Uberplayer Uberplayer is offline
 
Join Date: Aug 2005
Posts: 3,687
Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)Uberplayer has a reputation beyond repute (+1000)
(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)
__________________
<phyrex1an> you're all noobs
<phyrex1an> except uber
Reply With Quote
  #13  
Old October 17th, 2008, 08:31 AM
AceHart's Avatar
AceHart AceHart is offline
Your Friendly Neighborhood Admin
 
Join Date: Sep 2004
Location: GMT + 1
Posts: 17,493
AceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than THAceHart has more rep than TH
Drop?
I wrote "The Amazing Formula Finder by AceHart"(tm) and put it online... what more can you ask for?

Link:
Formula Finder
__________________
Minigame: > Chaos Control
Defense: Defend the Tower II
Must see: Revenge of the Skeletons
Reply With Quote
  #14  
Old October 17th, 2008, 12:20 PM
UndeadDragon's Avatar
UndeadDragon UndeadDragon is offline
Lorem Ipsum Dolor Sit.
 
Join Date: Aug 2007
Location: England (GMT +0)
Posts: 3,818
UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)UndeadDragon has a reputation beyond repute (+1000)
Wow, that formula finder is useful
__________________
/ .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. \
//I am a web designer. Clicky Clicky.\\
/ .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. \
Reply With Quote
  #15  
Old November 24th, 2008, 09:29 AM
Siretu's Avatar
Siretu Siretu is offline
Currently addicted to Lucia buns, A.I and SC2
 
Join Date: Dec 2006
Location: Home, sweet home!
Posts: 614
Siretu is starting to get some respect (+100)Siretu is starting to get some respect (+100)
You just made my homework LOTS easier. Thanks!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:07 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.