Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Police
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
9731077
Police
Commits
71952f2f
Commit
71952f2f
authored
Apr 20, 2019
by
9731077
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
robber move randomly aded
parent
070a564a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
1 deletion
+90
-1
Robber.java
Robber.java
+90
-1
No files found.
Robber.java
View file @
71952f2f
package
PACKAGE_NAME
;
import
java.util.*
;
public
class
Robber
{
private
int
x
,
y
,
moveNum
;
public
void
setY
(
int
y
)
{
this
.
y
=
y
;
}
public
void
setX
(
int
x
)
{
this
.
x
=
x
;
}
public
void
setMoveNum
(
int
moveNum
)
{
this
.
moveNum
=
moveNum
;
}
public
int
getY
()
{
return
y
;
}
public
int
getX
()
{
return
x
;
}
public
int
getMoveNum
()
{
return
moveNum
;
}
public
void
moveRandomly
(
int
length
,
int
width
)
{
Random
randomGenerator
=
new
Random
();
moveNum
++;
if
(
x
!=
0
&&
x
!=
length
-
1
&&
y
!=
0
&&
y
!=
width
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
!=
0
&&
y
!=
width
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
y
==
0
&&
x
!=
0
&&
x
!=
length
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
);
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
length
-
1
&&
y
!=
0
&&
y
!=
width
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
3
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
y
==
width
-
1
&&
x
!=
0
&&
x
!=
length
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
3
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
==
0
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
2
);
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
length
-
1
&&
y
==
0
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
);
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
0
&&
y
==
width
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
);
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
if
(
x
==
length
-
1
&&
y
==
width
-
1
)
{
int
rx
=
randomGenerator
.
nextInt
(
2
)
-
1
;
int
ry
=
randomGenerator
.
nextInt
(
2
)
-
1
;
x
=
x
+
rx
;
y
=
y
+
ry
;
}
}
}
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