Commit 36a1ea07 authored by hosein's avatar hosein

Main updated

parent 64e04cc8
......@@ -19,12 +19,12 @@ public class Main {
Thief thief = new Thief(positions[pn][0], positions[pn][1]);
Police[] polices = new Police[pn];
for (n = 0; n < pn; n++)
polices[n] = new Police(positions[n][0], positions[n][1]);
int i;
for (i = 0; i < pn; i++)
polices[i] = new Police(positions[i][0], positions[i][1]);
//--------------------------------------------------------------------------------
int i, I = 1;
int[][] thiefSituation = new int[1][2];
int c = 0;
......@@ -35,12 +35,13 @@ public class Main {
System.out.println("c ============== " + c);
playGround.show(5000);
playGround.show(120);
System.out.print("\n\n\n\n");
do {
thiefSituation = playGround.canPoliceSeeThief();
if (thiefSituation == null) {
System.out.println("randomMove");
for (i = 0; i < pn; i++)
polices[i].randomMove(n, m, playGround);
} else {
......@@ -49,8 +50,8 @@ public class Main {
if (playGround.getCatchThief()) break;
}
}
playGround.show(1250);
if (playGround.getCatchThief()) System.out.println("they catch him!");
if (playGround.getCatchThief()) {System.out.println("they catch him!");break;}
else playGround.show(120);
System.out.print("\n\n\n\n");
} while (!playGround.catchThief());
......
......@@ -5,6 +5,7 @@ import java.util.Random;
public class PlayGround {
private int[][] ground, thiefSituation;
private int n, m, policeNumbers;
private boolean catchThief;
PlayGround(int n, int m, int policeNumbers) {
this.n = n;
......@@ -16,6 +17,7 @@ public class PlayGround {
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
catchThief = false;
}
public void show(int time) {
......@@ -49,7 +51,6 @@ public class PlayGround {
for (k = 0; k < policeNumbers; k++) { // police
i = rand.nextInt(n);
j = rand.nextInt(m);
System.out.println("i = " + i + " j = " + j); ///////////////////////////////////////////////////////////////// TODO clean
if (ground[i][j] == 0) {
ground[i][j] = 1;
positions[k][0] = i; // x
......@@ -60,7 +61,6 @@ public class PlayGround {
for (k = 0; k < 1; k++) { // thief
i = rand.nextInt(n);
j = rand.nextInt(m);
System.out.println("i = " + i + " j = " + j);///////////////////////////////////////////////////////////////// TODO clean
if (ground[i][j] == 0) {
ground[i][j] = -1;
positions[policeNumbers][0] = i; // x
......@@ -87,36 +87,10 @@ public class PlayGround {
}
public void changeSituation(int xPrevious, int yPrevious, int xNew, int yNew, int k) {
if ((xPrevious != xNew || yPrevious!=yNew) && ground[xNew][yNew] == 1) System.out.println("RIIIIIIIIIIIIIIIIIIIIIIIIIIIDI");
if (ground[xPrevious][yPrevious] == 0) System.out.println("RIIIIIIIIIIIIIIIIIIIIIIIIIIIDI 2");
int c = 0;
for (int j, z = 0; z < n; z++)
for (j = 0; j < m; j++)
if (ground[z][j] == 1)
c++;
System.out.println("c1 ===== " + c);
if (xNew == thiefSituation[0][0] && yNew == thiefSituation[0][1]) return;
ground[xPrevious][yPrevious] = 0;
c = 0;
for (int j, z = 0; z < n; z++)
for (j = 0; j < m; j++)
if (ground[z][j] == 1)
c++;
System.out.println("c2 ===== " + c+" k == "+k);
ground[xNew][yNew] = k;
c = 0;
for (int j, z = 0; z < n; z++)
for (j = 0; j < m; j++)
if (ground[z][j] == 1)
c++;
System.out.println("c3 ===== " + c);
}
public int[][] getGround() {
......@@ -157,6 +131,10 @@ public class PlayGround {
}
public boolean isEmpty(int x, int y) {
if (ground[x][y] == -1) {
catchThief = true;
return true;
}
return ground[x][y] == 0;
}
......@@ -174,5 +152,7 @@ public class PlayGround {
return ret;
}
public boolean getCatchThief() {
return catchThief;
}
}
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