Commit 36a1ea07 authored by hosein's avatar hosein

Main updated

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