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
8e1b2215
Commit
8e1b2215
authored
Apr 19, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish
parent
218b9ba1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
33 deletions
+19
-33
Main.java
src/pack/Main.java
+7
-2
PlayGround.java
src/pack/PlayGround.java
+8
-2
Police.java
src/pack/Police.java
+3
-3
Thief.java
src/pack/Thief.java
+1
-26
No files found.
src/pack/Main.java
View file @
8e1b2215
...
...
@@ -71,12 +71,17 @@ public class Main {
if
(
playGround
.
getCatchThief
())
{
break
;
}
else
playGround
.
show
(
1200
);
System
.
out
.
print
(
"\n\n\n\n"
);
System
.
out
.
print
(
"\f\n\n\n\n"
);
/*
FIRST MOVE : POLICE
/*
thiefSituation = playGround.canPoliceSeeThief();
thiefSituation = playGround.canPoliceSeeThief();
if (thiefSituation == null) {
...
...
src/pack/PlayGround.java
View file @
8e1b2215
...
...
@@ -29,8 +29,10 @@ public class PlayGround {
System
.
out
.
print
(
"-"
);
else
if
(
ground
[
i
][
j
]
==
1
)
// police
System
.
out
.
print
(
"X"
);
else
// Dozd
else
if
(
ground
[
i
][
j
]
==
-
1
)
// Dozd
System
.
out
.
print
(
"*"
);
else
System
.
out
.
print
(
"O"
);
}
System
.
out
.
println
();
}
...
...
@@ -75,7 +77,11 @@ public class PlayGround {
}
public
void
changeSituation
(
int
xPrevious
,
int
yPrevious
,
int
xNew
,
int
yNew
,
int
k
)
{
if
(
xNew
==
thiefSituation
[
0
][
0
]
&&
yNew
==
thiefSituation
[
0
][
1
]
&&
k
==
1
)
return
;
if
(
xNew
==
thiefSituation
[
0
][
0
]
&&
yNew
==
thiefSituation
[
0
][
1
]
&&
k
==
1
)
{
ground
[
xPrevious
][
yPrevious
]
=
0
;
ground
[
xNew
][
yNew
]
=
100
;
return
;
}
ground
[
xPrevious
][
yPrevious
]
=
0
;
ground
[
xNew
][
yNew
]
=
k
;
if
(
k
==
-
1
)
{
...
...
src/pack/Police.java
View file @
8e1b2215
...
...
@@ -219,7 +219,7 @@ public class Police {
return
newSituation
;
}
case
1
:
if
(
x
!=
p
.
getNM
()[
0
][
0
]
&&
p
.
isEmpty
(
x
+
1
,
y
-
1
))
{
// go down, left
if
(
x
!=
p
.
getNM
()[
0
][
0
]
-
1
&&
p
.
isEmpty
(
x
+
1
,
y
-
1
))
{
// go down, left
newSituation
[
0
][
0
]
=
x
+
1
;
newSituation
[
0
][
1
]
=
y
-
1
;
return
newSituation
;
...
...
@@ -238,7 +238,7 @@ public class Police {
}
else
{
switch
(
r
.
nextInt
(
2
))
{
case
0
:
if
(
x
!=
p
.
getNM
()[
0
][
0
]
&&
p
.
isEmpty
(
x
+
1
,
y
+
1
))
{
// go down, right
if
(
x
!=
p
.
getNM
()[
0
][
0
]
-
1
&&
p
.
isEmpty
(
x
+
1
,
y
+
1
))
{
// go down, right
newSituation
[
0
][
0
]
=
x
+
1
;
newSituation
[
0
][
1
]
=
y
+
1
;
return
newSituation
;
...
...
@@ -294,7 +294,7 @@ public class Police {
return
newSituation
;
}
case
1
:
if
(
y
!=
p
.
getNM
()[
0
][
1
]
&&
p
.
isEmpty
(
x
+
1
,
y
+
1
))
{
// go down, right
if
(
y
!=
p
.
getNM
()[
0
][
1
]
-
1
&&
p
.
isEmpty
(
x
+
1
,
y
+
1
))
{
// go down, right
newSituation
[
0
][
0
]
=
x
+
1
;
newSituation
[
0
][
1
]
=
y
+
1
;
return
newSituation
;
...
...
src/pack/Thief.java
View file @
8e1b2215
...
...
@@ -170,21 +170,7 @@ public class Thief {
private
int
[][]
almostRandomMove
(
boolean
[]
is
,
PlayGround
p
)
{
int
[][]
destination
=
new
int
[
1
][
2
];
boolean
[]
isPoliceThere0
=
is
,
isPoliceThere
=
new
boolean
[
8
];
for
(
int
i
=
0
;
i
<
8
;
i
++)
isPoliceThere0
[
i
]
=
false
;
System
.
out
.
println
(
"before:"
);
for
(
int
i
=
0
;
i
<
3
;
i
++)
System
.
out
.
print
(
isPoliceThere0
[
i
]+
" "
);
System
.
out
.
println
();
for
(
int
i
=
3
;
i
<
5
;
i
++)
System
.
out
.
print
(
isPoliceThere0
[
i
]+
" "
);
System
.
out
.
println
();
for
(
int
i
=
5
;
i
<
8
;
i
++)
System
.
out
.
print
(
isPoliceThere0
[
i
]+
" "
);
System
.
out
.
println
(
"\n\n"
);
boolean
[]
isPoliceThere0
=
is
,
isPoliceThere
=
is
;
if
(
isPoliceThere0
[
0
])
{
...
...
@@ -228,17 +214,6 @@ System.out.println("before:");
isPoliceThere
[
6
]
=
true
;
}
for
(
int
i
=
0
;
i
<
3
;
i
++)
System
.
out
.
print
(
isPoliceThere
[
i
]+
" "
);
System
.
out
.
println
();
for
(
int
i
=
3
;
i
<
5
;
i
++)
System
.
out
.
print
(
isPoliceThere
[
i
]+
" "
);
System
.
out
.
println
();
for
(
int
i
=
5
;
i
<
8
;
i
++)
System
.
out
.
print
(
isPoliceThere
[
i
]+
" "
);
System
.
out
.
println
();
if
(!
isPoliceThere
[
0
]
||
!
isPoliceThere
[
1
]
||
!
isPoliceThere
[
2
]
||
!
isPoliceThere
[
3
]
||
!
isPoliceThere
[
4
]
||
!
isPoliceThere
[
5
]
||
!
isPoliceThere
[
6
]
||
!
isPoliceThere
[
7
])
{
Random
r
=
new
Random
();
...
...
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