尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證Multithreaded C++ genetic algorithm that evolves paths through 20x20 mazes
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗A genetic algorithm in C++ that evolves a route through a walled maze. Fitness is scored in parallel on a hand-rolled thread pool in the native build. The same core also compiles to WebAssembly for the browser.
A genome is a fixed-length sequence of moves over {UP, DOWN, LEFT, RIGHT, STAND}. Each generation
walks every genome from the top-left corner. A move into a wall or off the edge is blocked (the walker
stays put), and the walk stops at the bottom-right goal. The population keeps its better half and
refills it with one crossover child per survivor, each with one mutation: a replaced move, a deleted
move (a random one appended) or an inserted move (the last dropped).
mazes/*.txt holds one row per line: # is a wall, . is open. Start is the top-left corner and the
goal is the bottom-right one. The loader rejects a maze with no path between them. New mazes load
without code changes.
| File | What it is | Shortest path |
|---|---|---|
open.txt | 20x20, no walls (the original behaviour) | 38 |
obstacles.txt | 20x20 with six wall bars | 38 |
maze.txt | 20x20 recursive-backtracker maze (one route) | 66 |
loops.txt | 20x20 backtracker maze with 15 walls removed (several routes) | 42 |
tools/gen_mazes.py generated them with fixed seeds. They are committed as text, not generated at run
time.
The core can also generate a maze of any size from a seed (generateMaze in src/maze.cpp): a recursive
backtracker over the even cells, and with --loops, 16% of the remaining inner walls knocked out so
several routes exist. It uses the same seeded generator as the GA, so a size and a seed give the same
maze natively and in WebAssembly. optimalPath returns one shortest route by following the BFS
distances.
Needs a C++11 compiler and pthreads.
make # build/mazefinder
./build/mazefinder --maze mazes/maze.txt --seed 1
make test # unit tests (plain asserts)
./build/mazefinder --size 30 --loops --seed 4 --generations 1500 # a generated maze
./build/mazefinder --generate 30 --loops --seed 4 # print it
Options: --maze FILE (default mazes/open.txt) or --size N [--loops], --seed N, --generations N, --every N (print
the best fitness every N generations, default 100), --population N, --threads N (default 4), and
--verbose (every fitness value, and the best route as UDLRS letters).
make wasm # web/mazefinder.js and web/mazefinder.wasm (needs Emscripten 6.0.13, em++)
make determinism # native and WASM: same best fitness per maze and seed, same generated mazes
src/wasm_api.cpp exposes a small C API (mf_create, mf_step, mf_best_fitness,
mf_reached_goal, mf_generate, mf_optimal_path, and views of the maze and of every walked path, fittest
first). The built .js
and .wasm are committed so a static site can copy them. Thread pool: native build only. WASM
threads need SharedArrayBuffer, which needs COOP/COEP headers that GitHub Pages can't send, so the
browser build scores fitness on one thread.
src/maze.{h,cpp} | load, validate, BFS distances, generate, optimal path |
src/rng.h | the seeded splitmix64 generator |
src/ga.{h,cpp} | genome, walk, fitness, selection, crossover, mutation, seeded RNG (no threads, no I/O) |
src/main.cpp | native CLI and its thread pool |
src/wasm_api.cpp | the C API for the browser build |
tests/ | unit tests and the native-vs-WASM determinism test |
MIT — see LICENSE.