# Main Command: Go # Knight's Tour by Guy Walker # www.logoarts.co.uk To New # set default screen, pen and turtle ResetAll SetScreenSize [400 400] HideTurtle SetSC Black SetPC Green SetPS 1 PenUp End To Init Make "Moves [1 2 2 1 -1 -2 -2 -1 1 2] Make "Free [ ] Repeat 64 [Make "Free LPut 0 :Free] End To Title # write header SetPC White SetPos [-190 180] Label [Knight's Tour] End To Gridd :Xc :Yc # return X Y screen position Make "X (38*:Xc) - 132 Make "Y (38*:Yc) - 132 Output List :X :Y End To DrawBoard SetPC Brown Square 334 SetPC [96 57 19] Fill SetPC Brown Square 310 SetPC [199 178 153] Fill SetPC Brown Repeat 4 [ SetH (Repcount*90)-45 Forward 220 PenDown Forward 15 PenUp Home] # label grid numbers SetPC [64 64 64] Repeat 8 [ SetPos Gridd RepCount-1 Minus 1.25 Label Character 96+RepCount SetPos Gridd 8.15 RepCount-1 Label RepCount] # draw 64 alt colored squares For (List "N 0 7) [ For (List "M 0 7) [ SetPos Gridd :M :N SetPC Brown Square 32 If Even (:M+:N) [SetPC [117 76 36] ] [SetPC [198 156 109] ] Fill ] ] End To Empty :X :Y # Output True if Cell is empty and within board If And And And (:X>-1) (:X<8) (:Y>-1) (:Y<8) [ If ( 0=Item (1+:X+8*:Y) :Free) [Output "True] ] Output "False End To Step :Xc :Yc :Count # move to next square and update 'free' list SetPos Gridd :Xc :Yc PenUp If :Count=0 [SetPC Green Square 32] SetPC Black Label :Count Make "Free Replace :Free (1+:Xc+8*:Yc) 1 Write (Word :Xc :Yc "\ ) Make "Poss NextPos :Xc :Yc # choose a random next move If 0