Commit cd25f5fa authored by hosein's avatar hosein

Thief -> almostRandom updated

parent 56fe8bff
......@@ -4,12 +4,10 @@ import java.util.Random;
public class Thief {
private int x, y;
private boolean see;
Thief(int x, int y) {
this.x = x;
this.y = y;
see = false;
}
public void randomMove(int n, int m, PlayGround playGround) {
......@@ -126,7 +124,7 @@ public class Thief {
}
for (isPoliceThere[2] = false, q = i; q < x; q++) // up, right
for (w = j + 1; w < J; w++)
for (w = y + 1; w < J; w++)
if (playGround.getGround()[q][w] == 1) {
isPoliceThere[2] = true;
}
......@@ -161,31 +159,67 @@ public class Thief {
isPoliceThere[7] = true;
}
int[][] newSituation = almostRandomMove(isPoliceThere);
int[][] newSituation = almostRandomMove(isPoliceThere, playGround);
playGround.changeSituation(x, y, newSituation[0][0], newSituation[0][1], -1);
x = newSituation[0][0];
y = newSituation[0][1];
if (newSituation != null) {
playGround.changeSituation(x, y, newSituation[0][0], newSituation[0][1], -1);
x = newSituation[0][0];
y = newSituation[0][1];
}
}
private int[][] almostRandomMove(boolean[] isPoliceThere) {
private int[][] almostRandomMove(boolean[] is, PlayGround p) {
int[][] destination = new int[1][2];
boolean[] isPoliceThere = is;
if (isPoliceThere[0] && isPoliceThere[2]) isPoliceThere[1] = true;
if (isPoliceThere[0] && isPoliceThere[5]) isPoliceThere[3] = true;
if (isPoliceThere[7] && isPoliceThere[2]) isPoliceThere[4] = true;
if (isPoliceThere[5] && isPoliceThere[7]) isPoliceThere[6] = true;
if (isPoliceThere[1] && isPoliceThere[3]) isPoliceThere[0] = true;
if (isPoliceThere[1] && isPoliceThere[4]) isPoliceThere[2] = true;
if (isPoliceThere[6] && isPoliceThere[3]) isPoliceThere[5] = true;
if (isPoliceThere[4] && isPoliceThere[6]) isPoliceThere[7] = true;
if (isPoliceThere[0]) {
isPoliceThere[1] = true;
isPoliceThere[3] = true;
}
if (isPoliceThere[1]) {
isPoliceThere[0] = true;
isPoliceThere[2] = true;
isPoliceThere[3] = true;
isPoliceThere[4] = true;
}
if (isPoliceThere[2]) {
isPoliceThere[1] = true;
isPoliceThere[4] = true;
}
if (isPoliceThere[3]) {
isPoliceThere[1] = true;
isPoliceThere[0] = true;
isPoliceThere[5] = true;
isPoliceThere[6] = true;
}
if (isPoliceThere[4]) {
isPoliceThere[1] = true;
isPoliceThere[2] = true;
isPoliceThere[6] = true;
isPoliceThere[7] = true;
}
if (isPoliceThere[5]) {
isPoliceThere[6] = true;
isPoliceThere[3] = true;
}
if (isPoliceThere[6]) {
isPoliceThere[4] = true;
isPoliceThere[3] = true;
isPoliceThere[5] = true;
isPoliceThere[7] = true;
}
if (isPoliceThere[7]) {
isPoliceThere[4] = true;
isPoliceThere[6] = true;
}
if (!isPoliceThere[0] || !isPoliceThere[1] || !isPoliceThere[2] || !isPoliceThere[3] || !isPoliceThere[4] || !isPoliceThere[5] || !isPoliceThere[6] || !isPoliceThere[7]) {
Random r = new Random();
int i = 0;
do {
switch (r.nextInt(8)) {
case 0:
if (x == 0 || y == 0) break;
if (!isPoliceThere[0]) {
destination[0][0] = x - 1;
destination[0][1] = y - 1;
......@@ -194,6 +228,7 @@ public class Thief {
break;
case 1:
if (x == 0) break;
if (!isPoliceThere[1]) {
destination[0][0] = x - 1;
destination[0][1] = y;
......@@ -202,6 +237,7 @@ public class Thief {
break;
case 2:
if (x == 0 || y == p.getNM()[0][1] - 1) break;
if (!isPoliceThere[2]) {
destination[0][0] = x + 1;
destination[0][1] = y - 1;
......@@ -210,6 +246,7 @@ public class Thief {
break;
case 3:
if (y == 0) break;
if (!isPoliceThere[3]) {
destination[0][0] = x;
destination[0][1] = y - 1;
......@@ -218,6 +255,7 @@ public class Thief {
break;
case 4:
if (y == p.getNM()[0][1] - 1) break;
if (!isPoliceThere[4]) {
destination[0][0] = x;
destination[0][1] = y + 1;
......@@ -226,6 +264,7 @@ public class Thief {
break;
case 5:
if (y == 0 || x == p.getNM()[0][0] - 1) break;
if (!isPoliceThere[5]) {
destination[0][0] = x + 1;
destination[0][1] = y - 1;
......@@ -234,6 +273,7 @@ public class Thief {
break;
case 6:
if (x == p.getNM()[0][0] - 1) break;
if (!isPoliceThere[6]) {
destination[0][0] = x + 1;
destination[0][1] = y;
......@@ -242,12 +282,18 @@ public class Thief {
break;
case 7:
if (x == p.getNM()[0][0] - 1 || y == p.getNM()[0][1] - 1) break;
if (!isPoliceThere[7]) {
destination[0][0] = x + 1;
destination[0][1] = y + 1;
return destination;
}
}
i++;
if (i > 50) {
randomMove(p.getNM()[0][0], p.getNM()[0][1], p);
return null;
}
} while (true);
} else {
destination[0][0] = x;
......
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