Knight's tour: Difference between revisions

→‎{{header|Java}}: we only have to check the neighbors of the last move
m (→‎{{header|Java}}: parameterize rawtypes)
(→‎{{header|Java}}: we only have to check the neighbors of the last move)
Line 1,554:
c = nb[1];
grid[r][c] = count;
if (!orphanDetected(count, r, c) && solve(r, c, count + 1))
return true;
grid[r][c] = 0;
Line 1,584:
}
 
private static boolean orphanDetected(int countcnt, int r, int c) {
if (countcnt < total - 1) {
for (List<int[]> rnbrs = 2; neighbors(r, < base-2c); r++)
for (int[] c = 2; c <nb base-2;: c++nbrs)
if (gridcountNeighbors(nb[r0], nb[c1] == 0 && countNeighbors(r, c) == 0)
return true;
}
return false;
Anonymous user