Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
AP Lab 6
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
Omid Sayfun
AP Lab 6
Commits
0ac16802
Commit
0ac16802
authored
Apr 17, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Thoughtful:D Movement
parent
ef5bb69c
Pipeline
#485
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
12 deletions
+106
-12
Main.java
Main.java
+106
-12
No files found.
Main.java
View file @
0ac16802
...
@@ -59,29 +59,123 @@ public class Main{
...
@@ -59,29 +59,123 @@ public class Main{
Random
rand
=
new
Random
();
Random
rand
=
new
Random
();
// Move Polices
// Move Polices
for
(
Police
p
:
this
.
polices
){
for
(
Police
p
:
this
.
polices
){
while
(
true
){
if
(
p
.
target
==
null
){
// Random Move
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
while
(
true
){
if
(
p
.
x
+
xShift
>=
0
&&
p
.
x
+
xShift
<
this
.
n
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
p
.
x
+
xShift
>=
0
&&
p
.
x
+
xShift
<
this
.
n
){
break
;
}
xShift
=
rand
.
nextInt
(
3
)
-
1
;
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
p
.
y
+
yShift
>=
0
&&
p
.
y
+
yShift
<
this
.
m
){
break
;
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
if
(
isFree
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
p
.
x
+=
xShift
;
p
.
y
+=
yShift
;
if
(
isThiefInRange
(
p
.
x
,
p
.
y
)
){
for
(
Police
police
:
this
.
polices
){
police
.
target
=
this
.
thief
;
}
}
this
.
policeMoves
++;
break
;
break
;
}
}
xShift
=
rand
.
nextInt
(
3
)
-
1
;
}
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
else
{
// Move based on thought :D
while
(
true
){
int
xShiftThought
=
0
;
if
(
p
.
y
+
yShift
>=
0
&&
p
.
y
+
yShift
<
this
.
m
){
int
yShiftThought
=
0
;
if
(
p
.
target
.
x
-
p
.
x
!=
0
){
break
;
xShiftThought
=
(
p
.
target
.
x
-
p
.
x
)
/
Math
.
abs
(
p
.
target
.
x
-
p
.
x
);
}
if
(
p
.
target
.
y
-
p
.
y
!=
0
){
yShiftThought
=
(
p
.
target
.
y
-
p
.
y
)
/
Math
.
abs
(
p
.
target
.
y
-
p
.
y
);
}
if
(
isFree
(
p
.
x
+
xShiftThought
,
p
.
y
+
yShiftThought
)
){
// Diagonal
p
.
x
+=
xShiftThought
;
p
.
y
+=
yShiftThought
;
this
.
policeMoves
++;
}
else
if
(
isFree
(
p
.
x
,
p
.
y
+
yShiftThought
)
){
// Y Axis
p
.
y
+=
yShiftThought
;
this
.
policeMoves
++;
}
else
if
(
isFree
(
p
.
x
+
xShiftThought
,
p
.
y
)
){
// X Axis
p
.
x
+=
xShiftThought
;
this
.
policeMoves
++;
}
else
{
// Random Move
while
(
true
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
p
.
x
+
xShift
>=
0
&&
p
.
x
+
xShift
<
this
.
n
){
break
;
}
xShift
=
rand
.
nextInt
(
3
)
-
1
;
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
p
.
y
+
yShift
>=
0
&&
p
.
y
+
yShift
<
this
.
m
){
break
;
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
if
(
isFree
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
p
.
x
+=
xShift
;
p
.
y
+=
yShift
;
if
(
p
.
target
==
null
&&
isThiefInRange
(
p
.
x
,
p
.
y
)
){
for
(
Police
police
:
this
.
polices
){
police
.
target
=
this
.
thief
;
}
}
this
.
policeMoves
++;
break
;
}
}
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
}
if
(
isFree
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
}
}
// Move Thief
while
(
true
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
this
.
thief
.
x
+
xShift
>=
0
&&
this
.
thief
.
x
+
xShift
<
this
.
n
){
break
;
}
xShift
=
rand
.
nextInt
(
3
)
-
1
;
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
this
.
thief
.
y
+
yShift
>=
0
&&
this
.
thief
.
y
+
yShift
<
this
.
m
){
p
.
x
+=
xShift
;
p
.
y
+=
yShift
;
break
;
break
;
}
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
// To Do: Check if thief went into police house
if
(
isFree
(
this
.
thief
.
x
+
xShift
,
this
.
thief
.
y
+
yShift
)
){
this
.
thief
.
x
+=
xShift
;
this
.
thief
.
y
+=
yShift
;
this
.
thiefMoves
++;
break
;
}
}
}
}
}
}
...
...
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