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
f23ef9a7
Commit
f23ef9a7
authored
Apr 21, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completes the project
parent
d4850a88
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
85 deletions
+89
-85
Land.java
src/Land.java
+11
-3
Main.java
src/Main.java
+12
-2
Police.java
src/Police.java
+37
-74
Thief.java
src/Thief.java
+29
-6
No files found.
src/Land.java
View file @
f23ef9a7
public
class
Land
{
public
class
Land
{
private
int
length
;
private
int
length
;
private
int
width
;
private
int
width
;
private
int
[][]
landMatrix
=
new
int
[
length
][
width
];
private
char
[][]
landMatrix
;
public
Land
(
int
length
,
int
width
)
{
public
Land
(
int
length
,
int
width
)
{
this
.
length
=
length
;
this
.
length
=
length
;
this
.
width
=
width
;
this
.
width
=
width
;
landMatrix
=
new
char
[
length
][
width
];
}
}
public
int
getLength
()
{
public
int
getLength
()
{
...
@@ -16,8 +18,14 @@ public class Land {
...
@@ -16,8 +18,14 @@ public class Land {
return
width
;
return
width
;
}
}
public
int
[][]
getLandMatrix
()
{
public
void
setLandMatrix
(
int
x
,
int
y
,
char
c
){
return
landMatrix
;
if
(
x
>=
0
&&
x
<
width
&&
y
>=
0
&&
y
<
length
)
{
landMatrix
[
x
][
y
]
=
c
;
}
}
public
char
getLandMatrix
(
int
x
,
int
y
)
{
return
landMatrix
[
x
][
y
];
}
}
}
}
src/Main.java
View file @
f23ef9a7
...
@@ -8,8 +8,10 @@ public class Main {
...
@@ -8,8 +8,10 @@ public class Main {
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
arrestX
=
0
;
int
arrestY
=
56
;
int
arrestY
=
0
;
int
policeMovment
=
0
;
int
thiefMovement
=
0
;
Land
myLand
=
new
Land
(
length
,
width
);
Land
myLand
=
new
Land
(
length
,
width
);
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
int
policeNumbers
=
scanner
.
nextInt
();
int
policeNumbers
=
scanner
.
nextInt
();
...
@@ -78,8 +80,10 @@ public class Main {
...
@@ -78,8 +80,10 @@ public class Main {
thief
.
move
();
thief
.
move
();
thiefMovement
++;
for
(
Police
police
:
polices
)
{
for
(
Police
police
:
polices
)
{
police
.
move
();
police
.
move
();
policeMovment
++;
}
}
...
@@ -127,8 +131,10 @@ System.out.println(
...
@@ -127,8 +131,10 @@ System.out.println(
thief
.
smartMove
(
polices
.
get
(
0
).
getX
(),
polices
.
get
(
0
).
getY
());
thief
.
smartMove
(
polices
.
get
(
0
).
getX
(),
polices
.
get
(
0
).
getY
());
thiefMovement
++;
for
(
Police
police
:
polices
)
{
for
(
Police
police
:
polices
)
{
police
.
smartMove
(
thief
.
getX
(),
thief
.
getY
());
police
.
smartMove
(
thief
.
getX
(),
thief
.
getY
());
policeMovment
++;
}
}
...
@@ -162,6 +168,10 @@ System.out.println(
...
@@ -162,6 +168,10 @@ System.out.println(
System
.
out
.
println
();
System
.
out
.
println
();
}
}
System
.
out
.
println
(
"The number of police movements: "
+
policeMovment
+
"\n"
+
"The number of thieves' moves: "
+
thiefMovement
);
}
}
}
}
src/Police.java
View file @
f23ef9a7
import
java.util.Random
;
public
class
Police
{
public
class
Police
{
Random
rand
=
new
Random
();
Land
policeLand
;
private
Land
policeLand
;
private
int
x
;
private
int
x
;
private
int
y
;
private
int
y
;
public
void
setFirstxy
()
{
x
=
rand
.
nextInt
(
policeLand
.
getLength
());
y
=
rand
.
nextInt
(
policeLand
.
getLength
());
}
public
void
move
()
{
private
boolean
notify
=
false
;
int
a
=
rand
.
nextInt
(
8
);
private
boolean
thiefCatch
=
false
;
switch
(
a
)
{
case
0
:
//Right
if
(
x
+
1
<=
policeLand
.
getLength
())
{
x
+=
1
;
break
;
}
case
1
:
//Left
if
(
x
>
0
)
{
x
-=
1
;
break
;
}
case
2
:
//Up
if
(
y
>
0
)
{
y
-=
1
;
break
;
}
case
3
:
//Down
if
(
y
+
1
<
policeLand
.
getWidth
())
{
y
+=
1
;
}
case
4
:
//North East
if
(
y
>
0
)
{
if
(
x
+
1
<=
policeLand
.
getLength
())
{
y
+=
1
;
x
+=
1
;
}
}
case
5
:
public
void
setFirstxy
(
int
x
,
int
y
)
{
//North west
if
(
y
>
0
)
{
if
(
x
>
0
)
{
y
+=
1
;
x
-=
1
;
}
}
case
6
:
this
.
x
=
x
;
//Southeast
this
.
y
=
y
;
if
(
y
+
1
<
policeLand
.
getWidth
())
{
if
(
x
+
1
<=
policeLand
.
getLength
())
{
y
+=
1
;
x
+=
1
;
break
;
}
}
}
case
7
:
public
void
move
()
{
//Southwest
Move
move1
=
new
Move
(
x
,
y
,
policeLand
);
move1
.
moveXY
();
if
(
y
+
1
<
policeLand
.
getWidth
())
{
this
.
x
=
move1
.
getX
();
if
(
x
>
0
)
{
this
.
y
=
move1
.
getY
();
y
+=
1
;
x
-=
1
;
break
;
}
}
}
public
void
smartMove
(
int
w
,
int
z
)
{
// this.w = x;
// this.z = z;
Move
move1
=
new
Move
(
x
,
y
,
w
,
z
,
policeLand
);
move1
.
smartMove
();
this
.
x
=
move1
.
getX
();
this
.
y
=
move1
.
getY
();
}
}
}
public
void
setLand
(
Land
myLand
)
{
public
void
setLand
(
Land
myLand
)
{
policeLand
=
myLand
;
policeLand
=
myLand
;
}
}
...
@@ -97,4 +45,19 @@ public class Police {
...
@@ -97,4 +45,19 @@ public class Police {
return
y
;
return
y
;
}
}
public
boolean
getNotify
()
{
return
notify
;
}
public
void
setNotify
(
boolean
notify
)
{
this
.
notify
=
notify
;
}
public
void
SetThiefCatch
(
boolean
thiefCatch
){
this
.
thiefCatch
=
thiefCatch
;
}
public
boolean
getThiefCatch
(){
return
thiefCatch
;
}
}
}
src/Thief.java
View file @
f23ef9a7
import
java.util.Random
;
import
java.util.Random
;
public
class
Thief
{
public
class
Thief
{
Land
thiefLand
;
private
Land
thiefLand
;
Random
rand
=
new
Random
();
private
int
firstx
=
rand
.
nextInt
(
thiefLand
.
getLength
());
private
int
x
;
private
int
firsty
=
rand
.
nextInt
(
thiefLand
.
getLength
());
private
int
y
;
private
int
x
=
firstx
;
private
int
y
=
firsty
;
public
int
getX
(){
public
int
getX
(){
...
@@ -19,4 +17,29 @@ public class Thief {
...
@@ -19,4 +17,29 @@ public class Thief {
public
void
setLand
(
Land
myLand
)
{
public
void
setLand
(
Land
myLand
)
{
thiefLand
=
myLand
;
thiefLand
=
myLand
;
}
}
public
void
setFirstxy
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
// this.x = rand.nextInt(thiefLand.getLength());
// y = rand.nextInt(thiefLand.getLength());
}
public
void
move
()
{
Move
move1
=
new
Move
(
x
,
y
,
thiefLand
);
move1
.
moveXY
();
this
.
x
=
move1
.
getX
();
this
.
y
=
move1
.
getY
();
}
public
void
smartMove
(
int
w
,
int
z
)
{
// this.w = x;
// this.z = z;
Move
move1
=
new
Move
(
w
,
z
,
x
,
y
,
thiefLand
);
move1
.
smartMove
();
this
.
x
=
move1
.
getW
();
this
.
y
=
move1
.
getZ
();
}
}
}
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