Showing posts with label algebra. Show all posts
Showing posts with label algebra. Show all posts

17 March 2019

Guild Wars 2: Tyria's Gravity

Finally, Tyria's gravity has been calculated. Now we can compare to other planets' gravities and maybe draw some new conclusions from it? Anyways we left off by figuring out that Guild Wars 2 does indeed seem to have gravitation.

Next Steps

So, if we assume Guild Wars 2 does indeed have gravity - where things seem to point to - then we can calculate it. Calculating gravity is the same as acceleration. Acceleration is often related to F = m * a. Unfortunately, we know neither F nor m. There's another formula as well though. Acceleration is the change of velocity over time. So, basically a = ∆v / ∆t. Next up is another problem. We don't know the velocity of our character. It's not shown in any kind of way in Guild Wars 2. This means we need to calculate it as well. For this, we have a formula as well. The time it took to get from a position to another or the distance passed in a time frame. That's v = ∆x / ∆t.

The Experiment


Okay, so what we need to do is calculate the velocity at two different points of time that are still related to each other (e.g. different points of time in one fall). To get the velocity we need to calculate how long we take to fall a certain distance. We obviously need some way to tell the time, a watch could do this, however, the fall speed is too great to use a stopwatch this rapidly. Thusly I'm gonna record the fall on video and use the footage and frames to measure the fall speed. As a distance, I'm gonna use the Necromancer's staff traps that provide a 240 unit radius or 480 unit diameter. As a drop, I'm gonna use the one at the Kormir High Road.


To do the experiment I need to start the recording drop down while placing my marks on the wall and then get up as fast as possible, position the camera and jump down. It only took me one try even though it sounds quite stressful.

Analysis of the Footage

Next up, we're gonna analyze the footage. Specifically, we want to mark the two frames that meet the respective points well enough. Then we take the time between those.

As a reminder to calculate the gravitation we use the formula a = ∆v / ∆t with ∆v = v2 - v1 with v = x / ∆t with x = pos2 - pos1 and t = t2 - t1

If we combine everything to a big formula we get: 
a = ((pos2v2 - pos1v2) / (t2v2- t1v2)) - ((pos2v1 - pos1v1) / (t2v1 - t1v1)).

Screenshot pos1 of v1
The first mark or first velocity v1 we reach pos1 after about 30 seconds of the fall. When using Vegas Pro 15 - which was available last year during a Humble Bundle :P - the time is given in hours, minutes, seconds and 1/30th of a second using the format HH:MM:SS:ss. We convert the next smaller unit to seconds by dividing it through 30 and multiplying the result with 100. E.g. 30 / 30s = 1s or 9 / 30 = 0.30s. This point in time in the video is t1 is 29:24, so 29s + 24 / 30s = 29.80s. The second position pos2 is reached at 30:08 which is 30s + 8 / 30s = 30.27s. This means that ∆t = t2 - t1 so 30.27s - 29.8s = 0.47s. We already know the distance as it is the diameter of the staff mark which is
Screenshot pos2 of v1
480 units. Now we can calculate the velocity via v1 = ∆x / ∆t. So our first velocity v1 is 480u / 0.47s = 1021.28u/s. 

Screenshot pos1 of v2
Now on to the second one. We reach this point t1 in the video at 31:01. That's 31s + 1 / 30s = 31.03s. The second point t2 at the end of the mark is reached at 31:13 equivalent to 31s + 13 / 30s = 31.43s. Calculating the delta for v2 we get ∆t = 31.43s - 31.03s = 0.39s.

With this we can calculate the velocity v2 which is 480u / 0.39s = 1230.77u/s.

Screenshot pos2 of v2
At this point I must mention the difference between the first delta time and the second delta time is ∆t = 0.47s - 0.39s = 0.08s. Since my Guild Wars 2 runs at ~30 frames per second and my recording at 60 frames per second we are still limited to the ~30 frames per second from Guild Wars 2. One frame thus, as represented by Vegas Pro is 1/30th of a second. This means that one frame is equal to 1 / 30s = 0.1s. This means the difference between the two delta's could just as well be a measurement error and thus would require more research.

For the rest of the post, I'm gonna assume this is not a measurement error as such I'm gonna continue.

The Finale

Now that we have the two velocities and we can calculate the acceleration. As a reminder, we're gonna calculate the acceleration using a = (v2 - v1) / (t2 - t1). For t2 and t1 we're gonna use the start points pos1. Filling out the variables we get a = (1230.77u/s - 1021.28u/s) / (31.03s - 29.80s) = 209.49u/s / 1.23s = 170.32u/s². Now to convert this to something that's more familiar to us and less useful for theorycrafting (heh :D) using the conversion from units to metric and to feet:

in metric: 170.32u/s² * 2.52cm/u = 429.21cm/s² | 429.21cm/s² / 100 = 4.29m/s²
in feet: 170.32u/s² * 0.083ft/u = 14.14ft/s²
in mph: 14.14ft/s² / 5280ft/mile * 3600 = 8.64mph

