Commit cd883191 authored by Omid Sayfun's avatar Omid Sayfun

First Breakpoint

parent fa80d9d3
......@@ -14,6 +14,51 @@ public class Main{
this.thiefs = new ArrayList<Thief>();
this.polices = new ArrayList<Police>();
}
public Boolean isTakenByThief(int x, int y){
for(Thief t : this.thiefs){
if( t.x == x && t.y == y ){
return true;
}
}
return false;
}
public Boolean isTakenByPolice(int x, int y){
for(Police t : this.polices){
if( t.x == x && t.y == y ){
return true;
}
}
return false;
}
public Boolean isFree(int x, int y){
if( !isTakenByThief(x, y) && !isTakenByPolice(x, y) ){
return true;
}else{
return false;
}
}
public void print(){
for(int i = 0; i < n; i++){// Check Bounds
for(int j = 0; j < m; j++){
if( isTakenByThief(i, j) ){
System.out.print("T ");
}else if( isTakenByPolice(i, j) ){
System.out.print("P ");
}else{
System.out.print("- ");
}
}
System.out.println("");
}
}
}
static class Thief{
public int x;
......@@ -34,6 +79,46 @@ public class Main{
}
}
public static void main(String[] args) throws IOException, InterruptedException{
Scanner sc = new Scanner(System.in);
// Get Data
System.out.println("Enter N: ");
int n = Integer.parseInt(sc.next());
System.out.println("Enter M: ");
int m = Integer.parseInt(sc.next());
System.out.println("Enter number of polices: ");
int p = Integer.parseInt(sc.next());
System.out.println("Enter number of thiefs: ");
int t = Integer.parseInt(sc.next());
// Initialize Board
Board mainBoard = new Board(n, m);
Random rand = new Random();
// Create Polices
for(int i = 0; i < p; i++){
boolean flag = true;
int x = 0, y = 0;
while(flag){
x = rand.nextInt(n);
y = rand.nextInt(m);
flag = !mainBoard.isFree(x, y);
}
Police newPolice = new Police(x, y);
mainBoard.polices.add(newPolice);
}
// Create Thiefs
for(int i = 0; i < p; i++){
boolean flag = true;
int x = 0, y = 0;
while(flag){
x = rand.nextInt(n);
y = rand.nextInt(m);
flag = !mainBoard.isFree(x, y);
}
Thief newThief = new Thief(x, y);
mainBoard.thiefs.add(newThief);
}
// Print fucking board
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
mainBoard.print();
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