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.
Genetic algorithm · evolutionary computation · browser-native
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.
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 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.
Space toggle full generation P play yourself G replay best generations WASD/↑↓←→ move in human mode
02 — Learning cycle
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.
500 genomes, each ten random moves drawn from nine directions. Every agent starts on the same tile.
Genomes replay in one shared maze, each direction held for six frames. Walls, guards and checkpoints act on all of them equally.
Each agent is scored by its distance to the next checkpoint plus the precomputed route that remains from there to the goal.
A roulette wheel over the fitness sum. A better genome gets a larger slice of the wheel — never a guaranteed one.
The champion is cloned unmutated. Every other child redraws genes at mutationRate, weighted around a recent death.
Every five generations each genome gains five moves, so the search extends only as fast as prefixes are solved.
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.
| Generation | Move budget | Best-ever fitness |
|---|---|---|
| 10 | 20 | 3.05e-14 |
| 30 | 40 | 4.68e-14 |
| 50 | 60 | 6.82e-14 |
| 68 | 75 | 7.92e-14 |
A 60-individual verification run, stepped frame by frame in headless Chrome. These are recorded values, not illustrative ones.
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.
03 — The algorithm
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.
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.
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.
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”.
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.
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.
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.
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.
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.
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
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/.
| Module | Responsibility |
|---|---|
sketch.js | p5 lifecycle, generation loop, mode switching, control panel |
Population.js | Generation bookkeeping, fitness sum, selection, mutation pass, move-budget growth |
Player.js | Agent movement, collision resolution, fitness function, cloning |
Brain.js | Genome storage, random generation, mutation, cloning, length growth |
Node.js | Checkpoint graph with precomputed distance-to-finish |
Solid.js | Axis-separated wall collision |
Dot.js | Patrolling guards that kill on contact |
Coin.js | Collectible checkpoints |
setting_level.js | Maze geometry, walls, goal, guards, solids |
site/main.js | Instrumentation, analytics chart, UI controls (read-only over simulation state) |
The page’s instrumentation hooks in after calculateFitness(), before
selection replaces the population, so reported fitness is never stale.
05 — Engineering
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.
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.
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.
The dashboard hooks in after calculateFitness() and samples generation, best and mean fitness, budget and checkpoints without writing back into selection.
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.
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.
A GitHub Actions job checks required files, asset references and base-path safety before publishing, so a broken tree cannot reach Pages.
06 — Project
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.
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.
1/d² then squared, so early generations are numerically tiny and flat on a linear axis.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.
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.