Examples
Interactive demos showcasing NeatapticTS concepts in the browser. Each example is self‑contained and built with native ES2023 features – no transpilation.
Tip: Open DevTools console while an example runs to inspect logged telemetry or errors.
asciiMaze (Neuro‑evolving maze agent)
Demonstrates a simple environment where agents must traverse an ASCII maze layout. The population evolves weights / topology over generations; progress prints in real time.
If the demo fails to load, ensure the build step npm run build:ascii-maze
has produced docs/assets/ascii-maze.bundle.js
.
Behaviour & Telemetry
- Output area streams the live generation status; solved maze snapshots accumulate below.
- Lightweight telemetry (generation, best fitness, gens/sec) is exposed via:
- CustomEvent
asciiMazeTelemetry
onwindow
. window.asciiMazeLastTelemetry
object (latest snapshot).- The
run.onTelemetry(fn)
callback API when using the ESMstart()
function.
- CustomEvent
- Host pages can subscribe and surface summary stats outside the iframe.
Programmatic API (ESM)
Import the start
function and optionally supply an AbortSignal
for cancellation.
import { start } from './asciiMaze/browser-entry.js';
const controller = new AbortController();
const run = await start('#ascii-maze-output', { signal: controller.signal });
const unsubscribe = run.onTelemetry(t => {
console.log(`Gen ${t.generation} best ${t.bestFitness} (${t.gensPerSecond.toFixed(2)} gen/s)`);
});
// Early stop (either call stop or abort the signal)
// run.stop();
controller.abort();
await run.done;
unsubscribe();
API surface:
start(container: string|HTMLElement, opts?: { signal?: AbortSignal }) => Promise<RunHandle>
RunHandle.stop(): void
RunHandle.isRunning(): boolean
RunHandle.done: Promise<void>
RunHandle.onTelemetry(fn) => unsubscribe
RunHandle.getTelemetry(): TelemetrySnapshot | undefined
Telemetry snapshot (fields may extend):
interface TelemetrySnapshot {
generation: number;
bestFitness: number;
gensPerSecond: number;
exitReason?: string; // 'cancelled' | 'aborted' | 'solved' | etc.
details?: Record<string, any>; // rich metrics bundle
}
Legacy global usage (compatibility):
<script src="/assets/ascii-maze.bundle.js"></script>
<script>
window.asciiMaze.start(); // preferred
// window.asciiMazeStart(); // deprecated alias logs a warning
</script>
Embedding Notes
The iframe isolation keeps demo CSS / JS from interfering with site chrome. Now that an ESM start()
is exported, future inline embedding can attach directly to a provided container without iframe overhead (see enhancement plan).
Additional examples will appear here as they are added.