Local time in Turrialba, Costa Rica

All work
ACADEMIC

GENETIC KINGDOM

TEAM OF 3 · ALGORITHMS AND DATA STRUCTURES II · TEC · 2025

OVERVIEW

Tower-defense game in C++ and SFML where each enemy wave evolves through a genetic algorithm and finds its way through the player's towers with A* pathfinding.

HIGHLIGHTS

  1. Genetic algorithm over five genes (health, speed and three resistances), with fitness from distance traveled, time alive and damage received.
  2. Elitism, roulette or tournament selection depending on population diversity, two crossover types and adaptive Gaussian mutation.
  3. A* on an 11 by 20 grid with live re-routing; placing a tower that would block the path is refused.
  4. On-screen stats for generation, mutations and per-enemy fitness.
  5. Custom DynamicArray container used instead of std::vector.

STACK

  • C++17
  • SFML
  • CMake

MY CONTRIBUTION

  1. Genetic algorithm end to end: chromosomes, fitness, selection, crossover, mutation and the generation loop.
  2. A* pathfinding and the path-blocking check for tower placement.
  3. Wave system and the mapping from chromosomes to enemy stats.
  4. Game shell: state stack, menus, settings, audio, and the DynamicArray container.

SCREENS

  1. Settings screen with master, music and SFX volume
  2. Main menu

CHALLENGE

With a population of only 20 and one wave per generation, the population can collapse into near-identical enemies. The algorithm tracks a diversity metric, switches from roulette to tournament selection when it drops, adapts mutation and crossover rates, and replaces the worst 20% with random chromosomes.

TEAM