import java.util.Random; public class Move { private int x; private int y; private int w; private int z; private Land moveLand; public Move(int x,int y,Land land){ this.x = x; this.y = y; moveLand = land; } public Move(int x,int y,int w,int z,Land land){ this.x = x; this.y = y; this.w = w; this.z = z; moveLand = land; } //Random Move public void moveXY(){ Random rand = new Random(); int a = rand.nextInt(8); switch (a) { case 0: //Right if (y + 1 <moveLand.getLength()) { y += 1; break; } else moveXY(); case 1: //Left if (y > 0) { y -= 1; break; } else moveXY(); case 2: //Up if (x > 0) { x -= 1; break; } else moveXY(); case 3: //Down if (x + 1 < moveLand.getWidth()) { x += 1; break; } else moveXY(); case 4: //North East if ((x > 0) && (y + 1 < moveLand.getLength())) { x -= 1; y += 1; break; } else moveXY(); case 5: //North west if (x > 0 && y>0) { y -= 1; x -= 1; break; } else moveXY(); case 6: //Southeast if ((x + 1 < moveLand.getWidth()) && (y + 1 < moveLand.getLength())) { y += 1; x += 1; break; } else moveXY(); case 7: //Southwest if ((x + 1 < moveLand.getWidth()) && (y > 0)) { x += 1; y -= 1; break; } else moveXY(); } } public void smartMove(){ // Random random = new Random(); //This is the smart move of police and thief x,y are PoliceX, PoliceY and w, z are thiefX, thiefY if(x>w ){ if(y>z){ y-=1; x-=1; if(w>0) {w-=1;} if(z>0 ){z-=1;} } else if(y<z){ x-=1; y+=1; if(w>0) w-=1; if(z+1 <moveLand.getLength()) z+=1; } else { x-=1; if(w>0) w-=1; } } else if(x<w){ if(y>z){ y-=1; x+=1; if(w+1<moveLand.getWidth()) w+=1; if(z>0) z-=1; } else if(y<z){ x+=1; y+=1; if(w+1<moveLand.getWidth())w++; if(z+1<moveLand.getLength())z++; } else { x++; if(w+1<moveLand.getWidth())w++; } } else{ if(y>z){ y--; if(z>0) z--; } else if(y<z){ y++; if(z+1<moveLand.getLength()) z++; } } } public int getX(){ return x; } public int getY(){ return y; } public int getW(){ return w; } public int getZ(){ return z; } }