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
a6054093
Commit
a6054093
authored
Apr 15, 2019
by
hosein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playground -> putRandom | int[][] upgraded!
parent
ff9f1406
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
PlayGround.java
src/PlayGround.java
+23
-6
No files found.
src/PlayGround.java
View file @
a6054093
...
@@ -30,18 +30,34 @@ public class PlayGround {
...
@@ -30,18 +30,34 @@ public class PlayGround {
}
}
}
}
public
void
putRandom
()
{
public
int
[][]
putRandom
()
{
int
[][]
positions
=
new
int
[
policeNumbers
+
1
][
2
];
int
i
,
j
,
k
;
int
i
,
j
,
k
;
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
if
(
n
*
m
>
policeNumbers
)
if
(
n
*
m
<
policeNumbers
)
System
.
out
.
println
(
"Error!! NOT ENOUGH SPACE FOR POLICES AND THIEF IN GROUND"
);
for
(
k
=
0
;
k
<
policeNumbers
;
k
++)
{
else
{
for
(
k
=
0
;
k
<
policeNumbers
;
k
++)
{
// police
i
=
rand
.
nextInt
();
i
=
rand
.
nextInt
();
j
=
rand
.
nextInt
();
j
=
rand
.
nextInt
();
if
(
ground
[
i
][
j
]
==
0
)
if
(
ground
[
i
][
j
]
==
0
)
{
ground
[
i
][
j
]
=
1
;
ground
[
i
][
j
]
=
1
;
else
k
--;
positions
[
k
][
0
]
=
i
;
// x
positions
[
k
][
1
]
=
j
;
// y
}
else
k
--;
}
}
else
System
.
out
.
println
(
"Error!! police numbers are higher than n*m"
);
for
(
k
=
0
;
k
<
1
;
k
++)
{
// thief
i
=
rand
.
nextInt
();
j
=
rand
.
nextInt
();
if
(
ground
[
i
][
j
]
==
0
)
{
ground
[
i
][
j
]
=
1
;
positions
[
policeNumbers
][
0
]
=
i
;
// x
positions
[
policeNumbers
][
1
]
=
j
;
// y
}
}
}
return
positions
;
}
}
public
void
change
(
int
[][]
newPolicesSituation
,
int
xThief
,
int
yThief
)
{
public
void
change
(
int
[][]
newPolicesSituation
,
int
xThief
,
int
yThief
)
{
...
@@ -49,6 +65,7 @@ public class PlayGround {
...
@@ -49,6 +65,7 @@ public class PlayGround {
for
(
i
=
0
;
i
<
n
;
i
++)
for
(
i
=
0
;
i
<
n
;
i
++)
for
(
j
=
0
;
j
<
m
;
j
++)
for
(
j
=
0
;
j
<
m
;
j
++)
ground
[
i
][
j
]
=
0
;
ground
[
i
][
j
]
=
0
;
for
(
i
=
0
;
i
<
policeNumbers
;
i
++)
for
(
i
=
0
;
i
<
policeNumbers
;
i
++)
ground
[
newPolicesSituation
[
i
][
0
]][
newPolicesSituation
[
i
][
1
]]
=
1
;
ground
[
newPolicesSituation
[
i
][
0
]][
newPolicesSituation
[
i
][
1
]]
=
1
;
...
...
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