Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
police and thief
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
9731075
police and thief
Commits
684aca4e
Commit
684aca4e
authored
Apr 15, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Police -> move | int[][] added!
parent
6ef69b22
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
198 additions
and
16 deletions
+198
-16
Police.java
src/Police.java
+0
-14
Main.java
src/mma/Main.java
+53
-0
PlayGround.java
src/mma/PlayGround.java
+41
-1
Police.java
src/mma/Police.java
+103
-0
Thief.java
src/mma/Thief.java
+1
-1
No files found.
src/Police.java
deleted
100644 → 0
View file @
6ef69b22
public
class
Police
{
private
int
x
,
y
;
private
static
boolean
see
;
Police
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
see
=
false
;
}
}
src/mma/Main.java
0 → 100644
View file @
684aca4e
package
mma
;
//package src;
import
mma.PlayGround
;
import
mma.Police
;
import
mma.Thief
;
import
java.util.Scanner
;
public
class
Main
{
public
static
void
main
(
String
args
[])
{
Scanner
input
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Enter n: "
);
int
n
=
input
.
nextInt
();
System
.
out
.
print
(
"Enter m: "
);
int
m
=
input
.
nextInt
();
System
.
out
.
print
(
"Enter police numbers: "
);
int
pn
=
input
.
nextInt
();
PlayGround
playGround
=
new
PlayGround
(
n
,
m
,
pn
);
int
[][]
positions
=
playGround
.
putRandom
();
Thief
thief
=
new
Thief
(
positions
[
pn
][
0
],
positions
[
pn
][
1
]);
Police
[]
polices
=
new
Police
[
pn
];
for
(
n
=
0
;
n
<
pn
;
n
++)
polices
[
n
]
=
new
Police
(
positions
[
n
][
0
],
positions
[
n
][
1
]);
//--------------------------------------------------------------------------------
do
{
playGround
.
policeSeeThief
();
}
while
(!
playGround
.
catchThief
());
}
}
src/PlayGround.java
→
src/
mma/
PlayGround.java
View file @
684aca4e
package
mma
;
import
java.util.Random
;
public
class
PlayGround
{
private
int
[][]
ground
;
private
int
[][]
ground
,
thiefsituation
;
int
n
,
m
,
policeNumbers
;
PlayGround
(
int
n
,
int
m
,
int
policeNumbers
)
{
...
...
@@ -9,6 +11,7 @@ public class PlayGround {
this
.
m
=
m
;
this
.
policeNumbers
=
policeNumbers
;
ground
=
new
int
[
n
][
m
];
thiefsituation
=
new
int
[
1
][
1
];
int
i
,
j
;
for
(
i
=
0
;
i
<
n
;
i
++)
for
(
j
=
0
;
j
<
m
;
j
++)
...
...
@@ -53,6 +56,8 @@ public class PlayGround {
ground
[
i
][
j
]
=
1
;
positions
[
policeNumbers
][
0
]
=
i
;
// x
positions
[
policeNumbers
][
1
]
=
j
;
// y
thiefsituation
[
0
][
0
]
=
i
;
// x
thiefsituation
[
0
][
1
]
=
j
;
// y
}
}
}
...
...
@@ -72,5 +77,40 @@ public class PlayGround {
ground
[
xThief
][
yThief
]
=
-
1
;
}
public
int
[][]
getGround
()
{
return
ground
;
}
public
boolean
policeSeeThief
()
{
int
i
,
j
,
I
,
J
;
if
(
thiefsituation
[
0
][
0
]
>
1
)
i
=
thiefsituation
[
0
][
0
]
-
2
;
else
i
=
0
;
if
(
thiefsituation
[
0
][
0
]
<
n
-
2
)
I
=
thiefsituation
[
0
][
0
]
+
3
;
else
I
=
n
;
if
(
thiefsituation
[
0
][
1
]
>
1
)
j
=
thiefsituation
[
0
][
1
]
-
2
;
else
j
=
0
;
if
(
thiefsituation
[
0
][
1
]
<
m
-
2
)
J
=
thiefsituation
[
0
][
1
]
+
3
;
else
J
=
m
;
for
(;
i
<
I
;
i
++)
for
(;
j
<
J
;
j
++)
if
(
ground
[
i
][
j
]
==
-
1
)
return
true
;
return
false
;
}
public
boolean
catchThief
()
{
int
i
,
j
;
for
(
i
=
0
;
i
<
n
;
i
++)
for
(
j
=
0
;
j
<
m
;
j
++)
if
(
ground
[
i
][
j
]
==
100
)
return
true
;
return
false
;
}
}
src/mma/Police.java
0 → 100644
View file @
684aca4e
package
mma
;
import
java.util.Random
;
public
class
Police
{
private
int
x
,
y
;
private
static
boolean
see
;
Police
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
see
=
false
;
}
public
int
[][]
move
(
int
n
,
int
m
)
{
boolean
i
,
j
,
I
,
J
;
i
=
j
=
I
=
J
=
false
;
if
(
x
!=
0
)
i
=
true
;
if
(
x
!=
n
-
1
)
I
=
true
;
if
(
y
!=
0
)
j
=
true
;
if
(
y
!=
m
-
1
)
J
=
true
;
Random
random
=
new
Random
();
int
[][]
Return
=
new
int
[
1
][
1
];
while
(
true
)
{
switch
(
random
.
nextInt
()
%
8
)
{
case
0
:
if
(
i
==
true
&&
j
==
true
)
{
Return
[
0
][
0
]
=
x
-
1
;
// x
Return
[
0
][
1
]
=
y
-
1
;
// y
return
Return
;
}
break
;
case
1
:
if
(
i
==
true
)
{
Return
[
0
][
0
]
=
x
-
1
;
// x
Return
[
0
][
1
]
=
y
;
// y
return
Return
;
}
break
;
case
2
:
if
(
i
==
true
&&
J
==
true
)
{
Return
[
0
][
0
]
=
x
+
1
;
// x
Return
[
0
][
1
]
=
y
-
1
;
// y
return
Return
;
}
break
;
case
3
:
if
(
i
==
true
)
{
Return
[
0
][
0
]
=
x
;
// x
Return
[
0
][
1
]
=
y
-
1
;
// y
return
Return
;
}
break
;
case
4
:
if
(
J
==
true
)
{
Return
[
0
][
0
]
=
x
;
// x
Return
[
0
][
1
]
=
y
+
1
;
// y
return
Return
;
}
break
;
case
5
:
if
(
i
==
true
&&
J
==
true
)
{
Return
[
0
][
0
]
=
x
+
1
;
// x
Return
[
0
][
1
]
=
y
-
1
;
// y
return
Return
;
}
break
;
case
6
:
if
(
J
==
true
)
{
Return
[
0
][
0
]
=
x
+
1
;
// x
Return
[
0
][
1
]
=
y
;
// y
return
Return
;
}
break
;
case
7
:
if
(
I
==
true
&&
J
==
true
)
{
Return
[
0
][
0
]
=
x
+
1
;
// x
Return
[
0
][
1
]
=
y
+
1
;
// y
return
Return
;
}
}
}
}
public
int
[][]
getSituation
()
{
int
[][]
Return
=
new
int
[
1
][
1
];
Return
[
0
][
0
]
=
x
;
Return
[
0
][
1
]
=
y
;
return
Return
;
}
}
\ No newline at end of file
src/Thief.java
→
src/
mma/
Thief.java
View file @
684aca4e
public
class
Thief
{
private
int
x
,
y
;
private
static
boolean
see
;
private
boolean
see
;
Thief
(
int
x
,
int
y
)
{
this
.
x
=
x
;
...
...
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