Optimal Realm Defense
A mathematics professor introduced me to an interesting optimization problem in a video game setting. It goes like this:
"You are a warrior defending a region from a monster invasion! The region is represented by a square map, and you can select any starting position on the map. After you select your starting position, monsters will randomly spawn on the map, but you must choose where to start before they spawn. Once they appear, you must travel to each one and defeat them. Where should you start to minimize travel time on average?"
Understanding the Problem
To tackle this problem, we need to make a few assumptions and lay some groundwork:
- Monster Spawn: Monsters spawn with uniform random probability. That is, they are equally likely to spawn at any point on the map.
- Map Width: The map width is set to one for ease of future calculations.
- Travel Time: We assume travel speed is constant and terrain has no impact on travel time. Thus, a straight line is the fastest route between any two points.
Simplification and Approach
This problem is complex and can be approached from several directions. When faced with an open question like this, it’s a good idea to simplify it in stages until reaching the simplest unsolved version you can think of. That done, you can work through the problems from least to most complex, letting findings from each step inform the next. Use the interactive portion of the document below by clicking on highlighted text to see how we can simplify this problem into something approachable.
Interactive Exploration
When you see a word or phrase highlighted, it means you can click on it to make some changes, usually to the map on the left. Let's get started!
So let's see what the problem looks like. We select a starting point and monsters spawn. Then, we can draw the paths between the points. What we have now is a mathematical graph, a diagram of sorts that displays vertices (our enemies/hero) and edges (the paths between them). Specifically, we have a "complete graph" - one in which every point is connected to every other point.
Our goal now is to find the minimal travel distance required for the hero to touch every other point. Luckily, this is not a far-out concept in mathematics either. A path that connects each vertex (enemies and hero in our case) exactly once is called a Hamiltonian path. So we are looking for the shortest hamiltonian path that starts with our hero. Pretty easy, right?