26
26
*/
27
27
public class KnightsTour {
28
28
29
- private static final int base = 12 ;
30
- private static final int [][] moves = {
29
+ private static final int BASE = 12 ;
30
+ private static final int [][] MOVES = {
31
31
{1 , -2 },
32
32
{2 , -1 },
33
33
{2 , 1 },
@@ -41,19 +41,19 @@ public class KnightsTour {
41
41
private static int total ; // total squares in chess
42
42
43
43
public static void main (String [] args ) {
44
- grid = new int [base ][ base ];
45
- total = (base - 4 ) * (base - 4 );
44
+ grid = new int [BASE ][ BASE ];
45
+ total = (BASE - 4 ) * (BASE - 4 );
46
46
47
- for (int r = 0 ; r < base ; r ++) {
48
- for (int c = 0 ; c < base ; c ++) {
49
- if (r < 2 || r > base - 3 || c < 2 || c > base - 3 ) {
47
+ for (int r = 0 ; r < BASE ; r ++) {
48
+ for (int c = 0 ; c < BASE ; c ++) {
49
+ if (r < 2 || r > BASE - 3 || c < 2 || c > BASE - 3 ) {
50
50
grid [r ][c ] = -1 ;
51
51
}
52
52
}
53
53
}
54
54
55
- int row = 2 + (int ) (Math .random () * (base - 4 ));
56
- int col = 2 + (int ) (Math .random () * (base - 4 ));
55
+ int row = 2 + (int ) (Math .random () * (BASE - 4 ));
56
+ int col = 2 + (int ) (Math .random () * (BASE - 4 ));
57
57
58
58
grid [row ][col ] = 1 ;
59
59
@@ -95,7 +95,7 @@ private static boolean solve(int row, int column, int count) {
95
95
private static List <int []> neighbors (int row , int column ) {
96
96
List <int []> neighbour = new ArrayList <>();
97
97
98
- for (int [] m : moves ) {
98
+ for (int [] m : MOVES ) {
99
99
int x = m [0 ];
100
100
int y = m [1 ];
101
101
if (grid [row + y ][column + x ] == 0 ) {
@@ -109,7 +109,7 @@ private static List<int[]> neighbors(int row, int column) {
109
109
// Returns the total count of neighbors
110
110
private static int countNeighbors (int row , int column ) {
111
111
int num = 0 ;
112
- for (int [] m : moves ) {
112
+ for (int [] m : MOVES ) {
113
113
if (grid [row + m [1 ]][column + m [0 ]] == 0 ) {
114
114
num ++;
115
115
}
0 commit comments