RosettaCodeData/Task/Knights-tour/PicoLisp/knights-tour.l
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

30 lines
1 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(load "@lib/simul.l")
# Build board
(grid 8 8)
# Generate legal moves for a given position
(de moves (Tour)
(extract
'((Jump)
(let? Pos (Jump (car Tour))
(unless (memq Pos Tour)
Pos ) ) )
(quote # (taken from "games/chess.l")
((This) (: 0 1 1 0 -1 1 0 -1 1)) # South Southwest
((This) (: 0 1 1 0 -1 1 0 1 1)) # West Southwest
((This) (: 0 1 1 0 -1 -1 0 1 1)) # West Northwest
((This) (: 0 1 1 0 -1 -1 0 -1 -1)) # North Northwest
((This) (: 0 1 -1 0 -1 -1 0 -1 -1)) # North Northeast
((This) (: 0 1 -1 0 -1 -1 0 1 -1)) # East Northeast
((This) (: 0 1 -1 0 -1 1 0 1 -1)) # East Southeast
((This) (: 0 1 -1 0 -1 1 0 -1 1)) ) ) ) # South Southeast
# Build a list of moves, using Warnsdorffs algorithm
(let Tour '(b1) # Start at b1
(while
(mini
'((P) (length (moves (cons P Tour))))
(moves Tour) )
(push 'Tour @) )
(flip Tour) )