I have a small little book with formulas and data in it that helps students in exams. Let's look at which planet would equal this gravitation. 

Earth with a g-factor of 9.81 is well known. the nearest ones below are Merkur with 3.7 and Mars with 3.71.

Thus we've got us a planet with a little higher gravitational constant than Merkur or Mars.

Now if someone can do the drop with 60 frames per second it would be appreciated. Until disproven... I rest my case. Have a good day/night. 

17 February 2019

Merge Dragons: Recursive Merging!

PC-master race, am I right? I usually don't play mobile games but there was a time when I did. There was also a time when I was playing mobile games to earn cash. It works, but extremely inefficient. (it's more efficient than my blog right now..) Anyways instead of playing Diablo Immortal, if you like puzzle games and build-up games, you can play Merge Dragons instead!

Merge Dragons

This is a mobile game that I came across using recommendations from an app that suggests you other apps and gives you points when you play them, which you can swap for gift cards or PayPal payment. Anyways Merge Dragons is a puzzle game that allows you to - as the name says it - merge objects of the same type to create new objects. You then travel through different levels that are so far extremely easy to play and challenges which timed levels that are hard enough that even I have my problems with some. So, the goal is to finish the main objective of these levels.

The levels reset every time you go into them, however, there's a camp that works similar to the levels except it doesn't reset. This means you can pretty much build up everything there. Hence I said puzzle and build-up games.

Merging Stuff

Let's get to the real deal. In this game there are two ways to merge things:
a) Merge three objects, which will return a higher level object.
b) Merge five objects, which will return two higher level objects.
Objects can be leveled up to a certain point, the level cap or maximum level of an object. This differs from the object category to the object category. Due to the rules and confinements of the levels, you will have a few issues given by the different types of objects. These issues are mainly:

  1. space, it takes to combine objects
  2. the object count, it takes to get the maximum
  3. the  time, this game can really eat your time, be careful
Under these circumstances, I am wondering... how much do you save by going for five instead of three objects and how much more space do you need?

Using Math :D

Have I mentioned that I wrote a math exam yesterday? Fun! Anyways let's get into it right away.

Merging With Three

First up, the basic merge contains three objects of your liking that are the same (but not exact!) to get out one of the higher ones. For example, we need 3x level one to get 1x level two. Then we need 3x level two to get one level three. Needing 3x level two for one level three means we need 3 * 3 = 9 levels one. If we follow this thought further we might notice that the numbers will go like this:
3, 9, 27, 81, 243, 729, ...
These are equal to the exponents of three:
31, 32, 33, 34, 35, 36, ... 
Notice that the exponent is equal to the level - 1 of the object. If we assume n is the level of the object we want to produce we need 3n objects of the lowest level (level one):
f(lvl) = 3(lvl - 1)     for lvl ∈ N and lvl > 1
Now for space... we need three-space to create the next higher one. This means we need at most three times each previous level. That gives us this function:
f(lvl) = (lvl - 1) * 3   for lvl ∈ N and lvl > 1
So, for a level five object we need 35 = 243 level one objects and a maximum of f(5) = (5 - 1) * 3 = 12 fields of space.

Merging With Five

Now we merge 5x level one and get 2x level two. This is not an efficient way to only get one of the next higher ones. However, it speeds things up. Ignoring the rest if we have 10x level one we get 4x level two giving us 1x level three. So respective to whether or not we end up with 1x level three or 2x level three we had five or less than five before. 

Technically the algorithm is:
  1. divide five: 10 / 5 = 2
  2. increase the level by one: level one -> level two
  3. multiply by two: 2 * 2 = 4
  4. round down: floor(4) = 4
  5. if the number is equal or greater than five go to 1. else go to 6.: 4 < 5: go to 6.
  6. if the number is greater or equal to three increase level by one: level two -> level three
  7. if the number is greater or equal to three, divide by three: 4 / 3 = 1.333...
  8. round down and done: floor(1.333...) = 1
Here's the python code:

import math
#algorithm
def algo1(amount):
    level = 1
    while amount >= 5:
        amount /= 5
        level += 1
        amount *= 2
        amount = math.floor(amount)
    if amount >= 3:
        amount /= 3
        level += 1
        amount = math.floor(amount)
    return amount,level

We can't reverse this algorithm due to the rounding. If we do it most efficient (only five-merges) we will have some leftovers. The motivation behind this is that we get the maximum at the end. If you want to get only one at the end you have to round everything off with three-merges. To reverse it we start off by either one or two (if it's higher you could merge it to a higher as well and calculate with that). If it's one it is equal to a merge of three. If it's two it's a merge of five. In each of the cases, we multiply with the respective value. We decrease the level and then we get into the loop. In the loop, we need to make sure that our number is always even as we can't get odd results when always doing five-merges if we do have an odd one we will add one to it. This is going to be one of the leftovers.
After that, we divide by two (as we always create two), next up we multiply by five (since we always need five to make a higher-level one) which results in the level decreasing again. Once we reach level one we stop.

