Post Reply 
Some math problems from video games.
08-24-2017, 08:00 PM
Post: #1
Some math problems from video games.
As far as my experience goes, normally in a game there is, aside from the ubiquitous logic that is required in programming, a lot of math involved in the graphic engine, or graphical interface and/or in the physics engine; but there are few games that involve non-trivial math in terms of game mechanics (that is, the set of rules that normally are taken in consideration by the player to win the game).

Well a recent sets of geometrical problems arose in Gladiabots (I recommend the game if you like solving problems with logic. I also recommend Euclidea). I did not attack them yet but I think they may be interesting.

In the game a damaged robot can flee from enemies, but until today the flee options were somewhat limited. Recently it was introduced the "free from all units that satisfy those conditions". The "all" part was mapped to the average position on the map of all the units that satisfy the given conditions.

In images, it is the following.
[Image: cRmunZVl.png]

So if the red points (enemies) don't move, the damaged robot (black) will move away from the blue dot in a straight line.

People complained because sometimes this solution does not really ensure that the damaged robot follows the shortest path (shortest as in "shortest felt by a player") to go away as quick as possible from the closest enemy and at the same time from all the other selected enemies. So they started to proposed several ideas.

The first based on the average angle. The angle between the robot and an enemy is given by: robot, enemy, fixed point on the map (so far East is chosen. That is the point x=50, y=0 . The map has points from x=-50 to x=50 and y=-50 to y=50). The resulting average of all angles computed against the selected enemies determines a place on the map from which the robot flees.
My observation about this is that (a) even with static enemies, the point could move as soon as the robot moves (because the angles change). I still have to prove this though. (b) due to (a), the robot may not follow a straight line while fleeing (as for 'a' I need to prove this as well). (c) there could be multiple points that could generate the computed average angle given the triplet: robot, resulting point, fixed point. For example for an angle of 90 degrees there is an entire semi circle of possible resulting points if I am not mistaken.

Then there is the proposal with adding vectors. One draws the vectors from the robot to the selected enemies, and then add those, finding the resulting vector that would determine a point (on the map or on an extended plane since the map is limited) from where to flee. Questions: is this point equal to the one found with the average angle in all cases? (I would tend for the "no")

Third proposal so far :
[Image: QrHOiLo.png]
(actually the circle can be draw with the radius equal to the furthest selected enemy from the given robot)

Questions: is the point computed as shown from the figure above effective compared to the average position? (for effective, see earlier paragraphs). Would it lay on the same line that connects the average position of all selected enemies?

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
08-25-2017, 03:32 AM
Post: #2
RE: Some math problems from video games.
OK, it's Friday afternoon, let's generalize...

How about associating a repulsive force field with each enemy, e.g. through a set of potential functions V(i,|r-r_i|) that (presumably) decrease with the distance (|r-r_i|) to the enemy object (i). By allowing these to depend on (i) you can cater for different types (strengths, ranges,...) of enemies.

To escape your enemies' "force field" you would then simply follow "minus the gradient" of the total potential, just like water running downhill, to minimize the potential (threat)....

And you can make it fancier by allowing the potentials to depend on angles relative to the enemies' orientations (blind spots, direction of barrels?) as well.
Find all posts by this user
Quote this message in a reply
08-25-2017, 07:36 AM
Post: #3
RE: Some math problems from video games.
Alex nice idea! I'll pass it over. Only, it is Friday morning. Europe time, best time.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
08-28-2017, 12:01 PM
Post: #4
RE: Some math problems from video games.
This is an amazing thread, thanks.

I don't know much about this subject, but I am really interested now.

Please, post more about it.

Thanks again.
Find all posts by this user
Quote this message in a reply
09-03-2017, 02:21 PM
Post: #5
RE: Some math problems from video games.
With the adding vectors method, the furthest enemy would have the most influence on the direction to flee, which seems counter intuitive. Perhaps retaining the directions of the vectors, but replacing the distances with their reciprocals would give better results. I think this is the same as AlexFekken's proposal when force is inversely proportional to distance.
Find all posts by this user
Quote this message in a reply
09-03-2017, 10:26 PM
Post: #6
RE: Some math problems from video games.
I did some sketches about "sandpiles" where sands accumulates in the position of the considered enemy bots, so the escaping bot can escape away like water, but I have to code it to see if it works in some random cases.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)