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
32eac881
Commit
32eac881
authored
Apr 18, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PreFinal Release
parent
284276d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
40 deletions
+71
-40
Main.java
Main.java
+71
-40
No files found.
Main.java
View file @
32eac881
...
...
@@ -55,8 +55,41 @@ public class Main{
return
false
;
}
public
void
timeMove
(){
public
Boolean
timeMove
(){
Random
rand
=
new
Random
();
int
prevX
=
this
.
thief
.
x
;
int
prevY
=
this
.
thief
.
y
;
// 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
){
break
;
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
this
.
thiefMoves
++;
// To Do: Check if thief went into police house
if
(
isTakenByPolice
(
this
.
thief
.
x
+
xShift
,
this
.
thief
.
y
+
yShift
)
){
this
.
thief
.
x
+=
xShift
;
this
.
thief
.
y
+=
yShift
;
return
false
;
}
else
{
this
.
thief
.
x
+=
xShift
;
this
.
thief
.
y
+=
yShift
;
break
;
}
}
// Move Polices
for
(
Police
p
:
this
.
polices
){
if
(
p
.
target
==
null
){
// Random Move
...
...
@@ -78,7 +111,7 @@ public class Main{
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
if
(
isFre
e
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
if
(
!
isTakenByPolic
e
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
p
.
x
+=
xShift
;
p
.
y
+=
yShift
;
...
...
@@ -95,27 +128,39 @@ public class Main{
}
else
{
// Move based on thought :D
int
xShiftThought
=
0
;
int
yShiftThought
=
0
;
if
(
p
.
target
.
x
-
p
.
x
!=
0
){
if
(
p
revX
-
p
.
x
!=
0
){
xShiftThought
=
(
p
.
target
.
x
-
p
.
x
)
/
Math
.
abs
(
p
.
target
.
x
-
p
.
x
);
xShiftThought
=
(
p
revX
-
p
.
x
)
/
Math
.
abs
(
prevX
-
p
.
x
);
}
if
(
p
.
target
.
y
-
p
.
y
!=
0
){
if
(
p
revY
-
p
.
y
!=
0
){
yShiftThought
=
(
p
.
target
.
y
-
p
.
y
)
/
Math
.
abs
(
p
.
target
.
y
-
p
.
y
);
yShiftThought
=
(
p
revY
-
p
.
y
)
/
Math
.
abs
(
prevY
-
p
.
y
);
}
if
(
isFre
e
(
p
.
x
+
xShiftThought
,
p
.
y
+
yShiftThought
)
){
// Diagonal
if
(
!
isTakenByPolic
e
(
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
if
(
p
.
y
==
prevY
&&
p
.
x
==
prevX
){
return
false
;
}
}
else
if
(
!
isTakenByPolice
(
p
.
x
,
p
.
y
+
yShiftThought
)
){
// Y Axis
p
.
y
+=
yShiftThought
;
this
.
policeMoves
++;
}
else
if
(
isFree
(
p
.
x
+
xShiftThought
,
p
.
y
)
){
// X Axis
if
(
p
.
y
==
prevY
&&
p
.
x
==
prevX
){
return
false
;
}
}
else
if
(
!
isTakenByPolice
(
p
.
x
+
xShiftThought
,
p
.
y
)
){
// X Axis
p
.
x
+=
xShiftThought
;
this
.
policeMoves
++;
if
(
p
.
y
==
prevY
&&
p
.
x
==
prevX
){
return
false
;
}
}
else
{
// Random Move
while
(
true
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
...
...
@@ -134,44 +179,22 @@ public class Main{
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
if
(
isFre
e
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
if
(
!
isTakenByPolic
e
(
p
.
x
+
xShift
,
p
.
y
+
yShift
)
){
p
.
x
+=
xShift
;
p
.
y
+=
yShift
;
this
.
policeMoves
++;
if
(
p
.
y
==
prevY
&&
p
.
x
==
prevX
){
return
false
;
}
break
;
}
}
}
}
}
// 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
){
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
;
}
}
return
true
;
}
public
void
print
(
int
t
){
...
...
@@ -192,7 +215,10 @@ public class Main{
}
public
void
printFinal
(){
System
.
out
.
println
(
"\tThe Fucking Thief is caught!"
);
System
.
out
.
println
();
System
.
out
.
println
(
"Thief Moves: "
+
this
.
thiefMoves
);
System
.
out
.
println
(
"Police Moves: "
+
this
.
policeMoves
);
}
}
static
class
Thief
{
...
...
@@ -251,12 +277,17 @@ public class Main{
mainBoard
.
polices
.
add
(
newPolice
);
}
// Print fucking board
for
(
int
i
=
0
;
i
<
300
;
i
++){
flag
=
true
;
int
i
=
0
;
while
(
flag
){
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
mainBoard
.
print
(
i
);
flag
=
mainBoard
.
timeMove
();
TimeUnit
.
SECONDS
.
sleep
(
2
);
mainBoard
.
timeMove
()
;
i
++
;
}
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
mainBoard
.
printFinal
();
sc
.
close
();
}
}
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