Commit a6054093 authored by hosein's avatar hosein

playground -> putRandom | int[][] upgraded!

parent ff9f1406
......@@ -30,18 +30,34 @@ public class PlayGround {
}
}
public void putRandom() {
public int[][] putRandom() {
int[][] positions = new int[policeNumbers + 1][2];
int i, j, k;
Random rand = new Random();
if (n * m > policeNumbers)
for (k = 0; k < policeNumbers; k++) {
if (n * m < policeNumbers) System.out.println("Error!! NOT ENOUGH SPACE FOR POLICES AND THIEF IN GROUND");
else {
for (k = 0; k < policeNumbers; k++) { // police
i = rand.nextInt();
j = rand.nextInt();
if (ground[i][j] == 0)
if (ground[i][j] == 0) {
ground[i][j] = 1;
else k--;
positions[k][0] = i; // x
positions[k][1] = j; // y
} else k--;
}
else System.out.println("Error!! police numbers are higher than n*m");
for (k = 0; k < 1; k++) { // thief
i = rand.nextInt();
j = rand.nextInt();
if (ground[i][j] == 0) {
ground[i][j] = 1;
positions[policeNumbers][0] = i; // x
positions[policeNumbers][1] = j; // y
}
}
}
return positions;
}
public void change(int[][] newPolicesSituation, int xThief, int yThief) {
......@@ -49,6 +65,7 @@ public class PlayGround {
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
for (i = 0; i < policeNumbers; i++)
ground[newPolicesSituation[i][0]][newPolicesSituation[i][1]] = 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