Commit 1d44fbd4 authored by hosein's avatar hosein

playground -> ifMoveWillCheck added

parent ae8e9955
...@@ -32,13 +32,7 @@ public class Bishop extends Nut { ...@@ -32,13 +32,7 @@ public class Bishop extends Nut {
@Override @Override
public boolean canMove(int[] destination) { public boolean canMove(int[] destination) {
if (x == destination[0]) return false; if (x == destination[0]) return false;
else else return Math.abs((float) (y - destination[1]) / (float) (x - destination[0])) == 1.0;
return Math.abs((y - destination[1]) / (x - destination[0])) == 1;
}
@Override
public void changeAlive() {
isAlive = false;
} }
@Override @Override
...@@ -51,7 +45,7 @@ public class Bishop extends Nut { ...@@ -51,7 +45,7 @@ public class Bishop extends Nut {
if (destination[1] < y) Y = -1; if (destination[1] < y) Y = -1;
else Y = 1; else Y = 1;
for (int i = x + X, j = y + Y; i != destination[0]; i += X, j += Y) for (int i = x + X, j = y + Y; i > -1 && i != destination[0] && j > -1 && j != destination[1]; i += X, j += Y)
if (ground[i][j] != 0) if (ground[i][j] != 0)
return false; return false;
......
...@@ -10,7 +10,7 @@ public class King extends Nut { ...@@ -10,7 +10,7 @@ public class King extends Nut {
y = 4; y = 4;
} else { } else {
x = 0; x = 0;
y = 3; y = 4;
} }
} }
...@@ -31,11 +31,6 @@ public class King extends Nut { ...@@ -31,11 +31,6 @@ public class King extends Nut {
return r; return r;
} }
@Override
public void changeAlive() {
isAlive = false;
}
@Override @Override
public boolean canRoute(int[] destination, int[][] ground) { public boolean canRoute(int[] destination, int[][] ground) {
return true; return true;
......
...@@ -37,13 +37,10 @@ public class Knight extends Nut { ...@@ -37,13 +37,10 @@ public class Knight extends Nut {
return Math.pow(destination[0] - x, 2) + Math.pow(destination[1] - y, 2) == 5; return Math.pow(destination[0] - x, 2) + Math.pow(destination[1] - y, 2) == 5;
} }
@Override
public void changeAlive() {
isAlive = false;
}
@Override @Override
public boolean canRoute(int[] destination, int[][] ground) { public boolean canRoute(int[] destination, int[][] ground) {
return true; return true;
} }
} }
...@@ -31,11 +31,6 @@ public class Pawn extends Nut { ...@@ -31,11 +31,6 @@ public class Pawn extends Nut {
} }
} }
@Override
public void changeAlive() {
isAlive = false;
}
@Override @Override
public boolean canRoute(int[] destination, int[][] ground) { public boolean canRoute(int[] destination, int[][] ground) {
if (Math.abs(destination[0] - x) == 2 && ground[(x + destination[0]) / 2][y] != 0) return false; if (Math.abs(destination[0] - x) == 2 && ground[(x + destination[0]) / 2][y] != 0) return false;
......
...@@ -30,25 +30,20 @@ public class Queen extends Nut { ...@@ -30,25 +30,20 @@ public class Queen extends Nut {
} }
} }
@Override
public void changeAlive() {
isAlive = false;
}
@Override @Override
public boolean canRoute(int[] destination, int[][] ground) { public boolean canRoute(int[] destination, int[][] ground) {
if (destination[0] == x) { if (destination[0] == x) {
int t; int t;
if (destination[1] - y > 0) t = 1; if (destination[1] - y > 0) t = 1;
else t = -1; else t = -1;
for (int i = y + t; i != destination[1]; i += t) for (int i = y; i != destination[1]; i += t)
if (ground[x][i] != 0) if (ground[x][i] != 0)
return false; return false;
} else if (destination[1] == y) { } else if (destination[1] == y) {
int t; int t;
if (destination[0] - x > 0) t = 1; if (destination[0] - x > 0) t = 1;
else t = -1; else t = -1;
for (int i = x + t; i != destination[0]; i += t) for (int i = x; i != destination[0]; i += t)
if (ground[i][y] != 0) if (ground[i][y] != 0)
return false; return false;
} }
...@@ -61,7 +56,7 @@ public class Queen extends Nut { ...@@ -61,7 +56,7 @@ public class Queen extends Nut {
if (destination[1] < y) Y = -1; if (destination[1] < y) Y = -1;
else Y = 1; else Y = 1;
for (int i = x + X, j = y + Y; i != destination[0]; i += X, j += Y) for (int i = x + X, j = y + Y; i > -1 && i != destination[0] && j > -1 && j != destination[1]; i += X, j += Y)
if (ground[i][j] != 0) if (ground[i][j] != 0)
return false; return false;
......
...@@ -35,25 +35,20 @@ public class Rook extends Nut { ...@@ -35,25 +35,20 @@ public class Rook extends Nut {
return x == destination[0] || y == destination[1]; return x == destination[0] || y == destination[1];
} }
@Override
public void changeAlive() {
isAlive = false;
}
@Override @Override
public boolean canRoute(int[] destination, int[][] ground) { public boolean canRoute(int[] destination, int[][] ground) {
if (destination[0] == x) { if (destination[0] == x) {
int t; int t;
if (destination[1] - y > 0) t = 1; if (destination[1] - y > 0) t = 1;
else t = -1; else t = -1;
for (int i = y + t; i != destination[1]; i += t) for (int i = y ; i != destination[1]; i += t)
if (ground[x][i] != 0) if (ground[x][i] != 0)
return false; return false;
} else { } else {
int t; int t;
if (destination[0] - x > 0) t = 1; if (destination[0] - x > 0) t = 1;
else t = -1; else t = -1;
for (int i = x + t; i != destination[0]; i += t) for (int i = x ; i != destination[0]; i += t)
if (ground[i][y] != 0) if (ground[i][y] != 0)
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment