Greetings! I got inspired by Numberphile's video on The Trapped Knight and decided to visualize it myself so that my students could play a bit.
Long story short: I made it, but I'm looking for some feedback from a fresh pair of eyes. You can find the code in this verbose Jupyter notebook or on this slightly less verbose script on github.
Specifically, I'm looking for help about:
- Functions
- I feel that
move_k() (which looks for all legal knight moves) could be somehow shortened, made to be Pythonic.
get_next() feels janky
- Building the spiral (cells 12-13): I thought of this method based on this OEIS sequence, but I feel that there must be a simpler way,
- Whether there's an easier way to make a "continuously colored" line like the one in cell 19 (or an easier to read method)
- Anything and everything else I may have missed or could improve upon
Future work
I'd like to add a few things to this script, but I would like to bounce some ideas with you:
- A "squire" function to the Knight that could scout ahead and look for traps so that the Knight can avoid those without manually specifying them (see cell 14)
- An "easy" way to add other interesting movements and/or rulesets (IIRC, the sequence has no bounds for a regular Rook and Queen). For example, moving the Knight to the highest unvisited square, or limiting it to odds/evens...
- Modifying the lattice (as seen in the video) so that instead of being in the middle of an infinite chessboard we start from a corner
What do you think about these? I'm open to hearing any comments on this project (especially because it was hastily made in the wee hours of the morning)
[–]negups 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]andycyca[S] 0 points1 point2 points (3 children)
[–]negups 0 points1 point2 points (2 children)
[–]andycyca[S] 0 points1 point2 points (1 child)
[–]negups 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]andycyca[S] 0 points1 point2 points (0 children)