Commit ef5bb69c authored by Omid Sayfun's avatar Omid Sayfun

Changed to Single Thief

parent e0e67cec
Pipeline #484 canceled with stages
......@@ -6,23 +6,25 @@ public class Main{
static class Board{
public int n;
public int m;
public ArrayList<Thief> thiefs;
public Thief thief;
public int thiefMoves;
public int policeMoves;
public ArrayList<Police> polices;
public Board(int n, int m){
this.n = n;
this.m = m;
this.thiefs = new ArrayList<Thief>();
this.thief = null;
this.polices = new ArrayList<Police>();
this.thiefMoves = 0;
this.policeMoves = 0;
}
public Boolean isTakenByThief(int x, int y){
for(Thief t : this.thiefs){
if( t.x == x && t.y == y ){
if( this.thief != null && this.thief.x == x && this.thief.y == y ){
return true;
}
}
return false;
}
......@@ -45,13 +47,22 @@ public class Main{
}
}
public Boolean isThiefInRange(int x, int y){
if( Math.abs(this.thief.x - x) <= 2 && Math.abs(this.thief.y - y) <= 2 ){
return true;
}
return false;
}
public void timeMove(){
Random rand = new Random();
for(Thief t : this.thiefs){
// Move Polices
for(Police p : this.polices){
while(true){
int xShift = rand.nextInt(3) - 1;
while(true){
if( t.x + xShift >= 0 && t.x + xShift < this.n ){
if( p.x + xShift >= 0 && p.x + xShift < this.n ){
break;
}
......@@ -59,16 +70,16 @@ public class Main{
}
int yShift = rand.nextInt(3) - 1;
while(true){
if( t.y + yShift >= 0 && t.y + yShift < this.m ){
if( p.y + yShift >= 0 && p.y + yShift < this.m ){
break;
}
yShift = rand.nextInt(3) - 1;
}
if( isFree(t.x + xShift, t.y + yShift) ){
if( isFree(p.x + xShift, p.y + yShift) ){
t.x += xShift;
t.y += yShift;
p.x += xShift;
p.y += yShift;
break;
}
}
......@@ -104,10 +115,12 @@ public class Main{
static class Police{
public int x;
public int y;
public Thief target;
public Police(int x, int y){
this.x = x;
this.y = y;
this.target = null;
}
}
public static void main(String[] args) throws IOException, InterruptedException{
......@@ -119,13 +132,10 @@ public class Main{
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++){
// Create Thief
boolean flag = true;
int x = 0, y = 0;
while(flag){
......@@ -133,20 +143,20 @@ public class Main{
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 < t; i++){
boolean flag = true;
int x = 0, y = 0;
Thief newThief = new Thief(x, y);
mainBoard.thief = newThief;
// Create Polices
for(int i = 0; i < p; i++){
flag = true;
x = 0;
y = 0;
while(flag){
x = rand.nextInt(n);
y = rand.nextInt(m);
flag = !mainBoard.isFree(x, y);
flag = !(mainBoard.isFree(x, y) && !mainBoard.isThiefInRange(x, y));
}
Thief newThief = new Thief(x, y);
mainBoard.thiefs.add(newThief);
Police newPolice = new Police(x, y);
mainBoard.polices.add(newPolice);
}
// Print fucking board
for(int i = 0; i < 300; i++){
......
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