Genetic algorithm · evolutionary computation · browser-native

An agent that learns the maze
without a teacher.

Adam AI is an interactive evolutionary simulation by Mohammed Unais. A population of 500 agents is generated at random, scored on how far it gets through a guarded maze, then bred — highest fitness first — with small random mutations. No route is programmed here. The route is discovered, generation by generation, in the browser.

Population
500 / generation
Genome
fixed move sequence
Selection
fitness-proportional
Runtime
100% client-side

Developed and maintained by Mohammed Unais. Built on an original genetic-algorithm implementation by Gazi Jarin and Raiyan Rahman, reused with permission under the MIT licence. See credits.

01 — Live simulation

The population, evolving now

The red square is the current champion replayed each generation. Press Space to reveal the whole generation, and watch the fitness history build up in the panel below. Every number here is read from the running simulation — nothing is mocked for presentation.

Evolving

Space toggle full generation P play yourself G replay best generations WASD/↑↓←→ move in human mode

02 — Learning cycle

A random population becomes a route

No agent is told the answer, and no agent is told that it failed. Selection is the only signal: whatever travels further is copied more often, so small random edits accumulate into a path through the maze.

  1. Stage 01

    Initialise

    500 genomes, each ten random moves drawn from nine directions. Every agent starts on the same tile.

  2. Stage 02

    Execute

    Genomes replay in one shared maze, each direction held for six frames. Walls, guards and checkpoints act on all of them equally.

  3. Stage 03

    Evaluate

    Each agent is scored by its distance to the next checkpoint plus the precomputed route that remains from there to the goal.

  4. Stage 04

    Select

    A roulette wheel over the fitness sum. A better genome gets a larger slice of the wheel — never a guaranteed one.

  5. Stage 05

    Mutate

    The champion is cloned unmutated. Every other child redraws genes at mutationRate, weighted around a recent death.

  6. Stage 06

    Evolve

    Every five generations each genome gains five moves, so the search extends only as fast as prefixes are solved.

What improvement actually looks like

The first generation is noise: ten random moves from the corner, almost always ending against a wall. What survives is only what happens to drift further. Fitness then rises in small, monotone steps as longer genomes keep the successful prefixes intact.

GenerationMove budgetBest-ever fitness
10203.05e-14
30404.68e-14
50606.82e-14
68757.92e-14

A 60-individual verification run, stepped frame by frame in headless Chrome. These are recorded values, not illustrative ones.

Why it is slow

The genome is open-loop. It cannot see the guard, the wall or the checkpoint ahead — it replays a sequence of moves and dies when the sequence runs out. Improvement therefore comes from length and timing rather than strategy, and every checkpoint pushes the goal further away again.

  • Roughly 50 generations to the first checkpoint at 500 individuals, as reported upstream.
  • Later checkpoints take substantially longer: each gate enlarges the search space.
  • One elite slot and no crossover mean the population looks converged long before it solves the maze.

03 — The algorithm

What actually happens, cycle by cycle

This is a genetic algorithm, not deep learning and not reinforcement learning. There is no gradient, no reward model and no neural network. Six steps, all visible in the source.

  1. 01

    Initialise

    Each individual holds a Brain: an array of numberOfSteps (10) unit vectors chosen at random from eight compass directions plus a “stay still” vector. Every agent starts from the same tile.

  2. 02

    Execute

    A genome is a move budget, not a policy. Each direction is held for six frames, moving the agent tileSize/15 pixels per frame. Walls are resolved on the x and y axes separately, so agents slide along walls instead of sticking.

  3. 03

    Evaluate

    Fitness is computed when every agent is dead or finished. Reaching the goal scores 1/16 + 10000/steps²; otherwise the score falls off with the distance to the next unreached checkpoint. Collecting a checkpoint multiplies the score by 1.2, and the total is squared. Dying to a guard scales the distance estimate by 0.9 — which, because fitness is 1/d², slightly raises the score. That inversion is inherited, and documented rather than silently “fixed”.

  4. 04

    Select

    Roulette-wheel selection: each individual gets a slice of the wheel proportional to its fitness, then parents are drawn at random. Fit agents are likely to breed; unfit ones usually are not — but are never guaranteed to fail.

  5. 05

    Reproduce & mutate

    The elite is cloned unmutated into slot 0, so the best genome is never lost. Every other child copies its parent’s genome and, per gene, redraws that direction with probability mutationRate. Genes just before a guard-related death mutate five times more often.

  6. 06

    Expand the budget

    Every increaseEvery generations, increaseMovesBy new random directions are appended to every genome. Longer sequences can reach further, so progress compounds across generations — what the original README calls incremental learning.

No crossover

Reproduction is asexual: one parent, cloned, then mutated. There is no two-parent recombination anywhere in the codebase, and this page does not claim otherwise.

No neural network

The genome is a literal list of directions. Nothing infers state, extracts features or approximates a policy. Describing this as a neural network would be wrong.

Elitism, one slot

Only the single best individual survives unmutated. There is no fitness sharing, no diversity preservation and no speciation — which is why the population can converge prematurely.

