All puzzles › Game Development

Game Development Practice Problems

30 puzzles (9 easy, 18 medium, 3 hard), in Python, JavaScript and C++.

The algorithms inside a game engine. A fixed-timestep loop, A* pathfinding, behavior trees, spatial hashing, object pools, autotiling and a tech tree, thirty puzzles covering every pattern from sliding windows to knapsack.

The puzzles, easiest first

  1. Back to Front (Easy): Games draw far things first so near things paint over them, which is called the painter's algorithm.
  2. Cut the Silence (Easy): A recorded sound effect has silence at both ends, which delays it when it plays.
  3. Find the Stutter (Easy): A stutter is a run of slow frames, and players feel it even when the average frame rate looks fine.
  4. How Many Bag Slots? (Easy): A player picks up items[i] in amounts counts[i].
  5. Level Up (Easy): Everyone starts at level 1, and thresholds[i] is the total XP needed to reach level i + 2, in increasing order.
  6. Off One Edge, On the Other (Easy): Screen wrap turns the world into a loop: fly off the right edge and you come back on the left, as in Asteroids.
  7. Pause on Top of Play (Easy): Game menus are a stack: the pause menu sits on top of the game, and closing it returns you to exactly the game underneath.
  8. The Steady Clock (Easy): Every game loop draws frames as fast as the screen allows, but physics has to advance in a fixed timestep or it behaves differently on fast and slow machines.
  9. Who Is Allowed to Touch? (Easy): Each object has a layer, one bit saying what it is, and a mask, a bitmask of every layer it reacts to.
  10. Are All the Rooms Connected? (Medium): A dungeon generator has made n rooms and dug some corridors, each joining two rooms.
  11. Ctrl+Z in the Level Editor (Medium): A level editor gets commands: "place NAME" puts down a tile, "undo" takes back the last placement, and "redo" puts back the last thing undone.
  12. Don't Eat Yourself (Medium): A snake starts at row 0, column 0 on a board of the given width and height.
  13. Fewest Jumps to the Flag (Medium): Platforms sit in a row and reach[i] is how many platforms ahead you can jump from platform i.
  14. Fewest Towers on the Lane (Medium): Enemies spawn at the given spots along a straight lane, in no particular order.
  15. Keep the Combo Alive (Medium): A fighting game rewards a combo: hits landed close together.
  16. Last One Standing (Medium): n players numbered 0 to n - 1 sit in a circle.
  17. Lock On (Medium): Auto-aim locks on to the closest enemies.
  18. Only Check the Neighbors (Medium): Checking every pair of objects for collisions is O(n squared).
  19. Pack the Loadout (Medium): Each piece of gear has a weight and a power.
  20. Recycle the Bullets (Medium): Creating a fresh bullet every shot would make the garbage collector stutter, so games keep an object pool of reusable slots.
  21. Research Order (Medium): A strategy game's tech tree has n technologies, and each pair [tech, pre] means tech can't be researched until pre is done.
  22. Spend the Mana (Medium): Each spell has a mana cost and a damage, and each can be cast once.
  23. Standing on Solid Ground (Medium): A tilemap stores a level as a grid, which turns collision into arithmetic.
  24. Take the Least Damage (Medium): A hero crosses a trapped room from the top-left tile to the bottom-right, moving only right or down.
  25. Tiles That Know Their Neighbors (Medium): Autotiling picks each wall's picture from its neighbors, so walls join up into smooth shapes on their own.
  26. Where Is the Sword, Really? (Medium): In a scene graph every object is placed relative to its parent: a sword relative to a hand, the hand relative to an arm, the arm relative to the knight.
  27. Which Diamond Did I Click? (Medium): In an isometric game, square map tiles are drawn as diamonds, so finding the tile under the mouse takes a little algebra.
  28. Chase the Player (Hard): Given a grid where 0 is a wall and any other number is what it costs to step onto that tile (grass 1, swamp 5), return the cheapest cost from the top-left corner to the bottom-right, moving up, down, left or right, or -1 if there's no way through.
  29. Load It Before They Get There (Hard): An open world streams assets in as you move.
  30. What Does the Guard Do? (Hard): A guard's AI is a behavior tree.

Practice another pattern

Or browse by subject

Browse all 676 puzzles