[CS-FSLUG] Calculu, was Re: [OT] Re: Seeking opinions

Nathan T. celerate at gmail.com
Sun Jun 18 16:45:33 CDT 2006


Seeing as we were talking about applications of Calculus in real life
lately, I might as well  share with you folks what I've been doing
yesterday.

I was playing "Rise of Nations" yesterday, and in that game there is a
certain structure you can build in one of your towns called the "Terra
Cotta Army". Anyway, besides being a step towards a victory condition,
building such structures called "wonders" provides advantages, in this
case it would produce one of a particular unit every few seconds. For
the first unit it would take 30 seconds, and for every unit already
built half a second would be added on to the time between builds.

The problem with determining how many units would be built within a
certain amount of time with a single formula would be that the number
of units is one of the variables increasing the time to the next unit,
so you've either got a recursive function or a loop, but not one
single formula. So instead I found out how much time it would take to
make a certain number of units. I reasoned out that the amount of time
between one unit being built after the previous would be 30+0.5x where
x is the number of already created units. That could be represented in
Leibniz notation as dt/dx = 30+0.5x. I then integrated the formula
with respect to x which gave me 30x+0.5x^2+C, and I tried the formula
out hoping that the constant would be easy enough to find. I got the
following results

   # of units    |  Seconds from formula  |  Actual time  |  Error
--------------------|-----------------------------------|---------------------|----------
         1         |            30.25               |      30.00       |  0.25
         2         |            61.00               |      60.50       |  0.50
         3         |            92.25               |      91.50       |  0.75
         4         |           124.00              |     123.00      |  1.00

As you can see the error was a linear function, 0.25x to be exact, so
that was the not-so-constant constant.

So the final formula was 30x+0.25x^2-0.25x , as to why the 0.25x
didn't show up in the first formula I don't know, but both formulas
worked :-P

I could have probably saved myself quite a bit of time simply using a
recursive function or loop, but that would have been settling for less
for me. Ultimately I put my formula to use in a very basic program to
solve the original equation by dividing the time by the formula while
changing the x variable until it found the closest match to 1, but I
might fix that program up later so it's more efficient, as it is now
it works it's way down from a maximum x value that'll cover up to just
over ten hours of game play after the wonder is built.




More information about the Christiansource mailing list