Commit 0ac16802 authored by Omid Sayfun's avatar Omid Sayfun

Added Thoughtful:D Movement

parent ef5bb69c
Pipeline #485 failed with stages
......@@ -59,6 +59,8 @@ public class Main{
Random rand = new Random();
// Move Polices
for(Police p : this.polices){
if( p.target == null){// Random Move
while(true){
int xShift = rand.nextInt(3) - 1;
while(true){
......@@ -80,8 +82,100 @@ public class Main{
p.x += xShift;
p.y += yShift;
if( isThiefInRange(p.x, p.y) ){
for( Police police : this.polices ){
police.target = this.thief;
}
}
this.policeMoves++;
break;
}
}
}else{// Move based on thought :D
int xShiftThought = 0;
int yShiftThought = 0;
if( p.target.x - p.x != 0 ){
xShiftThought = (p.target.x - p.x) / Math.abs(p.target.x - p.x);
}
if( p.target.y - p.y != 0 ){
yShiftThought = (p.target.y - p.y) / Math.abs(p.target.y - p.y);
}
if( isFree(p.x + xShiftThought, p.y + yShiftThought) ){ // Diagonal
p.x += xShiftThought;
p.y += yShiftThought;
this.policeMoves++;
}else if( isFree(p.x, p.y + yShiftThought) ){ // Y Axis
p.y += yShiftThought;
this.policeMoves++;
}else if( isFree(p.x + xShiftThought, p.y) ){ // X Axis
p.x += xShiftThought;
this.policeMoves++;
}else{ // Random Move
while(true){
int xShift = rand.nextInt(3) - 1;
while(true){
if( p.x + xShift >= 0 && p.x + xShift < this.n ){
break;
}
xShift = rand.nextInt(3) - 1;
}
int yShift = rand.nextInt(3) - 1;
while(true){
if( p.y + yShift >= 0 && p.y + yShift < this.m ){
break;
}
yShift = rand.nextInt(3) - 1;
}
if( isFree(p.x + xShift, p.y + yShift) ){
p.x += xShift;
p.y += yShift;
if( p.target == null && isThiefInRange(p.x, p.y) ){
for( Police police : this.polices ){
police.target = this.thief;
}
}
this.policeMoves++;
break;
}
}
}
}
}
// Move Thief
while(true){
int xShift = rand.nextInt(3) - 1;
while(true){
if( this.thief.x + xShift >= 0 && this.thief.x + xShift < this.n ){
break;
}
xShift = rand.nextInt(3) - 1;
}
int yShift = rand.nextInt(3) - 1;
while(true){
if( this.thief.y + yShift >= 0 && this.thief.y + yShift < this.m ){
break;
}
yShift = rand.nextInt(3) - 1;
}
// To Do: Check if thief went into police house
if( isFree(this.thief.x + xShift, this.thief.y + yShift) ){
this.thief.x += xShift;
this.thief.y += yShift;
this.thiefMoves++;
break;
}
}
}
......
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