Solution for knight's tour problem (Java)