Commit 92929a35 authored by 9611046's avatar 9611046

smartMove adds

parent 1b0bf0d9
...@@ -3,6 +3,8 @@ import java.util.Random; ...@@ -3,6 +3,8 @@ import java.util.Random;
public class Move { public class Move {
private int x; private int x;
private int y; private int y;
private int w;
private int z;
private Land moveLand; private Land moveLand;
public Move(int x,int y,Land land){ public Move(int x,int y,Land land){
...@@ -10,7 +12,14 @@ public class Move { ...@@ -10,7 +12,14 @@ public class Move {
this.y = y; this.y = y;
moveLand = land; 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(){ public void moveXY(){
Random rand = new Random(); Random rand = new Random();
int a = rand.nextInt(8); int a = rand.nextInt(8);
...@@ -91,10 +100,76 @@ public class Move { ...@@ -91,10 +100,76 @@ public class Move {
} }
} }
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(){ public int getX(){
return x; return x;
} }
public int getY(){ public int getY(){
return y; return y;
} }
public int getW(){
return w;
}
public int getZ(){
return z;
}
} }
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