; define("EAST",1); define("WEST",-1); define("EASTEAST",2); define("WESTWEST",-2); define("NORTH",1); define("SOUTH",-1); define("NORTHNORTH",2); define("SOUTHSOUTH",-2); define("ALLC",256); //board size define("D",64); define("DD",D*D); //start point define("SX",1); define("SY",0); function printtable() { global $status; echo "\n"; echo "
"; for($i=0;$i\n"; for($j=0;$j     \n", $c1,$c2,$c3,$aa); } echo "\n"; } echo "
\n"; } function nextx($i,$x) { $vx=array(EAST, WEST, WESTWEST, EASTEAST, WESTWEST, WEST, EAST, EASTEAST); return ($x+$vx[$i]); } function nexty($i,$y) { $vy=array(NORTHNORTH, NORTHNORTH, NORTH, NORTH, SOUTH, SOUTHSOUTH, SOUTHSOUTH, SOUTH); return ($y+$vy[$i]); } function valid($x,$y) { global $status; return ($status[$x][$y]==0 && !($x < 0 || $x >= D || $y < 0 || $y >= D)); } function score($x,$y) { $score = 9; if(valid($x,$y)){ $score = 8; for($i=0;$i<8;$i++) { $xxx= nextx($i,$x); $yyy= nexty($i,$y); if(!valid($xxx,$yyy)){ $score = $score - 1; } } } return $score; } function weakestlink($x,$y) { $pick = 0; $newscore = 9; for($i=0;$i<8;$i++) { $xx= nextx($i,$x); $yy= nexty($i,$y); $thisscore = score($xx,$yy); if($thisscore < $newscore){ $newscore = $thisscore; $pick = $i; } } return $pick; } function moveknight($x,$y) { global $status,$currentpos; if(valid($x,$y)) { $status[$x][$y]=$currentpos; $currentpos++; $i = weakestlink($x,$y); $xx= nextx($i,$x); $yy= nexty($i,$y); moveknight($xx,$yy); if($currentpos>DD) { printtable(); exit(0); } } } //main $currentpos; $currentpos=1; for($i=0;$i