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
36a1ea07
Commit
36a1ea07
authored
Apr 19, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main updated
parent
64e04cc8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
37 deletions
+18
-37
Main.java
src/pack/Main.java
+8
-7
PlayGround.java
src/pack/PlayGround.java
+10
-30
No files found.
src/pack/Main.java
View file @
36a1ea07
...
...
@@ -19,12 +19,12 @@ public class Main {
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
]);
int
i
;
for
(
i
=
0
;
i
<
pn
;
i
++)
polices
[
i
]
=
new
Police
(
positions
[
i
][
0
],
positions
[
i
][
1
]);
//--------------------------------------------------------------------------------
int
i
,
I
=
1
;
int
[][]
thiefSituation
=
new
int
[
1
][
2
];
int
c
=
0
;
...
...
@@ -35,12 +35,13 @@ public class Main {
System
.
out
.
println
(
"c ============== "
+
c
);
playGround
.
show
(
5000
);
playGround
.
show
(
120
);
System
.
out
.
print
(
"\n\n\n\n"
);
do
{
thiefSituation
=
playGround
.
canPoliceSeeThief
();
if
(
thiefSituation
==
null
)
{
System
.
out
.
println
(
"randomMove"
);
for
(
i
=
0
;
i
<
pn
;
i
++)
polices
[
i
].
randomMove
(
n
,
m
,
playGround
);
}
else
{
...
...
@@ -49,8 +50,8 @@ public class Main {
if
(
playGround
.
getCatchThief
())
break
;
}
}
playGround
.
show
(
1250
);
if
(
playGround
.
getCatchThief
())
System
.
out
.
println
(
"they catch him!"
);
if
(
playGround
.
getCatchThief
())
{
System
.
out
.
println
(
"they catch him!"
);
break
;}
else
playGround
.
show
(
120
);
System
.
out
.
print
(
"\n\n\n\n"
);
}
while
(!
playGround
.
catchThief
());
...
...
src/pack/PlayGround.java
View file @
36a1ea07
...
...
@@ -5,6 +5,7 @@ import java.util.Random;
public
class
PlayGround
{
private
int
[][]
ground
,
thiefSituation
;
private
int
n
,
m
,
policeNumbers
;
private
boolean
catchThief
;
PlayGround
(
int
n
,
int
m
,
int
policeNumbers
)
{
this
.
n
=
n
;
...
...
@@ -16,6 +17,7 @@ public class PlayGround {
for
(
i
=
0
;
i
<
n
;
i
++)
for
(
j
=
0
;
j
<
m
;
j
++)
ground
[
i
][
j
]
=
0
;
catchThief
=
false
;
}
public
void
show
(
int
time
)
{
...
...
@@ -49,7 +51,6 @@ public class PlayGround {
for
(
k
=
0
;
k
<
policeNumbers
;
k
++)
{
// police
i
=
rand
.
nextInt
(
n
);
j
=
rand
.
nextInt
(
m
);
System
.
out
.
println
(
"i = "
+
i
+
" j = "
+
j
);
///////////////////////////////////////////////////////////////// TODO clean
if
(
ground
[
i
][
j
]
==
0
)
{
ground
[
i
][
j
]
=
1
;
positions
[
k
][
0
]
=
i
;
// x
...
...
@@ -60,7 +61,6 @@ public class PlayGround {
for
(
k
=
0
;
k
<
1
;
k
++)
{
// thief
i
=
rand
.
nextInt
(
n
);
j
=
rand
.
nextInt
(
m
);
System
.
out
.
println
(
"i = "
+
i
+
" j = "
+
j
);
///////////////////////////////////////////////////////////////// TODO clean
if
(
ground
[
i
][
j
]
==
0
)
{
ground
[
i
][
j
]
=
-
1
;
positions
[
policeNumbers
][
0
]
=
i
;
// x
...
...
@@ -87,36 +87,10 @@ public class PlayGround {
}
public
void
changeSituation
(
int
xPrevious
,
int
yPrevious
,
int
xNew
,
int
yNew
,
int
k
)
{
if
((
xPrevious
!=
xNew
||
yPrevious
!=
yNew
)
&&
ground
[
xNew
][
yNew
]
==
1
)
System
.
out
.
println
(
"RIIIIIIIIIIIIIIIIIIIIIIIIIIIDI"
);
if
(
ground
[
xPrevious
][
yPrevious
]
==
0
)
System
.
out
.
println
(
"RIIIIIIIIIIIIIIIIIIIIIIIIIIIDI 2"
);
int
c
=
0
;
for
(
int
j
,
z
=
0
;
z
<
n
;
z
++)
for
(
j
=
0
;
j
<
m
;
j
++)
if
(
ground
[
z
][
j
]
==
1
)
c
++;
System
.
out
.
println
(
"c1 ===== "
+
c
);
if
(
xNew
==
thiefSituation
[
0
][
0
]
&&
yNew
==
thiefSituation
[
0
][
1
])
return
;
ground
[
xPrevious
][
yPrevious
]
=
0
;
c
=
0
;
for
(
int
j
,
z
=
0
;
z
<
n
;
z
++)
for
(
j
=
0
;
j
<
m
;
j
++)
if
(
ground
[
z
][
j
]
==
1
)
c
++;
System
.
out
.
println
(
"c2 ===== "
+
c
+
" k == "
+
k
);
ground
[
xNew
][
yNew
]
=
k
;
c
=
0
;
for
(
int
j
,
z
=
0
;
z
<
n
;
z
++)
for
(
j
=
0
;
j
<
m
;
j
++)
if
(
ground
[
z
][
j
]
==
1
)
c
++;
System
.
out
.
println
(
"c3 ===== "
+
c
);
}
public
int
[][]
getGround
()
{
...
...
@@ -157,6 +131,10 @@ public class PlayGround {
}
public
boolean
isEmpty
(
int
x
,
int
y
)
{
if
(
ground
[
x
][
y
]
==
-
1
)
{
catchThief
=
true
;
return
true
;
}
return
ground
[
x
][
y
]
==
0
;
}
...
...
@@ -174,5 +152,7 @@ public class PlayGround {
return
ret
;
}
public
boolean
getCatchThief
()
{
return
catchThief
;
}
}
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