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
cd25f5fa
Commit
cd25f5fa
authored
Apr 19, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thief -> almostRandom updated
parent
56fe8bff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
17 deletions
+63
-17
Thief.java
src/pack/Thief.java
+63
-17
No files found.
src/pack/Thief.java
View file @
cd25f5fa
...
...
@@ -4,12 +4,10 @@ import java.util.Random;
public
class
Thief
{
private
int
x
,
y
;
private
boolean
see
;
Thief
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
see
=
false
;
}
public
void
randomMove
(
int
n
,
int
m
,
PlayGround
playGround
)
{
...
...
@@ -126,7 +124,7 @@ public class Thief {
}
for
(
isPoliceThere
[
2
]
=
false
,
q
=
i
;
q
<
x
;
q
++)
// up, right
for
(
w
=
j
+
1
;
w
<
J
;
w
++)
for
(
w
=
y
+
1
;
w
<
J
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
2
]
=
true
;
}
...
...
@@ -161,31 +159,67 @@ public class Thief {
isPoliceThere
[
7
]
=
true
;
}
int
[][]
newSituation
=
almostRandomMove
(
isPoliceThere
);
int
[][]
newSituation
=
almostRandomMove
(
isPoliceThere
,
playGround
);
playGround
.
changeSituation
(
x
,
y
,
newSituation
[
0
][
0
],
newSituation
[
0
][
1
],
-
1
);
x
=
newSituation
[
0
][
0
];
y
=
newSituation
[
0
][
1
];
if
(
newSituation
!=
null
)
{
playGround
.
changeSituation
(
x
,
y
,
newSituation
[
0
][
0
],
newSituation
[
0
][
1
],
-
1
);
x
=
newSituation
[
0
][
0
];
y
=
newSituation
[
0
][
1
];
}
}
private
int
[][]
almostRandomMove
(
boolean
[]
is
PoliceThere
)
{
private
int
[][]
almostRandomMove
(
boolean
[]
is
,
PlayGround
p
)
{
int
[][]
destination
=
new
int
[
1
][
2
];
boolean
[]
isPoliceThere
=
is
;
if
(
isPoliceThere
[
0
]
&&
isPoliceThere
[
2
])
isPoliceThere
[
1
]
=
true
;
if
(
isPoliceThere
[
0
]
&&
isPoliceThere
[
5
])
isPoliceThere
[
3
]
=
true
;
if
(
isPoliceThere
[
7
]
&&
isPoliceThere
[
2
])
isPoliceThere
[
4
]
=
true
;
if
(
isPoliceThere
[
5
]
&&
isPoliceThere
[
7
])
isPoliceThere
[
6
]
=
true
;
if
(
isPoliceThere
[
1
]
&&
isPoliceThere
[
3
])
isPoliceThere
[
0
]
=
true
;
if
(
isPoliceThere
[
1
]
&&
isPoliceThere
[
4
])
isPoliceThere
[
2
]
=
true
;
if
(
isPoliceThere
[
6
]
&&
isPoliceThere
[
3
])
isPoliceThere
[
5
]
=
true
;
if
(
isPoliceThere
[
4
]
&&
isPoliceThere
[
6
])
isPoliceThere
[
7
]
=
true
;
if
(
isPoliceThere
[
0
])
{
isPoliceThere
[
1
]
=
true
;
isPoliceThere
[
3
]
=
true
;
}
if
(
isPoliceThere
[
1
])
{
isPoliceThere
[
0
]
=
true
;
isPoliceThere
[
2
]
=
true
;
isPoliceThere
[
3
]
=
true
;
isPoliceThere
[
4
]
=
true
;
}
if
(
isPoliceThere
[
2
])
{
isPoliceThere
[
1
]
=
true
;
isPoliceThere
[
4
]
=
true
;
}
if
(
isPoliceThere
[
3
])
{
isPoliceThere
[
1
]
=
true
;
isPoliceThere
[
0
]
=
true
;
isPoliceThere
[
5
]
=
true
;
isPoliceThere
[
6
]
=
true
;
}
if
(
isPoliceThere
[
4
])
{
isPoliceThere
[
1
]
=
true
;
isPoliceThere
[
2
]
=
true
;
isPoliceThere
[
6
]
=
true
;
isPoliceThere
[
7
]
=
true
;
}
if
(
isPoliceThere
[
5
])
{
isPoliceThere
[
6
]
=
true
;
isPoliceThere
[
3
]
=
true
;
}
if
(
isPoliceThere
[
6
])
{
isPoliceThere
[
4
]
=
true
;
isPoliceThere
[
3
]
=
true
;
isPoliceThere
[
5
]
=
true
;
isPoliceThere
[
7
]
=
true
;
}
if
(
isPoliceThere
[
7
])
{
isPoliceThere
[
4
]
=
true
;
isPoliceThere
[
6
]
=
true
;
}
if
(!
isPoliceThere
[
0
]
||
!
isPoliceThere
[
1
]
||
!
isPoliceThere
[
2
]
||
!
isPoliceThere
[
3
]
||
!
isPoliceThere
[
4
]
||
!
isPoliceThere
[
5
]
||
!
isPoliceThere
[
6
]
||
!
isPoliceThere
[
7
])
{
Random
r
=
new
Random
();
int
i
=
0
;
do
{
switch
(
r
.
nextInt
(
8
))
{
case
0
:
if
(
x
==
0
||
y
==
0
)
break
;
if
(!
isPoliceThere
[
0
])
{
destination
[
0
][
0
]
=
x
-
1
;
destination
[
0
][
1
]
=
y
-
1
;
...
...
@@ -194,6 +228,7 @@ public class Thief {
break
;
case
1
:
if
(
x
==
0
)
break
;
if
(!
isPoliceThere
[
1
])
{
destination
[
0
][
0
]
=
x
-
1
;
destination
[
0
][
1
]
=
y
;
...
...
@@ -202,6 +237,7 @@ public class Thief {
break
;
case
2
:
if
(
x
==
0
||
y
==
p
.
getNM
()[
0
][
1
]
-
1
)
break
;
if
(!
isPoliceThere
[
2
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
-
1
;
...
...
@@ -210,6 +246,7 @@ public class Thief {
break
;
case
3
:
if
(
y
==
0
)
break
;
if
(!
isPoliceThere
[
3
])
{
destination
[
0
][
0
]
=
x
;
destination
[
0
][
1
]
=
y
-
1
;
...
...
@@ -218,6 +255,7 @@ public class Thief {
break
;
case
4
:
if
(
y
==
p
.
getNM
()[
0
][
1
]
-
1
)
break
;
if
(!
isPoliceThere
[
4
])
{
destination
[
0
][
0
]
=
x
;
destination
[
0
][
1
]
=
y
+
1
;
...
...
@@ -226,6 +264,7 @@ public class Thief {
break
;
case
5
:
if
(
y
==
0
||
x
==
p
.
getNM
()[
0
][
0
]
-
1
)
break
;
if
(!
isPoliceThere
[
5
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
-
1
;
...
...
@@ -234,6 +273,7 @@ public class Thief {
break
;
case
6
:
if
(
x
==
p
.
getNM
()[
0
][
0
]
-
1
)
break
;
if
(!
isPoliceThere
[
6
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
;
...
...
@@ -242,12 +282,18 @@ public class Thief {
break
;
case
7
:
if
(
x
==
p
.
getNM
()[
0
][
0
]
-
1
||
y
==
p
.
getNM
()[
0
][
1
]
-
1
)
break
;
if
(!
isPoliceThere
[
7
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
+
1
;
return
destination
;
}
}
i
++;
if
(
i
>
50
)
{
randomMove
(
p
.
getNM
()[
0
][
0
],
p
.
getNM
()[
0
][
1
],
p
);
return
null
;
}
}
while
(
true
);
}
else
{
destination
[
0
][
0
]
=
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