PLZ can u help me to solve this Q by using java netbeans sol
PLZ can u help me to solve this Q.
by using java (netbeans)
solve using Two-Dimensional Arrays :
In chess, the knight moves in a very special way:
either: two squares forward and one to the side
or : one square forward and two to the side
Write a program to print the Probability of the moves
here
here
here
here
Knight
here
here
here
here
| here | here | ||||||
| here | here | ||||||
| Knight | |||||||
| here | here | ||||||
| here | here | ||||||
Solution
//Assuming that knights initial position is given as (x,y) and n is the number of moves remaining
double findProb(int x, int y, int n){
double[][] mat = new double[8][8];
for(double[] row: mat)
Arrays.fill(row, -1.0);
findProbUtil(mat, x, y, n);
}
double findProbUtil(double[][8] m, int x, int y, int n){
if(x<0 || x>7 || y<0 || y>7)
return 0;
if(n==0)
return 1;
if(m[x][y]!=-1)
return m[x][y];
double res = 0.0;
//for all possible next moves
res += findProbUtil(m, x+2, y+1, n-1);
res += findProbUtil(m, x+1, y+2, n-1);
res += findProbUtil(m, x-1, y+2, n-1);
res += findProbUtil(m, x-2, y+1, n-1);
res += findProbUtil(m, x-2, y-1, n-1);
res += findProbUtil(m, x-1, y-2, n-1);
res += findProbUtil(m, x+1, y-2, n-1);
res += findProbUtil(m, x+2, y-1, n-1);
m[x][y] = res;
return res;
}

