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
Hide 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
{
private
int
length
;
private
int
width
;
private
int
[][]
landMatrix
=
new
int
[
length
][
width
];
private
char
[][]
landMatrix
;
public
Land
(
int
length
,
int
width
)
{
this
.
length
=
length
;
this
.
width
=
width
;
landMatrix
=
new
char
[
length
][
width
];
}
public
int
getLength
()
{
...
...
@@ -16,8 +18,14 @@ public class Land {
return
width
;
}
public
int
[][]
getLandMatrix
()
{
return
landMatrix
;
public
void
setLandMatrix
(
int
x
,
int
y
,
char
c
){
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 {
Scanner
scanner
=
new
Scanner
(
System
.
in
);
int
length
=
scanner
.
nextInt
();
int
width
=
scanner
.
nextInt
();
int
arrestX
=
56
;
int
arrestY
=
56
;
int
arrestX
=
0
;
int
arrestY
=
0
;
int
policeMovment
=
0
;
int
thiefMovement
=
0
;
Land
myLand
=
new
Land
(
length
,
width
);
Random
rand
=
new
Random
();
int
policeNumbers
=
scanner
.
nextInt
();
...
...
@@ -78,8 +80,10 @@ public class Main {
thief
.
move
();
thiefMovement
++;
for
(
Police
police
:
polices
)
{
police
.
move
();
policeMovment
++;
}
...
...
@@ -127,8 +131,10 @@ System.out.println(
thief
.
smartMove
(
polices
.
get
(
0
).
getX
(),
polices
.
get
(
0
).
getY
());
thiefMovement
++;
for
(
Police
police
:
polices
)
{
police
.
smartMove
(
thief
.
getX
(),
thief
.
getY
());
policeMovment
++;
}
...
...
@@ -162,6 +168,10 @@ 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
{
Random
rand
=
new
Random
();
Land
policeLand
;
private
Land
policeLand
;
private
int
x
;
private
int
y
;
public
void
setFirstxy
()
{
x
=
rand
.
nextInt
(
policeLand
.
getLength
());
y
=
rand
.
nextInt
(
policeLand
.
getLength
());
private
boolean
notify
=
false
;
private
boolean
thiefCatch
=
false
;
public
void
setFirstxy
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
}
public
void
move
()
{
int
a
=
rand
.
nextInt
(
8
);
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
:
//North west
if
(
y
>
0
)
{
if
(
x
>
0
)
{
y
+=
1
;
x
-=
1
;
}
}
case
6
:
//Southeast
if
(
y
+
1
<
policeLand
.
getWidth
())
{
if
(
x
+
1
<=
policeLand
.
getLength
())
{
y
+=
1
;
x
+=
1
;
break
;
}
}
case
7
:
//Southwest
if
(
y
+
1
<
policeLand
.
getWidth
())
{
if
(
x
>
0
)
{
y
+=
1
;
x
-=
1
;
break
;
}
}
}
Move
move1
=
new
Move
(
x
,
y
,
policeLand
);
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
(
x
,
y
,
w
,
z
,
policeLand
);
move1
.
smartMove
();
this
.
x
=
move1
.
getX
();
this
.
y
=
move1
.
getY
();
}
public
void
setLand
(
Land
myLand
)
{
policeLand
=
myLand
;
}
...
...
@@ -97,4 +45,19 @@ public class Police {
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
;
public
class
Thief
{
Land
thiefLand
;
Random
rand
=
new
Random
();
private
int
firstx
=
rand
.
nextInt
(
thiefLand
.
getLength
());
private
int
firsty
=
rand
.
nextInt
(
thiefLand
.
getLength
());
private
int
x
=
firstx
;
private
int
y
=
firsty
;
private
Land
thiefLand
;
private
int
x
;
private
int
y
;
public
int
getX
(){
...
...
@@ -19,4 +17,29 @@ public class Thief {
public
void
setLand
(
Land
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