Commit e0e67cec authored by Omid Sayfun's avatar Omid Sayfun

Added Time Capability

parent cd883191
import java.util.*;
import java.util.concurrent.*;
import java.io.IOException;
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 j = 0; j < m; j++){
if( isTakenByThief(i, j) ){
......@@ -105,7 +137,7 @@ public class Main{
mainBoard.polices.add(newPolice);
}
// Create Thiefs
for(int i = 0; i < p; i++){
for(int i = 0; i < t; i++){
boolean flag = true;
int x = 0, y = 0;
while(flag){
......@@ -117,8 +149,12 @@ public class Main{
mainBoard.thiefs.add(newThief);
}
// Print fucking board
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.print();
for(int i = 0; i < 300; i++){
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.print(i);
TimeUnit.SECONDS.sleep(2);
mainBoard.timeMove();
}
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