If we wanted to make 1x level five object, for example, it would go like this:
  1. if equal to two: set to five else set to three: 1, set 3
  2. decrease the level by one: level five -> level four
  3. if it's odd add one to it: 3 + 1 = 4
  4. divide by 2: 4 / 2 = 4
  5. decrease the level by one: level five -> level four
  6. multiply with five: 4 * 5 = 20
  7. if it's level one, then stop, else go to 3.
Here's the respective python code:

import math
#algorithm
def algo2(amount, level):
    if amount == 2:
        amount = 5
    else:
        amount = 3
    level -= 1
    while level > 1:
        if amount % 2 == 1:
            amount += 1
        amount /= 2
        level -= 1
        amount = math.ceil(amount)
        amount *= 5
    return amount

The result is 65. If we use our function and iterate over the level increasing it we get the following numbers:
3, 10, 25, 65, 165, 415, 1040, 2600, 6500
vs
3, 9, 27, 81, 243, 729, 2187, 6561, 19683
Well... merging five saves us a lot of work, haha. Unfortunately, there's a downside.

Merging five takes a lot more space. How much? Well.. in the camp there's a setting to disallow merges unless you actively move one object onto a set of 2+ of the same type. If we assume we have this setting on it takes similarly to our merge three functions:
f(level) = (level - 1) * 5

Finish!

Well, is there a simpler way to calculate it? I don't know or have found one. You can basically use an approximate but I've checked the numbers and I haven't seen a simple relation between them to calculate them easier. I'm not sure if I make another post on the Formula for a five merge outside the camp. I guess it depends on how many views this post gets. Let's say.. a hundred views are enough to be worthy.

Oh and on a side note: Upgrading the dragons do not provide more work power, it only increases your dragon power for unlocking more area in the camp. Thus it actually decreases the actions your dragons can do. Decide for yourself which you prefer.


28 January 2019

Guild Wars 2: Which Height is Deadly?

A few days ago I somehow ended up talking about falling damage with someone. He mentioned that it is known at which falling height (in-game units) it is deadly. What a snarky little detail. Wouldn't it be interesting to know how much it is in a more common unit? Well, let's do that and see what we can deduct from it!

In-Game Falling Death Data

On the page, for falling damage on the official Guild Wars 2 wiki, we can find a nice little graphic that shows how much %-health you lose respectively to which height you fall from. Due to copyright, I can't post it here so I have to describe it. It shows the %-health loss in a step of 10 starting from 0% and going to 180% and the distance in in-game units with a step of 100 going from 0 to 1500. It marks anything starting with 1500 as deadly even with fall damage reduction trade and 1250 units or higher as deadly without falling damage trait.[1]

Conversion

A long time ago I already did a conversion from units to meters and feet. I'll leave this link to the post so you can check on it if you don't remember.

The conversion was 1 Unit is equal to 2.52cm or 0.083ft.

Now we just have to put in the numbers and do the calculation...
a) with falling damage reduction: 1500units * 2.52cm/unit = 3780cm or 37.8m.For feet it's 1500units * 0.083ft/unit = 124.5ft
b) without falling damage reduction: 1250units * 2.52cm/unit = 31.5m.For feet it's 1250units * 0.083ft/unit = 103.75ft
Well... that sounds ridiculous. I don't have anything to compare it to though. So let's see for a real-life equivalent to compare.

Most Reliable Resource

Looking through the interwebs there are a lot of stories about huge falls and indecisiveness of accurate numbers. Though according to a paper of NASA the fatal speed seems to be 16m/s on hard surfaces.[2] Assuming the acceleration due to gravitation a to be 9.81m/s² and the formula being V = a * t. The total time of the fall would be t = V / a, thereby 16m/s / 9.81m/s² = 1.63s. 

To calculate the distance of the fall we have to put this into the following formula: d = 1/2 * g * t²
Thus our falling distance is 1/2 * 9.81m/s² * (1.63s)² = 13.03m. (14.75ft)

Can We Calculate the Gravity on Tyria?

To do that we would need to know how long it takes to fall a certain distance or how long it takes to fall 1250, additionally it wouldn't be accurate enough compared to simply calculating the falling speed and acceleration between reaching two points during a free fall.

Nonetheless, it's still interesting to see that it takes twice the height in Guild Wars 2 to die compared to real life. Float away Sapient Beings, float away! 

[1] https://wiki.guildwars2.com/wiki/Damage#Falling_damage
[2] https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19930020462.pdf

About Me

My photo
I'm a B.Sc. Games Engineer and I created this blog to share my ideas, theorycrafting, thoughts and whatever I'm working on or doing.