Commit 8e1b2215 authored by hosein's avatar hosein

finish

parent 218b9ba1
...@@ -71,12 +71,17 @@ public class Main { ...@@ -71,12 +71,17 @@ public class Main {
if (playGround.getCatchThief()) { if (playGround.getCatchThief()) {
break; break;
} else playGround.show(1200); } else playGround.show(1200);
System.out.print("\n\n\n\n"); System.out.print("\f\n\n\n\n");
/*
FIRST MOVE : POLICE
/* thiefSituation = playGround.canPoliceSeeThief();
thiefSituation = playGround.canPoliceSeeThief();
if (thiefSituation == null) { if (thiefSituation == null) {
......
...@@ -29,8 +29,10 @@ public class PlayGround { ...@@ -29,8 +29,10 @@ public class PlayGround {
System.out.print("-"); System.out.print("-");
else if (ground[i][j] == 1) // police else if (ground[i][j] == 1) // police
System.out.print("X"); System.out.print("X");
else // Dozd else if (ground[i][j] == -1)// Dozd
System.out.print("*"); System.out.print("*");
else
System.out.print("O");
} }
System.out.println(); System.out.println();
} }
...@@ -75,7 +77,11 @@ public class PlayGround { ...@@ -75,7 +77,11 @@ 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] && k == 1) return; if (xNew == thiefSituation[0][0] && yNew == thiefSituation[0][1] && k == 1) {
ground[xPrevious][yPrevious] = 0;
ground[xNew][yNew] = 100;
return ;
}
ground[xPrevious][yPrevious] = 0; ground[xPrevious][yPrevious] = 0;
ground[xNew][yNew] = k; ground[xNew][yNew] = k;
if (k == -1) { if (k == -1) {
......
...@@ -219,7 +219,7 @@ public class Police { ...@@ -219,7 +219,7 @@ public class Police {
return newSituation; return newSituation;
} }
case 1: case 1:
if (x != p.getNM()[0][0] && p.isEmpty(x + 1, y - 1)) { // go down, left if (x != p.getNM()[0][0]-1 && p.isEmpty(x + 1, y - 1)) { // go down, left
newSituation[0][0] = x + 1; newSituation[0][0] = x + 1;
newSituation[0][1] = y - 1; newSituation[0][1] = y - 1;
return newSituation; return newSituation;
...@@ -238,7 +238,7 @@ public class Police { ...@@ -238,7 +238,7 @@ public class Police {
} else { } else {
switch (r.nextInt(2)) { switch (r.nextInt(2)) {
case 0: case 0:
if (x != p.getNM()[0][0] && p.isEmpty(x + 1, y + 1)) { // go down, right if (x != p.getNM()[0][0] -1&& p.isEmpty(x + 1, y + 1)) { // go down, right
newSituation[0][0] = x + 1; newSituation[0][0] = x + 1;
newSituation[0][1] = y + 1; newSituation[0][1] = y + 1;
return newSituation; return newSituation;
...@@ -294,7 +294,7 @@ public class Police { ...@@ -294,7 +294,7 @@ public class Police {
return newSituation; return newSituation;
} }
case 1: case 1:
if (y != p.getNM()[0][1] && p.isEmpty(x + 1, y + 1)) { // go down, right if (y != p.getNM()[0][1] -1&& p.isEmpty(x + 1, y + 1)) { // go down, right
newSituation[0][0] = x + 1; newSituation[0][0] = x + 1;
newSituation[0][1] = y + 1; newSituation[0][1] = y + 1;
return newSituation; return newSituation;
......
...@@ -170,21 +170,7 @@ public class Thief { ...@@ -170,21 +170,7 @@ public class Thief {
private int[][] almostRandomMove(boolean[] is, PlayGround p) { private int[][] almostRandomMove(boolean[] is, PlayGround p) {
int[][] destination = new int[1][2]; int[][] destination = new int[1][2];
boolean[] isPoliceThere0 = is, isPoliceThere = new boolean[8]; boolean[] isPoliceThere0 = is, isPoliceThere = is;
for (int i=0;i<8;i++)
isPoliceThere0[i] = false;
System.out.println("before:");
for (int i = 0;i< 3;i++)
System.out.print(isPoliceThere0[i]+" ");
System.out.println();
for (int i = 3;i<5 ;i++)
System.out.print(isPoliceThere0[i]+" ");
System.out.println();
for (int i =5 ;i<8 ;i++)
System.out.print(isPoliceThere0[i]+" ");
System.out.println("\n\n");
if (isPoliceThere0[0]) { if (isPoliceThere0[0]) {
...@@ -228,17 +214,6 @@ System.out.println("before:"); ...@@ -228,17 +214,6 @@ System.out.println("before:");
isPoliceThere[6] = true; isPoliceThere[6] = true;
} }
for (int i = 0;i< 3;i++)
System.out.print(isPoliceThere[i]+" ");
System.out.println();
for (int i = 3;i<5 ;i++)
System.out.print(isPoliceThere[i]+" ");
System.out.println();
for (int i =5 ;i<8 ;i++)
System.out.print(isPoliceThere[i]+" ");
System.out.println();
if (!isPoliceThere[0] || !isPoliceThere[1] || !isPoliceThere[2] || !isPoliceThere[3] || !isPoliceThere[4] || !isPoliceThere[5] || !isPoliceThere[6] || !isPoliceThere[7]) { if (!isPoliceThere[0] || !isPoliceThere[1] || !isPoliceThere[2] || !isPoliceThere[3] || !isPoliceThere[4] || !isPoliceThere[5] || !isPoliceThere[6] || !isPoliceThere[7]) {
Random r = new Random(); Random r = new Random();
......
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