HP Forums

Full Version: Some math problems from video games.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

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 :

(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?
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.
Alex nice idea! I'll pass it over. Only, it is Friday morning. Europe time, best time.
This is an amazing thread, thanks.