Skip to content

Repository files navigation

Racetrack (pen-and paper game)

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).

Screenshot

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.

Usage

Generate track

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 pdf

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

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

Related

About

racetrack (pen-and-paper game)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages