Commit 26c95b6a authored by hosein's avatar hosein

playground -> canMove updated

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