Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
police
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
9611046
police
Commits
d4850a88
Commit
d4850a88
authored
Apr 21, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main changes
parent
92929a35
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
7 deletions
+151
-7
Main.java
src/Main.java
+151
-7
No files found.
src/Main.java
View file @
d4850a88
...
@@ -4,20 +4,164 @@ import java.util.Scanner;
...
@@ -4,20 +4,164 @@ import java.util.Scanner;
public
class
Main
{
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
int
length
=
scanner
.
nextInt
();
int
length
=
scanner
.
nextInt
();
int
width
=
scanner
.
nextInt
();
int
width
=
scanner
.
nextInt
();
int
arrestX
=
56
;
int
arrestY
=
56
;
Land
myLand
=
new
Land
(
length
,
width
);
Land
myLand
=
new
Land
(
length
,
width
);
Random
rand
=
new
Random
();
// police.setLand(myLand);
int
policeNumbers
=
scanner
.
nextInt
();
int
policeNumbers
=
scanner
.
nextInt
();
ArrayList
<
Police
>
polices
=
new
ArrayList
<
Police
>(
policeNumbers
);
ArrayList
<
Police
>
polices
=
new
ArrayList
<>(
policeNumbers
);
for
(
int
i
=
0
;
i
<
polices
.
size
();
i
++)
{
int
[][]
policePlace
;
polices
.
get
(
i
).
setLand
(
myLand
);
policePlace
=
new
int
[
2
][
policeNumbers
];
int
[][]
thiefPlace
=
new
int
[
2
][
1
];
for
(
int
i
=
0
;
i
<
policeNumbers
;
i
++)
{
Police
police
=
new
Police
();
polices
.
add
(
police
);
}
for
(
Police
value
:
polices
)
{
value
.
setLand
(
myLand
);
}
}
Thief
thief
=
new
Thief
();
Thief
thief
=
new
Thief
();
thief
.
setLand
(
myLand
);
thief
.
setLand
(
myLand
);
thiefPlace
[
0
][
0
]
=
rand
.
nextInt
(
myLand
.
getLength
());
thiefPlace
[
1
][
0
]
=
rand
.
nextInt
(
myLand
.
getWidth
());
thief
.
setFirstxy
(
thiefPlace
[
0
][
0
],
thiefPlace
[
1
][
0
]);
for
(
int
i
=
0
;
i
<
policeNumbers
;
i
++)
{
policePlace
[
0
][
i
]
=
rand
.
nextInt
(
myLand
.
getLength
());
policePlace
[
1
][
i
]
=
rand
.
nextInt
(
myLand
.
getWidth
());
if
(
policePlace
[
0
][
i
]
!=
thiefPlace
[
0
][
0
]
&&
policePlace
[
1
][
i
]
!=
thiefPlace
[
1
][
0
])
{
polices
.
get
(
i
).
setFirstxy
(
policePlace
[
0
][
i
],
policePlace
[
1
][
i
]);
}
else
{
policePlace
[
0
][
i
]
=
rand
.
nextInt
(
myLand
.
getLength
());
policePlace
[
1
][
i
]
=
rand
.
nextInt
(
myLand
.
getWidth
());
if
(
policePlace
[
0
][
i
]
!=
thiefPlace
[
0
][
0
]
&&
policePlace
[
1
][
i
]
!=
thiefPlace
[
1
][
0
])
{
polices
.
get
(
i
).
setFirstxy
(
policePlace
[
0
][
i
],
policePlace
[
1
][
i
]);
}
}
}
// while (!polices.get(0).getNotify()) {
do
{
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
myLand
.
setLandMatrix
(
i
,
j
,
'-'
);
}
}
for
(
Police
police
:
polices
)
myLand
.
setLandMatrix
(
police
.
getX
(),
police
.
getY
(),
'P'
);
myLand
.
setLandMatrix
(
thief
.
getX
(),
thief
.
getY
(),
'D'
);
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
System
.
out
.
print
(
myLand
.
getLandMatrix
(
i
,
j
));
}
System
.
out
.
println
();
}
Thread
.
sleep
(
1000
);
System
.
out
.
println
();
thief
.
move
();
for
(
Police
police
:
polices
)
{
police
.
move
();
}
for
(
Police
police
:
polices
)
{
if
((
Math
.
abs
(
police
.
getX
()
-
thief
.
getX
())
<=
2
)
&&
(
Math
.
abs
(
police
.
getY
()
-
thief
.
getY
())
<=
2
))
{
for
(
Police
value
:
polices
)
{
value
.
setNotify
(
true
);
}
break
;
}
}
}
while
(!
polices
.
get
(
0
).
getNotify
());
System
.
out
.
println
(
"The thief is observed!!!!!!!!!!!!"
+
"Here is my exiting chase!!!!!!!!!!!"
);
// Printing land after notifying
// Move smartMove = new
//moving polices after notifying
do
{
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
myLand
.
setLandMatrix
(
i
,
j
,
'-'
);
}
}
for
(
Police
police
:
polices
)
myLand
.
setLandMatrix
(
police
.
getX
(),
police
.
getY
(),
'P'
);
myLand
.
setLandMatrix
(
thief
.
getX
(),
thief
.
getY
(),
'D'
);
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
System
.
out
.
print
(
myLand
.
getLandMatrix
(
i
,
j
));
}
System
.
out
.
println
();
}
Thread
.
sleep
(
2000
);
System
.
out
.
println
();
thief
.
smartMove
(
polices
.
get
(
0
).
getX
(),
polices
.
get
(
0
).
getY
());
for
(
Police
police
:
polices
)
{
police
.
smartMove
(
thief
.
getX
(),
thief
.
getY
());
}
for
(
Police
police
:
polices
)
{
if
(
police
.
getX
()
==
thief
.
getX
()
&&
police
.
getY
()
==
thief
.
getY
())
{
arrestX
=
thief
.
getX
();
arrestY
=
thief
.
getY
();
for
(
Police
value
:
polices
)
{
value
.
SetThiefCatch
(
true
);
}
break
;
}
}
}
while
(!
polices
.
get
(
0
).
getThiefCatch
());
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
myLand
.
setLandMatrix
(
i
,
j
,
'-'
);
}
}
myLand
.
setLandMatrix
(
arrestX
,
arrestY
,
'*'
);
for
(
int
i
=
0
;
i
<
myLand
.
getLength
();
i
++)
{
for
(
int
j
=
0
;
j
<
myLand
.
getWidth
();
j
++)
{
System
.
out
.
print
(
myLand
.
getLandMatrix
(
i
,
j
));
}
System
.
out
.
println
();
}
}
}
}
}
\ No newline at end of file
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