Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@ -25,10 +25,19 @@ import java.util.*;
*/
public class KnightsTour {
private final static int base = 12;
private final static int[][] moves = {{1, -2}, {2, -1}, {2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}}; // Possible moves by knight on chess
private static int[][] grid; // chess grid
private static int total; // total squares in chess
private static final int base = 12;
private static final int[][] moves = {
{ 1, -2 },
{ 2, -1 },
{ 2, 1 },
{ 1, 2 },
{ -1, 2 },
{ -2, 1 },
{ -2, -1 },
{ -1, -2 },
}; // Possible moves by knight on chess
private static int[][] grid; // chess grid
private static int total; // total squares in chess
public static void main(String[] args) {
grid = new int[base][base];
@ -52,7 +61,6 @@ public class KnightsTour {
} else {
System.out.println("no result");
}
}
// Return True when solvable
@ -67,17 +75,23 @@ public class KnightsTour {
return false;
}
Collections.sort(neighbor, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
return a[2] - b[2];
Collections.sort(
neighbor,
new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
return a[2] - b[2];
}
}
});
);
for (int[] nb : neighbor) {
row = nb[0];
column = nb[1];
grid[row][column] = count;
if (!orphanDetected(count, row, column) && solve(row, column, count + 1)) {
if (
!orphanDetected(count, row, column) &&
solve(row, column, count + 1)
) {
return true;
}
grid[row][column] = 0;
@ -95,7 +109,7 @@ public class KnightsTour {
int y = m[1];
if (grid[row + y][column + x] == 0) {
int num = countNeighbors(row + y, column + x);
neighbour.add(new int[]{row + y, column + x, num});
neighbour.add(new int[] { row + y, column + x, num });
}
}
return neighbour;