I am trying to print the minimum steps needed to traverse a chessboard as a knight from one diagonal position to the other. I have the following code:
Building the chessboard
I started with creating the chessboard as a 100 x 100 arrayplot. The problem I seem to be having is merging it with the KnightsTour and travPath code. Reference for this code is linked in the last paragraph:
Chessboard=ArrayPlot[Table[Mod[j+i,2],{i,100},{j,100}],
ColorRules->{1->RGBColor[0,.55,.77],0->RGBColor[.67,.9,.99]},Frame->False,
DataRange->{{1,100},{1,100}}];(*Standard re-sizeable chessboard*)
Describing the Diagonal Knights Tour
From my readings,the algorithms "Manhattan Distance" decreases for each move on the board such that (100-1)+(100-1)=198, therefore any two move advance cannot close in by anymore than 3:
KnightsTour[i_IntegerQ, j_IntegerQ]:=Module[{m},m = i-j;If[j>m,2.((j-m)/3)+m;m-2.((j-m)/4),(*Denote the decrease in the Manhatten Distance*)
If[i==1 & j==1,3;If[i==2 & j==2,4;]]]];
Showing the Path Traversal
This line uses FindHamiltonianPath to follow and highlight the path of traversal according to the algorithm above. I am having trouble in this section because the graphics will not combine here, throwing the following error:
Could not combine the graphics object in Show [{},, HighlightGraph[KnightsTour, PathGraph[KnightsTour[[1 ;; 1]]],
PlotTheme -> "Marketing", GraphHighlightStyle -> "DehilightHide",
EdgeStyle -> Thickness[0.1]]}]
travPath = FindHamiltonianPath[KnightsTour[1,1]];
Manipulate[Show[{Chessboard,HighlightGraph[KnightsTour,PathGraph[KnightsTour[[;;i]]], (*Chessboard should play out the steps taken by the knight*)
PlotTheme->"Marketing",GraphHighlightStyle->"DehilightHide",
EdgeStyle ->Thickness[0.1]]}],{i,1,Length[travPath],100},
SaveDefinitions->True]
I had copied the manipulation code from here, not sure why this won't work for the chessboard that I developed, nor the checkerboard I had copied from the site hyperlinked in this text.
I would like to fix these errors here, any hints are appreciated. I would also like to improve upon the code by printing out the minimum steps taken as the knight traverses the board from the diagonal. Again, I appreciate any insight here.
travPath = FindHamiltonianPath[KnightsTour]
"KnigtsTour" needs arguments $\endgroup$KnightsTour[i_IntegerQ, j_IntegerQ]
should read:KnightsTour[i_?IntegerQ, j_?IntegerQ]
. Then` FindHamiltonianPath` wants a graph object as first argument, not a number. $\endgroup$