Commit 329b56a2 authored by 9731077's avatar 9731077

finished

parent 6797a5f1
import java.util.*;
public class Police {
private int x, y, policeNum, previosX, previosY, moveNum;
public Police(int policeNum){
this.policeNum = policeNum;
private int x, y, policeNum, previosx, previosy, moveNum;
public Police(int x, int y) {
this.x = x;
this.y = y;
}
public int getMoveNum() {
......@@ -13,19 +17,19 @@ public class Police {
}
public int getPreviosX() {
return previosX;
return previosx;
}
public void setPreviosX(int previosX) {
this.previosX = previosX;
this.previosx = previosX;
}
public int getPreviosY() {
return previosY;
return previosy;
}
public void setPreviosY(int previosY) {
this.previosY = previosY;
this.previosy = previosY;
}
public int getX() {
......@@ -43,4 +47,114 @@ public class Police {
public void setY(int y) {
this.y = y;
}
public void setPoliceNum(int policeNum) {
this.policeNum = policeNum;
}
public boolean lookingForRobber(int m, int n, int xThief, int yThief) {
boolean bl = false;
for (int i = x - 2; i <= x + 2; i++)
for (int j = y - 2; j <= y + 2; j++)
if (i == xThief && j == yThief)
bl = true;
return bl;
}
public void moveIntellegently(int xThief, int yThief) {
if (xThief > x)
x++;
if (xThief < x)
x--;
if (x == xThief && yThief > y)
y++;
if (x == xThief && yThief < y)
y--;
moveNum++;
}
public void moveRandomly(int m, int n) {
Random randomGenerator = new Random();
moveNum++;
if (x != 0 && x != m - 1 && y != 0 && y != n - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(3) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == 0 && y != 0 && y != n - 1) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(3) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (y == 0 && x != 0 && x != m - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(2);
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == m - 1 && y != 0 && y != n - 1) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(3) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (y == n - 1 && x != 0 && x != m - 1) {
int rx = randomGenerator.nextInt(3) - 1;
int ry = randomGenerator.nextInt(2) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == 0 && y == 0) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(2);
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == m - 1 && y == 0) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(2);
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == 0 && y == n - 1) {
int rx = randomGenerator.nextInt(2);
int ry = randomGenerator.nextInt(2) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
if (x == m - 1 && y == n - 1) {
int rx = randomGenerator.nextInt(2) - 1;
int ry = randomGenerator.nextInt(2) - 1;
previosx = x;
previosy = y;
x = x + rx;
y = y + ry;
}
}
}
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