Generate printable tracks and calculate optimal solution.
Needs: shapely, svgpathtools
I was expecting this to need heuristic algorithms (reinforcement learning, evolutionary search, graph deformation or what not), but it turns out the problem is surprisingly shallow and can be brute-forced quite easily (at least for reasonably-sized tracks that you would print on a page).
I think this is used as a problem in some machine-learning textbooks (see linked projects under "Related" below). But the aim here was to produce printable tracks to play on paper, with the requirement for overlapping tracks (figure-eight, overpasses), and an easy way to generate the optimal solution, so I've stopped short of developing elaborate machine-learning approaches for a problem that my laptop can brute-force in 15 seconds.
generate track from svg path (needs svgpathtools):
- track rendered with constant width, intended for manual tweaking off an svg path drawn in inkscape
python3 svg2track.py nbring.svg
python3 svg2track.py spa.svg spa.json --grid 70x48 --width 1.1
render track as pdf (needs shapely), writes TRACK.pdf:
- flags --simplify: straightened track edges, --center show center line, --ribs: show progress tracking ribs
python3 racetrack.py nbring.json
python3 racetrack.py nbring.json --simplify 0.05
render run from file:
- draws solution from file, evaluates legality and lap completion (illegal part of run drawn in red)
python3 racetrack.py nbring.json --run nbring_solution.json
solve (BFS shortest graph), writes TRACK_bfs.json, TRACK.pdf
python3 racetrack.py --bfs nbring.json
python3 racetrack.py nbring.json --simplify 0.05
solve (trivial speed-1 run), writes TRACK_solution.json, TRACK.pdf
- this is an abandoned attempt towards a heuristic solver: abandoned, as it turns out that the brute force solution is tractable
python3 racetrack.py --solve nbring.json
- wikipedia.org/wiki/Racetrack_(game)
- zeljkolazic (2019)
- popojan (2020): browser game formulky.cz (this is a 'gridless' generalization)
- meshko/graphpapergames (2026): browser game
- IshanTiwari-030800 (2026)
- senegrom (2026)
