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
9731077
Police
Commits
329b56a2
Commit
329b56a2
authored
Apr 21, 2019
by
9731077
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished
parent
6797a5f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
7 deletions
+121
-7
Police.java
Police.java
+121
-7
No files found.
Police.java
View file @
329b56a2
import
java.util.*
;
public
class
Police
{
private
int
x
,
y
,
policeNum
,
previosX
,
previosY
,
moveNum
;
public
Police
(
int
policeNum
){
this
.
policeNum
=
policeNum
;
private
int
x
,
y
,
policeNum
,
previosx
,
previosy
,
moveNum
;
public
Police
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
}
public
int
getMoveNum
()
{
...
...
@@ -13,19 +17,19 @@ public class Police {
}
public
int
getPreviosX
()
{
return
previos
X
;
return
previos
x
;
}
public
void
setPreviosX
(
int
previosX
)
{
this
.
previos
X
=
previosX
;
this
.
previos
x
=
previosX
;
}
public
int
getPreviosY
()
{
return
previos
Y
;
return
previos
y
;
}
public
void
setPreviosY
(
int
previosY
)
{
this
.
previos
Y
=
previosY
;
this
.
previos
y
=
previosY
;
}
public
int
getX
()
{
...
...
@@ -43,4 +47,114 @@ public class Police {
public
void
setY
(
int
y
)
{
this
.
y
=
y
;
}
public
void
setPoliceNum
(
int
policeNum
)
{
this
.
policeNum
=
policeNum
;
}
public
boolean
lookingForRobber
(
int
m
,
int
n
,
int
xThief
,
int
yThief
)
{
boolean
bl
=
false
;
for
(
int
i
=
x
-
2
;
i
<=
x
+
2
;
i
++)
for
(
int
j
=
y
-
2
;
j
<=
y
+
2
;
j
++)
if
(
i
==
xThief
&&
j
==
yThief
)
bl
=
true
;
return
bl
;
}
public
void
moveIntellegently
(
int
xThief
,
int
yThief
)
{
if
(
xThief
>
x
)
x
++;
if
(
xThief
<
x
)
x
--;
if
(
x
==
xThief
&&
yThief
>
y
)
y
++;
if
(
x
==
xThief
&&
yThief
<
y
)
y
--;
moveNum
++;
}
public
void
moveRandomly
(
int
m
,
int
n
)
{
Random
randomGenerator
=
new
Random
();
moveNum
++;
if
(
x
!=
0
&&
x
!=
m
-
1
&&
y
!=
0
&&
y
!=
n
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
!=
0
&&
y
!=
n
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
y
==
0
&&
x
!=
0
&&
x
!=
m
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
);
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
m
-
1
&&
y
!=
0
&&
y
!=
n
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
y
==
n
-
1
&&
x
!=
0
&&
x
!=
m
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
==
0
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
2
);
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
m
-
1
&&
y
==
0
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
);
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
==
n
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
m
-
1
&&
y
==
n
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
previosx
=
x
;
previosy
=
y
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
}
}
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