Commit ae8e9955 authored by hosein's avatar hosein

playground -> ifMoveWillCheck added

parent 947240a2
...@@ -120,17 +120,8 @@ public class PlayGround { ...@@ -120,17 +120,8 @@ public class PlayGround {
return 2; return 2;
Nut j = null; //4 check //4 check
for (Nut i : nutsID.keySet()) { ifMoveWillCheck(getDestination((string[0].charAt(0)) , (short) (string[0].charAt(1))), getDestination(string[1].charAt(0), (short) (string[1].charAt(1))), turn);
if (nutsID.get(i) == id1) {
j = i;
i.move(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))), ground);
break;
}
}
isCheck(turn);
j.move(getDestination(string[0].charAt(0), (short) (string[0].charAt(1))), ground);
if (getCheck()) return 4; if (getCheck()) return 4;
...@@ -158,6 +149,16 @@ public class PlayGround { ...@@ -158,6 +149,16 @@ public class PlayGround {
return 1; //1 can move return 1; //1 can move
} }
private void ifMoveWillCheck(int[] origin, int[] destination, int turn) {
int id1 = ground[origin[0]][origin[1]], id2 = ground[destination[0]][destination[1]];
ground[origin[0]][origin[1]] = 0;
ground[destination[0]][destination[1]] = id1;
isCheck(turn);
getCheck();
ground[origin[0]][origin[1]] = id1;
ground[destination[0]][destination[1]] = id2;
}
public void moveNut(String[] string) { public void moveNut(String[] string) {
int id2 = getNutID(string[1].charAt(0), (short) string[1].charAt(1)), id1 = getNutID(string[0].charAt(0), (short) string[0].charAt(1)); int id2 = getNutID(string[1].charAt(0), (short) string[1].charAt(1)), id1 = getNutID(string[0].charAt(0), (short) string[0].charAt(1));
if (id2 != 0) if (id2 != 0)
...@@ -204,11 +205,10 @@ public class PlayGround { ...@@ -204,11 +205,10 @@ public class PlayGround {
if ((bQueen.canMove(wKing.getXY()) && bQueen.canRoute(wKing.getXY(), ground)) || if ((bQueen.canMove(wKing.getXY()) && bQueen.canRoute(wKing.getXY(), ground)) ||
(bRooks[0].canMove(wKing.getXY()) && bRooks[0].canRoute(wKing.getXY(), ground)) || (bRooks[0].canMove(wKing.getXY()) && bRooks[0].canRoute(wKing.getXY(), ground)) ||
(bRooks[1].canMove(wKing.getXY()) && bRooks[1].canRoute(wKing.getXY(), ground)) || (bRooks[1].canMove(wKing.getXY()) && bRooks[1].canRoute(wKing.getXY(), ground)) ||
(bKnights[0].canMove(wKing.getXY()) && bKnights[0].canRoute(wKing.getXY(), ground)) || (bKnights[0].canMove(wKing.getXY())) ||
(bKnights[1].canMove(wKing.getXY()) && bKnights[1].canRoute(wKing.getXY(), ground)) || (bKnights[1].canMove(wKing.getXY())) ||
(bBishops[0].canMove(wKing.getXY()) && bBishops[0].canRoute(wKing.getXY(), ground)) || (bBishops[0].canMove(wKing.getXY()) && bBishops[0].canRoute(wKing.getXY(), ground)) ||
(bBishops[1].canMove(wKing.getXY()) && bBishops[1].canRoute(wKing.getXY(), ground)) (bBishops[1].canMove(wKing.getXY()) && bBishops[1].canRoute(wKing.getXY(), ground))) {
) {
check = true; check = true;
return; return;
} }
...@@ -221,16 +221,15 @@ public class PlayGround { ...@@ -221,16 +221,15 @@ public class PlayGround {
if ((wQueen.canMove(bKing.getXY()) && wQueen.canRoute(bKing.getXY(), ground)) || if ((wQueen.canMove(bKing.getXY()) && wQueen.canRoute(bKing.getXY(), ground)) ||
(wRooks[0].canMove(bKing.getXY()) && wRooks[0].canRoute(bKing.getXY(), ground)) || (wRooks[0].canMove(bKing.getXY()) && wRooks[0].canRoute(bKing.getXY(), ground)) ||
(wRooks[1].canMove(bKing.getXY()) && wRooks[1].canRoute(bKing.getXY(), ground)) || (wRooks[1].canMove(bKing.getXY()) && wRooks[1].canRoute(bKing.getXY(), ground)) ||
(wKnights[0].canMove(bKing.getXY()) && wKnights[0].canRoute(bKing.getXY(), ground)) || (wKnights[0].canMove(bKing.getXY())) ||
(wKnights[1].canMove(bKing.getXY()) && wKnights[1].canRoute(bKing.getXY(), ground)) || (wKnights[1].canMove(bKing.getXY())) ||
(wBishops[0].canMove(bKing.getXY()) && wBishops[0].canRoute(bKing.getXY(), ground)) || (wBishops[0].canMove(bKing.getXY()) && wBishops[0].canRoute(bKing.getXY(), ground)) ||
(wBishops[1].canMove(bKing.getXY()) && wBishops[1].canRoute(bKing.getXY(), ground)) (wBishops[1].canMove(bKing.getXY()) && (wBishops[1].canRoute(bKing.getXY(), ground)))) {
) {
check = true; check = true;
return; return;
} }
check = false;
} }
check = false;
} }
public boolean getCheck() { public boolean getCheck() {
...@@ -321,4 +320,5 @@ public class PlayGround { ...@@ -321,4 +320,5 @@ public class PlayGround {
System.out.println(" ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ "); System.out.println(" ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ");
} }
} }
\ No newline at end of file
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