← Back to projects
ML & Statistics2024Academic

Genetic Golf

A visual genetic algorithm: 500 golf balls learn by evolution to reach the hole while dodging obstacles.

500agents per generation

The problem

The AI course's final project asked for a tangible demonstration of evolutionary computing, not a results spreadsheet.

What I did

Implemented the full evolutionary loop in JavaScript with p5.js: per-shot DNA of [x, y, angle, force], a fitness function with penalties, mating pool and mutation, animated in-browser with 500 agents and 15 shots per individual.

The outcome

Working in-browser simulator, presented as the Artificial Intelligence course's final project.

How it evolves

  1. 500 balls with random DNAInput
  2. DNA of position, angle and power15 shots per individual
  3. Shot simulationWith obstacles
  4. Fitness with penaltiesHow close to the hole
  5. Mating pool and mutationThe best ones breed
  6. A generation that reaches the holeOutput

Nobody teaches the ball where the hole is. Each generation takes its shots, gets scored by how close it got, and the best ones breed: the behavior emerges from selection, not from programming.

Stack

  • JavaScript
  • p5.js
  • HTML/CSS