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
Show 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,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
.
thief
s
=
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
++){
...
...
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