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
e0e67cec
Commit
e0e67cec
authored
Apr 16, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Time Capability
parent
cd883191
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
.gitignore
.gitignore
+1
-0
Main.java
Main.java
+40
-4
No files found.
.gitignore
0 → 100644
View file @
e0e67cec
*.class
Main.java
View file @
e0e67cec
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.*
;
import
java.io.IOException
;
import
java.io.IOException
;
public
class
Main
{
public
class
Main
{
...
@@ -44,7 +45,38 @@ public class Main{
...
@@ -44,7 +45,38 @@ public class Main{
}
}
}
}
public
void
print
(){
public
void
timeMove
(){
Random
rand
=
new
Random
();
for
(
Thief
t
:
this
.
thiefs
){
while
(
true
){
int
xShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
t
.
x
+
xShift
>=
0
&&
t
.
x
+
xShift
<
this
.
n
){
break
;
}
xShift
=
rand
.
nextInt
(
3
)
-
1
;
}
int
yShift
=
rand
.
nextInt
(
3
)
-
1
;
while
(
true
){
if
(
t
.
y
+
yShift
>=
0
&&
t
.
y
+
yShift
<
this
.
m
){
break
;
}
yShift
=
rand
.
nextInt
(
3
)
-
1
;
}
if
(
isFree
(
t
.
x
+
xShift
,
t
.
y
+
yShift
)
){
t
.
x
+=
xShift
;
t
.
y
+=
yShift
;
break
;
}
}
}
}
public
void
print
(
int
t
){
System
.
out
.
println
(
"Time: "
+
t
);
for
(
int
i
=
0
;
i
<
n
;
i
++){
// Check Bounds
for
(
int
i
=
0
;
i
<
n
;
i
++){
// Check Bounds
for
(
int
j
=
0
;
j
<
m
;
j
++){
for
(
int
j
=
0
;
j
<
m
;
j
++){
if
(
isTakenByThief
(
i
,
j
)
){
if
(
isTakenByThief
(
i
,
j
)
){
...
@@ -105,7 +137,7 @@ public class Main{
...
@@ -105,7 +137,7 @@ public class Main{
mainBoard
.
polices
.
add
(
newPolice
);
mainBoard
.
polices
.
add
(
newPolice
);
}
}
// Create Thiefs
// Create Thiefs
for
(
int
i
=
0
;
i
<
p
;
i
++){
for
(
int
i
=
0
;
i
<
t
;
i
++){
boolean
flag
=
true
;
boolean
flag
=
true
;
int
x
=
0
,
y
=
0
;
int
x
=
0
,
y
=
0
;
while
(
flag
){
while
(
flag
){
...
@@ -117,8 +149,12 @@ public class Main{
...
@@ -117,8 +149,12 @@ public class Main{
mainBoard
.
thiefs
.
add
(
newThief
);
mainBoard
.
thiefs
.
add
(
newThief
);
}
}
// Print fucking board
// Print fucking board
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
for
(
int
i
=
0
;
i
<
300
;
i
++){
mainBoard
.
print
();
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
mainBoard
.
print
(
i
);
TimeUnit
.
SECONDS
.
sleep
(
2
);
mainBoard
.
timeMove
();
}
sc
.
close
();
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