Commit 26c95b6a authored by hosein's avatar hosein

playground -> canMove updated

parent ca8e1e8e
......@@ -14,7 +14,6 @@ public class PlayGround {
private Queen wQueen, bQueen;
private King wKing, bKing;
public PlayGround() {
nutsID = new HashMap<>();
......@@ -194,25 +193,20 @@ public class PlayGround {
}
public short canMove(String[] string, int turn) {
if (getNutID(string[0].charAt(0), (short) (string[0].charAt(1))) == 0) //6 mabda mohree nist
int id1 = getNutID(string[0].charAt(0), (short) (string[0].charAt(1)));
int id2 = getNutID(string[1].charAt(0), (short) (string[1].charAt(1)));
if (id1 == 0) //6 mabda mohree nist
return 6;
if (getNutID(string[0].charAt(0), (short) (string[0].charAt(1))) * getNutID(string[1].charAt(0), (short) (string[1].charAt(1))) > 0) //2 destination is not empty
if (id1 * id2 > 0) //2 destination is not empty
return 2;
Nut j = null;
// Todo shayad bekhad on mohre ro bezare jelosh
boolean check; //4 cant move because of check
if (turn == 1)
check = wKing.isCheck();
else
check = bKing.isCheck();
if (check) return 4;
Nut j = null; //5 if nut moves, king will be check
for (Nut i : nutsID.keySet()) {
j = i;
if (nutsID.get(i) == getNutID(string[0].charAt(0), (short) (string[0].charAt(1)))) {
if (nutsID.get(i) == id1) {
i.move(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))));
break;
}
......@@ -222,21 +216,26 @@ public class PlayGround {
check = wKing.isCheck();
else
check = bKing.isCheck();
//todo reverse sarbaz mojaze
j.move(getDestination(string[0].charAt(0), (short) (string[0].charAt(1))));
if (check) return 5;
if (check) return 4;
j = null;
// on mohre on harekato nemitone bere
for (Nut i : nutsID.keySet()) {
if (nutsID.get(i) == getNutID(string[0].charAt(0), (short) (string[0].charAt(1)))) {
if (!i.canMove(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))))) return 7;
else break;
if (nutsID.get(i) == id1) {
if (!i.canMove(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))))) return 5;
else {
if (Math.abs(id1) < 9 && string[0].charAt(0) != string[1].charAt(0) && id2 == 0)
return 5;
break;
}
}
}
// the route can not be traversed
for (Nut i : nutsID.keySet()) {
if (nutsID.get(i) == getNutID(string[0].charAt(0), (short) (string[0].charAt(1)))) {
if (nutsID.get(i) == id1) {
if (!i.canRoute()) return 3;
else break;
}
......@@ -247,12 +246,15 @@ public class PlayGround {
}
public void moveNut(String[] string) {
for (Nut i : nutsID.keySet()) {
if (nutsID.get(i) == getNutID(string[0].charAt(0), (short) (string[0].charAt(1)))) {
i.move(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))));
break;
if (getNutID(string[1].charAt(0), (short) string[1].charAt(1)) == 0)
for (Nut i : nutsID.keySet()) {
if (nutsID.get(i) == getNutID(string[0].charAt(0), (short) (string[0].charAt(1)))) {
i.move(getDestination(string[1].charAt(0), (short) (string[1].charAt(1))));
break;
}
}
}
}
......
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