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
cd883191
Commit
cd883191
authored
Apr 16, 2019
by
Omid Sayfun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First Breakpoint
parent
fa80d9d3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
1 deletion
+86
-1
Main.java
Main.java
+86
-1
No files found.
Main.java
View file @
cd883191
...
@@ -14,6 +14,51 @@ public class Main{
...
@@ -14,6 +14,51 @@ public class Main{
this
.
thiefs
=
new
ArrayList
<
Thief
>();
this
.
thiefs
=
new
ArrayList
<
Thief
>();
this
.
polices
=
new
ArrayList
<
Police
>();
this
.
polices
=
new
ArrayList
<
Police
>();
}
}
public
Boolean
isTakenByThief
(
int
x
,
int
y
){
for
(
Thief
t
:
this
.
thiefs
){
if
(
t
.
x
==
x
&&
t
.
y
==
y
){
return
true
;
}
}
return
false
;
}
public
Boolean
isTakenByPolice
(
int
x
,
int
y
){
for
(
Police
t
:
this
.
polices
){
if
(
t
.
x
==
x
&&
t
.
y
==
y
){
return
true
;
}
}
return
false
;
}
public
Boolean
isFree
(
int
x
,
int
y
){
if
(
!
isTakenByThief
(
x
,
y
)
&&
!
isTakenByPolice
(
x
,
y
)
){
return
true
;
}
else
{
return
false
;
}
}
public
void
print
(){
for
(
int
i
=
0
;
i
<
n
;
i
++){
// Check Bounds
for
(
int
j
=
0
;
j
<
m
;
j
++){
if
(
isTakenByThief
(
i
,
j
)
){
System
.
out
.
print
(
"T "
);
}
else
if
(
isTakenByPolice
(
i
,
j
)
){
System
.
out
.
print
(
"P "
);
}
else
{
System
.
out
.
print
(
"- "
);
}
}
System
.
out
.
println
(
""
);
}
}
}
}
static
class
Thief
{
static
class
Thief
{
public
int
x
;
public
int
x
;
...
@@ -34,6 +79,46 @@ public class Main{
...
@@ -34,6 +79,46 @@ public class Main{
}
}
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
// Get Data
System
.
out
.
println
(
"Enter N: "
);
int
n
=
Integer
.
parseInt
(
sc
.
next
());
System
.
out
.
println
(
"Enter M: "
);
int
m
=
Integer
.
parseInt
(
sc
.
next
());
System
.
out
.
println
(
"Enter number of polices: "
);
int
p
=
Integer
.
parseInt
(
sc
.
next
());
System
.
out
.
println
(
"Enter number of thiefs: "
);
int
t
=
Integer
.
parseInt
(
sc
.
next
());
// Initialize Board
Board
mainBoard
=
new
Board
(
n
,
m
);
Random
rand
=
new
Random
();
// Create Polices
for
(
int
i
=
0
;
i
<
p
;
i
++){
boolean
flag
=
true
;
int
x
=
0
,
y
=
0
;
while
(
flag
){
x
=
rand
.
nextInt
(
n
);
y
=
rand
.
nextInt
(
m
);
flag
=
!
mainBoard
.
isFree
(
x
,
y
);
}
Police
newPolice
=
new
Police
(
x
,
y
);
mainBoard
.
polices
.
add
(
newPolice
);
}
// Create Thiefs
for
(
int
i
=
0
;
i
<
p
;
i
++){
boolean
flag
=
true
;
int
x
=
0
,
y
=
0
;
while
(
flag
){
x
=
rand
.
nextInt
(
n
);
y
=
rand
.
nextInt
(
m
);
flag
=
!
mainBoard
.
isFree
(
x
,
y
);
}
Thief
newThief
=
new
Thief
(
x
,
y
);
mainBoard
.
thiefs
.
add
(
newThief
);
}
// Print fucking board
new
ProcessBuilder
(
"cmd"
,
"/c"
,
"cls"
).
inheritIO
().
start
().
waitFor
();
mainBoard
.
print
();
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