Commit e0e67cec authored by Omid Sayfun's avatar Omid Sayfun

Added Time Capability

parent cd883191
import java.util.*; import java.util.*;
import java.util.concurrent.*;
import java.io.IOException; import java.io.IOException;
public class Main{ public class Main{
...@@ -44,7 +45,38 @@ public class Main{ ...@@ -44,7 +45,38 @@ public class Main{
} }
} }
public void print(){ public void timeMove(){
Random rand = new Random();
for(Thief t : this.thiefs){
while(true){
int xShift = rand.nextInt(3) - 1;
while(true){
if( t.x + xShift >= 0 && t.x + xShift < this.n ){
break;
}
xShift = rand.nextInt(3) - 1;
}
int yShift = rand.nextInt(3) - 1;
while(true){
if( t.y + yShift >= 0 && t.y + yShift < this.m ){
break;
}
yShift = rand.nextInt(3) - 1;
}
if( isFree(t.x + xShift, t.y + yShift) ){
t.x += xShift;
t.y += yShift;
break;
}
}
}
}
public void print(int t){
System.out.println("Time: " + t);
for(int i = 0; i < n; i++){// Check Bounds for(int i = 0; i < n; i++){// Check Bounds
for(int j = 0; j < m; j++){ for(int j = 0; j < m; j++){
if( isTakenByThief(i, j) ){ if( isTakenByThief(i, j) ){
...@@ -105,7 +137,7 @@ public class Main{ ...@@ -105,7 +137,7 @@ public class Main{
mainBoard.polices.add(newPolice); mainBoard.polices.add(newPolice);
} }
// Create Thiefs // Create Thiefs
for(int i = 0; i < p; i++){ for(int i = 0; i < t; i++){
boolean flag = true; boolean flag = true;
int x = 0, y = 0; int x = 0, y = 0;
while(flag){ while(flag){
...@@ -117,8 +149,12 @@ public class Main{ ...@@ -117,8 +149,12 @@ public class Main{
mainBoard.thiefs.add(newThief); mainBoard.thiefs.add(newThief);
} }
// Print fucking board // Print fucking board
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); for(int i = 0; i < 300; i++){
mainBoard.print(); new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.print(i);
TimeUnit.SECONDS.sleep(2);
mainBoard.timeMove();
}
sc.close(); 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