Commit 1d44fbd4 authored by hosein's avatar hosein

playground -> ifMoveWillCheck added

parent ae8e9955
......@@ -32,13 +32,7 @@ public class Bishop extends Nut {
@Override
public boolean canMove(int[] destination) {
if (x == destination[0]) return false;
else
return Math.abs((y - destination[1]) / (x - destination[0])) == 1;
}
@Override
public void changeAlive() {
isAlive = false;
else return Math.abs((float) (y - destination[1]) / (float) (x - destination[0])) == 1.0;
}
@Override
......@@ -51,7 +45,7 @@ public class Bishop extends Nut {
if (destination[1] < y) 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)
return false;
......
......@@ -10,7 +10,7 @@ public class King extends Nut {
y = 4;
} else {
x = 0;
y = 3;
y = 4;
}
}
......@@ -31,11 +31,6 @@ public class King extends Nut {
return r;
}
@Override
public void changeAlive() {
isAlive = false;
}
@Override
public boolean canRoute(int[] destination, int[][] ground) {
return true;
......
......@@ -37,13 +37,10 @@ public class Knight extends Nut {
return Math.pow(destination[0] - x, 2) + Math.pow(destination[1] - y, 2) == 5;
}
@Override
public void changeAlive() {
isAlive = false;
}
@Override
public boolean canRoute(int[] destination, int[][] ground) {
return true;
}
}
......@@ -31,11 +31,6 @@ public class Pawn extends Nut {
}
}
@Override
public void changeAlive() {
isAlive = false;
}
@Override
public boolean canRoute(int[] destination, int[][] ground) {
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 {
}
}
@Override
public void changeAlive() {
isAlive = false;
}
@Override
public boolean canRoute(int[] destination, int[][] ground) {
if (destination[0] == x) {
int t;
if (destination[1] - y > 0) 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)
return false;
} else if (destination[1] == y) {
int t;
if (destination[0] - x > 0) 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)
return false;
}
......@@ -61,7 +56,7 @@ public class Queen extends Nut {
if (destination[1] < y) 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)
return false;
......
......@@ -35,25 +35,20 @@ public class Rook extends Nut {
return x == destination[0] || y == destination[1];
}
@Override
public void changeAlive() {
isAlive = false;
}
@Override
public boolean canRoute(int[] destination, int[][] ground) {
if (destination[0] == x) {
int t;
if (destination[1] - y > 0) 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)
return false;
} else {
int t;
if (destination[0] - x > 0) 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)
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