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
89fb11cc
Commit
89fb11cc
authored
Apr 19, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thief -> randomMove added
parent
7d2a06ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
247 additions
and
0 deletions
+247
-0
Thief.java
src/pack/Thief.java
+247
-0
No files found.
src/pack/Thief.java
View file @
89fb11cc
package
pack
;
package
pack
;
import
java.util.Random
;
public
class
Thief
{
public
class
Thief
{
private
int
x
,
y
;
private
int
x
,
y
;
private
boolean
see
;
private
boolean
see
;
...
@@ -10,5 +12,250 @@ public class Thief {
...
@@ -10,5 +12,250 @@ public class Thief {
see
=
false
;
see
=
false
;
}
}
public
void
randomMove
(
int
n
,
int
m
,
PlayGround
playGround
)
{
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
();
boolean
confirm
=
false
;
int
X
=
0
,
Y
=
0
;
do
{
switch
(
random
.
nextInt
(
8
))
{
case
0
:
if
(
i
&&
j
)
{
X
=
x
-
1
;
Y
=
y
-
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
1
:
if
(
i
)
{
X
=
x
-
1
;
Y
=
y
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
2
:
if
(
i
&&
J
)
{
X
=
x
-
1
;
Y
=
y
+
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
3
:
if
(
j
)
{
X
=
x
;
Y
=
y
-
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
4
:
if
(
J
)
{
X
=
x
;
Y
=
y
+
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
5
:
if
(
j
&&
I
)
{
X
=
x
+
1
;
Y
=
y
-
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
6
:
if
(
I
)
{
X
=
x
+
1
;
Y
=
y
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
break
;
case
7
:
if
(
I
&&
J
)
{
X
=
x
+
1
;
Y
=
y
+
1
;
confirm
=
playGround
.
isEmpty
(
X
,
Y
);
}
}
}
while
(!
confirm
);
playGround
.
changeSituation
(
x
,
y
,
X
,
Y
,
-
1
);
x
=
X
;
y
=
Y
;
}
public
void
targetedMove
(
PlayGround
playGround
)
{
boolean
[]
isPoliceThere
=
new
boolean
[
8
];
int
i
,
j
,
I
,
J
;
if
(
x
>
1
)
i
=
x
-
2
;
else
i
=
0
;
if
(
x
<
playGround
.
getNM
()[
0
][
0
]
-
2
)
I
=
x
+
3
;
else
I
=
playGround
.
getNM
()[
0
][
0
];
if
(
y
>
1
)
j
=
y
-
2
;
else
j
=
0
;
if
(
y
<
playGround
.
getNM
()[
0
][
1
]
-
2
)
J
=
y
+
3
;
else
J
=
playGround
.
getNM
()[
0
][
1
];
int
q
,
w
;
for
(
isPoliceThere
[
0
]
=
false
,
q
=
i
;
q
<
x
;
q
++)
// up, left
for
(
w
=
j
;
w
<
y
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
0
]
=
true
;
}
for
(
isPoliceThere
[
1
]
=
false
,
q
=
i
;
q
<
x
;
q
++)
// up
for
(
w
=
y
;
w
<
y
+
1
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
1
]
=
true
;
}
for
(
isPoliceThere
[
2
]
=
false
,
q
=
i
;
q
<
x
;
q
++)
// up, right
for
(
w
=
j
+
1
;
w
<
J
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
2
]
=
true
;
}
for
(
isPoliceThere
[
3
]
=
false
,
q
=
x
;
q
<
x
+
1
;
q
++)
// left
for
(
w
=
j
;
w
<
y
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
3
]
=
true
;
}
for
(
isPoliceThere
[
4
]
=
false
,
q
=
x
;
q
<
x
+
1
;
q
++)
// right
for
(
w
=
y
+
1
;
w
<
J
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
4
]
=
true
;
}
for
(
isPoliceThere
[
5
]
=
false
,
q
=
x
+
1
;
q
<
I
;
q
++)
// down, left
for
(
w
=
j
;
w
<
y
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
5
]
=
true
;
}
for
(
isPoliceThere
[
6
]
=
false
,
q
=
x
+
1
;
q
<
I
;
q
++)
// down
for
(
w
=
y
;
w
<
y
+
1
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
6
]
=
true
;
}
for
(
isPoliceThere
[
7
]
=
false
,
q
=
x
+
1
;
q
<
I
;
q
++)
// down, right
for
(
w
=
y
+
1
;
w
<
J
;
w
++)
if
(
playGround
.
getGround
()[
q
][
w
]
==
1
)
{
isPoliceThere
[
7
]
=
true
;
}
int
[][]
newSituation
=
almostRandomMove
(
isPoliceThere
);
playGround
.
changeSituation
(
x
,
y
,
newSituation
[
0
][
0
],
newSituation
[
0
][
1
],
-
1
);
x
=
newSituation
[
0
][
0
];
y
=
newSituation
[
0
][
1
];
}
private
int
[][]
almostRandomMove
(
boolean
[]
isPoliceThere
)
{
int
[][]
destination
=
new
int
[
1
][
2
];
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
]
||
!
isPoliceThere
[
2
]
||
!
isPoliceThere
[
3
]
||
!
isPoliceThere
[
4
]
||
!
isPoliceThere
[
5
]
||
!
isPoliceThere
[
6
]
||
!
isPoliceThere
[
7
])
{
Random
r
=
new
Random
();
do
{
switch
(
r
.
nextInt
(
8
))
{
case
0
:
if
(!
isPoliceThere
[
0
])
{
destination
[
0
][
0
]
=
x
-
1
;
destination
[
0
][
1
]
=
y
-
1
;
return
destination
;
}
break
;
case
1
:
if
(!
isPoliceThere
[
1
])
{
destination
[
0
][
0
]
=
x
-
1
;
destination
[
0
][
1
]
=
y
;
return
destination
;
}
break
;
case
2
:
if
(!
isPoliceThere
[
2
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
-
1
;
return
destination
;
}
break
;
case
3
:
if
(!
isPoliceThere
[
3
])
{
destination
[
0
][
0
]
=
x
;
destination
[
0
][
1
]
=
y
-
1
;
return
destination
;
}
break
;
case
4
:
if
(!
isPoliceThere
[
4
])
{
destination
[
0
][
0
]
=
x
;
destination
[
0
][
1
]
=
y
+
1
;
return
destination
;
}
break
;
case
5
:
if
(!
isPoliceThere
[
5
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
-
1
;
return
destination
;
}
break
;
case
6
:
if
(!
isPoliceThere
[
6
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
;
return
destination
;
}
break
;
case
7
:
if
(!
isPoliceThere
[
7
])
{
destination
[
0
][
0
]
=
x
+
1
;
destination
[
0
][
1
]
=
y
+
1
;
return
destination
;
}
}
}
while
(
true
);
}
else
{
destination
[
0
][
0
]
=
x
;
destination
[
0
][
1
]
=
y
;
return
destination
;
}
}
}
}
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