A compact TypeScript implementation trains a self-parking car with a genetic algorithm by turning control into an optimization of a discrete genome. The simulated car has two actuators (engine and steering) that accept signals -1, 0, +1 every 100 ms, and eight distance sensors reporting 0-4 m. The controller (brain) maps the eight sensor inputs to two outputs using two linear polynomials (one per actuator) - each polynomial has eight sensor coefficients plus a bias, so 18 real-valued coefficients define behavior. Raw polynomial outputs are run through a sigmoid and a three-way threshold (with a configurable margin) to produce muscle signals. The setup is intentionally simple (no neural nets) to make evolution and interpretation straightforward.
Genomes are the 18 coefficients encoded in a custom 10-bit floating format (1 sign, 4 exponent, 5 fraction) so each coefficient is 10 bits and the full genome is 180 bits. A genetic algorithm operates on these bitstrings; the repo includes the full ~500-line TypeScript implementation and a browser simulator that lets users train from scratch, tweak GA parameters, observe evolved cars, or drive manually. Empirically, evolved populations begin to approach the parking spot by about the 40th generation, though collisions and imperfect fits remain early on.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.