I speedrun the basic training mode in Team Fortress 2 (Valve, 2007). At one point, the player is required to destroy a series of targets that pop up randomly. These targets are the only random part of the run; everything else is consistent and optimized.
The targets are laid out in two rows of three and one row of one, as shown in the following diagram. The site tells me I'm not allowed to post images, so:
Primary targets can only be destroyed by a primary weapon, secondary targets by a secondary weapon, and melee targets by a melee weapon.
8 groups of targets appear, randomly and independently, during the practice. Except for the first group, no group will appear until the previous one has been destroyed. A group of targets may consist of:
- The melee target;
- Any one or two secondary targets; or
- Any one or two primary targets.
We complete this section as the "Scout" character, who has the following weapons:
- Primary: Scattergun. Hitscan, meaning the bullets travel instantaneously. Can fire a shot every 0.625 seconds.
- Secondary: Pistol. Hitscan. Can fire a shot every 0.17 seconds.
- Melee: Bat. Sends a hitscan attack 0.25 seconds after the player attacks. Can fire a shot every 0.5 seconds. (This is irrelevant as there is at most one melee target, and the time between groups of targets exceeds 0.5 seconds.)
In Team Fortress 2, you can only hold one weapon at a time, and after you switch to another weapon you must wait 0.5 seconds before you can shoot again. Since the player does not know what target is going to appear next, they must guess and hold out a weapon. If they guess correctly, they can destroy the targets with the weapon they are holding. If they guess incorrectly, they lose 0.5 seconds waiting to shoot.
Given this information, what weapon should I hold out to optimize my average completion time?
Throughout this post, we make the simplifying assumption that the player has perfect aim and can snap from target to target instantly.