04 — Architecture

How the code is put together

Static HTML, CSS and JavaScript. No build step, no package manager, no server, no API keys. p5.js 0.5.8 is vendored in libraries/.

Runtime modules

ModuleResponsibility
sketch.jsp5 lifecycle, generation loop, mode switching, control panel
Population.jsGeneration bookkeeping, fitness sum, selection, mutation pass, move-budget growth
Player.jsAgent movement, collision resolution, fitness function, cloning
Brain.jsGenome storage, random generation, mutation, cloning, length growth
Node.jsCheckpoint graph with precomputed distance-to-finish
Solid.jsAxis-separated wall collision
Dot.jsPatrolling guards that kill on contact
Coin.jsCollectible checkpoints
setting_level.jsMaze geometry, walls, goal, guards, solids
site/main.jsInstrumentation, analytics chart, UI controls (read-only over simulation state)

Control flow

draw()every frame
Population.update()advance agents
all dead?end of generation
nokeep stepping
yesevolve
calculateFitness
naturalSelection
mutateDemBabies

The page’s instrumentation hooks in after calculateFitness(), before selection replaces the population, so reported fitness is never stale.

Stack & constraints

  • Language ES5/ES6 JavaScript, no transpiler
  • Renderer p5.js 0.5.8 (canvas 2D), vendored
  • Build none — static files served as-is
  • Hosting GitHub Pages via GitHub Actions
  • Dependencies 0 runtime packages; p5 is committed
  • Data none collected, no cookies, no external services

05 — Engineering

What building this involved

The genetic algorithm and the maze are inherited. The interface, the instrumentation that makes the run legible, and the pipeline that ships it are the work of this rebuild.

01

Simulation in the browser

500 agents evolve per generation on canvas 2D at a measured ~60 fps, with no server, no build step and no external requests at runtime.

02

Genetic operators

Roulette-wheel selection over the fitness sum, a single unmutated elite slot, per-gene mutation and a move budget that grows on a fixed schedule.

03

Read-only instrumentation

The dashboard hooks in after calculateFitness() and samples generation, best and mean fitness, budget and checkpoints without writing back into selection.

04

Hand-drawn charting

The fitness chart is about 120 lines of canvas 2D with a log10 axis — written because a charting library was not worth the payload for one line chart.

05

Interaction design

Pause, replay, human control and restart share one state machine with the keyboard shortcuts, so a button and a key can never disagree about the current mode.

06

Delivery that fails closed

A GitHub Actions job checks required files, asset references and base-path safety before publishing, so a broken tree cannot reach Pages.

06 — Project

Project information & credits

Adam AI is an independent redevelopment and maintained implementation by Mohammed Unais. It explores genetic algorithms and evolutionary computation through an interactive browser-based simulation.

Developed and maintained by Mohammed Unais

I built Adam AI to make evolutionary computation observable. Most explanations stop at a diagram of selection and mutation; the interesting part is what a population does under real selection pressure — how quickly it converges, where it stalls, and why an open-loop genome can memorise a route without ever understanding the maze.

My work is the redevelopment: reading the inherited algorithm line by line, fixing the defects that broke the demo, instrumenting the population so every displayed number is measured rather than decorative, and wiring up a deployment that validates itself. The genetic algorithm is not mine; the presentation, analysis and engineering around it are.

Role
Redevelopment, interface, instrumentation, documentation and deployment
Focus
Evolutionary computation and front-end engineering
Stack
JavaScript · p5.js · CSS · GitHub Actions

Known limitations

  • Open-loop genome: it cannot react to state, so it memorises timing rather than navigating.
  • One hand-authored level; no generalisation to an unseen maze.
  • Premature convergence — one elite slot, no crossover and no diversity pressure collapse the population onto similar paths.
  • Guard deaths are rewarded rather than penalised: the distance estimate is scaled by 0.9 before inverting, so dying close to a checkpoint scores higher. Preserved for comparability with the original.
  • Fitness is 1/d² then squared, so early generations are numerically tiny and flat on a linear axis.
  • Expect roughly 50 generations to the first checkpoint; later checkpoints take substantially longer.

Credits

Original simulation — the genetic algorithm, the maze and the p5 sketch were created by Gazi Jarin with Raiyan Rahman and published as gazijarin/AdamAI in December 2018. Reused and developed further with their permission. The genetic-algorithm structure follows Code Bullet’s work, as credited upstream.

This implementation — interface, design system, live instrumentation, analytics, defect fixes, documentation and deployment by Mohammed Unais. The inherited simulation remains the work of its original authors; no original-authorship claim is made over it.

Rendering by p5.js 0.5.8, © p5.js contributors, LGPL-2.1. File-by-file provenance in NOTICE.md.

Licence

Adam AI is released under the MIT licence — © 2018 Gazi Jarin and Raiyan Rahman, © 2026 Mohammed Unais. The original implementation is reused with its authors’ permission, and their copyright notice is retained in the licence text.

Third-party code keeps its own terms: p5.js and its addons are LGPL-2.1.

Full terms in LICENSE; provenance and the modification record in NOTICE.md.