Commit 947240a2 authored by hosein's avatar hosein

nuts -> move updated

parent 41971b18
......@@ -51,7 +51,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 != destination[0]; i += X, j += Y)
if (ground[i][j] != 0)
return false;
......
......@@ -4,9 +4,11 @@ public abstract class Nut {
protected int id, x, y; // 1 means white & -1 means black
protected boolean isAlive;
public void move(int[] destination) {
public void move(int[] destination, int[][] g) {
g[x][y] = 0;
x = destination[0];
y = destination[1];
g[x][y] = id;
}
public abstract boolean canRoute(int[] destination, int[][] ground);
......
......@@ -23,7 +23,7 @@ public class Pawn extends Nut {
@Override
public boolean canMove(int[] destination) {
if (id > 0) {
if (x == 6 && destination[0] - x == 2 && destination[1] == y) return true;
if (x == 6 && destination[0] - x == -2 && destination[1] == y) return true;
return destination[0] < x && destination[0] >= x - 1 && destination[1] <= y + 1 && destination[1] >= y - 1;
} else {
if (x == 1 && destination[0] - x == 2 && destination[1] == y) return true;
......@@ -38,10 +38,17 @@ public class Pawn extends Nut {
@Override
public boolean canRoute(int[] destination, int[][] ground) {
if (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;
return true;
}
public boolean canCheck(int[] k) {
if (id > 0)
return (x - 1 == k[0] && y - 1 == k[1]) || (x - 1 == k[0] && y + 1 == k[1]);
else
return (x + 1 == k[0] && y - 1 == k[1]) || (x + 1 == k[0] && y + 1 == k[1]);
}
}
......@@ -41,14 +41,14 @@ public class Queen extends Nut {
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 + t; i != destination[1]; i += t)
if (ground[x][i] != 0)
return false;
} else {
} 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 + t; i != destination[0]; i += t)
if (ground[i][y] != 0)
return false;
}
......@@ -61,7 +61,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 != destination[0]; i += X, j += Y)
if (ground[i][j] != 0)
return false;
......
......@@ -46,14 +46,14 @@ public class Rook extends Nut {
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 + t; 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 + t; i != destination[0]; i += t)
if (ground[i][y] != 0)
return false;
}
......@@ -61,8 +61,5 @@ public class Rook extends Nut {
}
}
}
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