Commit 32eac881 authored by Omid Sayfun's avatar Omid Sayfun

PreFinal Release

parent 284276d9
......@@ -55,8 +55,41 @@ public class Main{
return false;
}
public void timeMove(){
public Boolean timeMove(){
Random rand = new Random();
int prevX = this.thief.x;
int prevY = this.thief.y;
// 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;
}
this.thiefMoves++;
// To Do: Check if thief went into police house
if( isTakenByPolice(this.thief.x + xShift, this.thief.y + yShift) ){
this.thief.x += xShift;
this.thief.y += yShift;
return false;
}else{
this.thief.x += xShift;
this.thief.y += yShift;
break;
}
}
// Move Polices
for(Police p : this.polices){
if( p.target == null){// Random Move
......@@ -78,7 +111,7 @@ public class Main{
}
yShift = rand.nextInt(3) - 1;
}
if( isFree(p.x + xShift, p.y + yShift) ){
if( !isTakenByPolice(p.x + xShift, p.y + yShift) ){
p.x += xShift;
p.y += yShift;
......@@ -95,27 +128,39 @@ public class Main{
}else{// Move based on thought :D
int xShiftThought = 0;
int yShiftThought = 0;
if( p.target.x - p.x != 0 ){
if( prevX - p.x != 0 ){
xShiftThought = (p.target.x - p.x) / Math.abs(p.target.x - p.x);
xShiftThought = (prevX - p.x) / Math.abs(prevX - p.x);
}
if( p.target.y - p.y != 0 ){
if( prevY - p.y != 0 ){
yShiftThought = (p.target.y - p.y) / Math.abs(p.target.y - p.y);
yShiftThought = (prevY - p.y) / Math.abs(prevY - p.y);
}
if( isFree(p.x + xShiftThought, p.y + yShiftThought) ){ // Diagonal
if( !isTakenByPolice(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
if( p.y == prevY && p.x == prevX ){
return false;
}
}else if( !isTakenByPolice(p.x, p.y + yShiftThought) ){ // Y Axis
p.y += yShiftThought;
this.policeMoves++;
}else if( isFree(p.x + xShiftThought, p.y) ){ // X Axis
if( p.y == prevY && p.x == prevX ){
return false;
}
}else if( !isTakenByPolice(p.x + xShiftThought, p.y) ){ // X Axis
p.x += xShiftThought;
this.policeMoves++;
if( p.y == prevY && p.x == prevX ){
return false;
}
}else{ // Random Move
while(true){
int xShift = rand.nextInt(3) - 1;
......@@ -134,45 +179,23 @@ public class Main{
}
yShift = rand.nextInt(3) - 1;
}
if( isFree(p.x + xShift, p.y + yShift) ){
if( !isTakenByPolice(p.x + xShift, p.y + yShift) ){
p.x += xShift;
p.y += yShift;
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 ){
if( p.y == prevY && p.x == prevX ){
break;
}
xShift = rand.nextInt(3) - 1;
return false;
}
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;
}
}
}
return true;
}
public void print(int t){
System.out.println("Time: " + t);
......@@ -192,7 +215,10 @@ public class Main{
}
public void printFinal(){
System.out.println("\tThe Fucking Thief is caught!");
System.out.println();
System.out.println("Thief Moves: " + this.thiefMoves);
System.out.println("Police Moves: " + this.policeMoves);
}
}
static class Thief{
......@@ -251,12 +277,17 @@ public class Main{
mainBoard.polices.add(newPolice);
}
// Print fucking board
for(int i = 0; i < 300; i++){
flag = true;
int i = 0;
while(flag){
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.print(i);
flag = mainBoard.timeMove();
TimeUnit.SECONDS.sleep(2);
mainBoard.timeMove();
i++;
}
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.printFinal();
sc.close();
}
}
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