Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
AP Lab 6
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Omid Sayfun
AP Lab 6
Commits
ef5bb69c
Commit
ef5bb69c
authored
Apr 17, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed to Single Thief
parent
e0e67cec
Pipeline
#484
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
32 deletions
+42
-32
Main.java
Main.java
+42
-32
No files found.
Main.java
View file @
ef5bb69c
...
@@ -6,22 +6,24 @@ public class Main{
...
@@ -6,22 +6,24 @@ public class Main{
static
class
Board
{
static
class
Board
{
public
int
n
;
public
int
n
;
public
int
m
;
public
int
m
;
public
ArrayList
<
Thief
>
thiefs
;
public
Thief
thief
;
public
int
thiefMoves
;
public
int
policeMoves
;
public
ArrayList
<
Police
>
polices
;
public
ArrayList
<
Police
>
polices
;
public
Board
(
int
n
,
int
m
){
public
Board
(
int
n
,
int
m
){
this
.
n
=
n
;
this
.
n
=
n
;
this
.
m
=
m
;
this
.
m
=
m
;
this
.
thiefs
=
new
ArrayList
<
Thief
>();
this
.
thief
=
null
;
this
.
polices
=
new
ArrayList
<
Police
>();
this
.
polices
=
new
ArrayList
<
Police
>();
this
.
thiefMoves
=
0
;
this
.
policeMoves
=
0
;
}
}
public
Boolean
isTakenByThief
(
int
x
,
int
y
){
public
Boolean
isTakenByThief
(
int
x
,
int
y
){
for
(
Thief
t
:
this
.
thiefs
){
if
(
this
.
thief
!=
null
&&
this
.
thief
.
x
==
x
&&
this
.
thief
.
y
==
y
){
if
(
t
.
x
==
x
&&
t
.
y
==
y
){
return
true
;
return
true
;
}
}
}
return
false
;
return
false
;
}
}
...
@@ -45,13 +47,22 @@ public class Main{
...
@@ -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
(){
public
void
timeMove
(){
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
for
(
Thief
t
:
this
.
thiefs
){
// Move Polices
for
(
Police
p
:
this
.
polices
){
while
(
true
){
while
(
true
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
while
(
true
){
if
(
t
.
x
+
xShift
>=
0
&&
t
.
x
+
xShift
<
this
.
n
){
if
(
p
.
x
+
xShift
>=
0
&&
p
.
x
+
xShift
<
this
.
n
){
break
;
break
;
}
}
...
@@ -59,16 +70,16 @@ public class Main{
...
@@ -59,16 +70,16 @@ public class Main{
}
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
while
(
true
){
if
(
t
.
y
+
yShift
>=
0
&&
t
.
y
+
yShift
<
this
.
m
){
if
(
p
.
y
+
yShift
>=
0
&&
p
.
y
+
yShift
<
this
.
m
){
break
;
break
;
}
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
}
if
(
isFree
(
t
.
x
+
xShift
,
t
.
y
+
yShift
)
){
if
(
isFree
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
t
.
x
+=
xShift
;
p
.
x
+=
xShift
;
t
.
y
+=
yShift
;
p
.
y
+=
yShift
;
break
;
break
;
}
}
}
}
...
@@ -104,10 +115,12 @@ public class Main{
...
@@ -104,10 +115,12 @@ public class Main{
static
class
Police
{
static
class
Police
{
public
int
x
;
public
int
x
;
public
int
y
;
public
int
y
;
public
Thief
target
;
public
Police
(
int
x
,
int
y
){
public
Police
(
int
x
,
int
y
){
this
.
x
=
x
;
this
.
x
=
x
;
this
.
y
=
y
;
this
.
y
=
y
;
this
.
target
=
null
;
}
}
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
...
@@ -119,35 +132,32 @@ public class Main{
...
@@ -119,35 +132,32 @@ public class Main{
int
m
=
Integer
.
parseInt
(
sc
.
next
());
int
m
=
Integer
.
parseInt
(
sc
.
next
());
System
.
out
.
println
(
"Enter number of polices: "
);
System
.
out
.
println
(
"Enter number of polices: "
);
int
p
=
Integer
.
parseInt
(
sc
.
next
());
int
p
=
Integer
.
parseInt
(
sc
.
next
());
System
.
out
.
println
(
"Enter number of thiefs: "
);
int
t
=
Integer
.
parseInt
(
sc
.
next
());
// Initialize Board
// Initialize Board
Board
mainBoard
=
new
Board
(
n
,
m
);
Board
mainBoard
=
new
Board
(
n
,
m
);
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
// Create Thief
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
.
thief
=
newThief
;
// Create Polices
// Create Polices
for
(
int
i
=
0
;
i
<
p
;
i
++){
for
(
int
i
=
0
;
i
<
p
;
i
++){
boolean
flag
=
true
;
flag
=
true
;
int
x
=
0
,
y
=
0
;
x
=
0
;
y
=
0
;
while
(
flag
){
while
(
flag
){
x
=
rand
.
nextInt
(
n
);
x
=
rand
.
nextInt
(
n
);
y
=
rand
.
nextInt
(
m
);
y
=
rand
.
nextInt
(
m
);
flag
=
!
mainBoard
.
isFree
(
x
,
y
);
flag
=
!
(
mainBoard
.
isFree
(
x
,
y
)
&&
!
mainBoard
.
isThiefInRange
(
x
,
y
)
);
}
}
Police
newPolice
=
new
Police
(
x
,
y
);
Police
newPolice
=
new
Police
(
x
,
y
);
mainBoard
.
polices
.
add
(
newPolice
);
mainBoard
.
polices
.
add
(
newPolice
);
}
}
// Create Thiefs
for
(
int
i
=
0
;
i
<
t
;
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
// Print fucking board
for
(
int
i
=
0
;
i
<
300
;
i
++){
for
(
int
i
=
0
;
i
<
300
;
i
++){
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment