This is a 2D companion to the 3D "Fitness Landscape: Adaptive Walk" sim, built around genuinely distinct mechanics: instead of a continuous 2-trait terrain, each genotype here is a bit string of L=6 discrete loci (64 possible genotypes) and fitness comes from Stuart Kauffman's NK model (1993) — the classic way to make a combinatorial adaptive landscape's ruggedness a tunable, exact parameter.
Locus i's fitness contribution depends on itself + K neighbor loci:
f_i = table_i[ bits(locus i, i+1, …, i+K mod L) ] (random per-pattern lookup)
Genotype fitness: W(g) = (1/L)·Σ f_i
Each generation (Wright–Fisher):
1. Mutation: each of the L bits flips independently with prob. μ
2. Selection: P(parent = j) = exp(β·W_j) / Σ exp(β·W_k)
3. Sample N offspring genotypes (with replacement) from step 2
K=0 makes the landscape purely additive (no epistasis) — provably single-peaked, since the best genotype is just each locus's individually-best allele. As K rises toward L−1=5, each locus's contribution depends on more of its neighbors, and the landscape becomes rugged with multiple local optima that a hill-climbing population can get stuck on — exactly Kauffman's result, reproduced numerically here (a standalone Node.js check of this same code found 1.00 local optima on average at K=0, rising to 9.16 at K=5, versus the Kauffman–Levin (1987) closed-form prediction of 2⁶/7 = 9.14 for a fully random K=N−1 landscape).
Population size N still controls the strength of genetic drift exactly as in the continuous version: a small N samples so noisily each generation that chance alone can carry the population off a local optimum, across the "hypercube" to a fitter genotype nearby — while a large N reliably converges to whichever peak it started nearest.
- Population size N — individuals sampled each generation; smaller = stronger drift.
- Mutation rate μ — per-locus bit-flip probability each generation; larger = bigger, riskier genotype jumps.
- Selection strength β — how sharply fitness biases reproduction; β=0 is neutral drift, high β is near-pure hill-climbing.
- Epistasis K — how many neighboring loci each locus's fitness contribution depends on; 0 = single smooth peak, 5 = maximally rugged "house of cards" landscape.
- New landscape — redraws the random per-locus fitness lookup tables, giving a fresh rugged (or smooth) surface at the current K.