Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kallel_Mohamed_Firefighter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KALLEL Mohamed ali
Kallel_Mohamed_Firefighter
Commits
c77cbe67
Commit
c77cbe67
authored
1 year ago
by
KALLEL Mohamed ali
Browse files
Options
Downloads
Patches
Plain Diff
task 1
parent
45a4dc2b
No related branches found
No related tags found
No related merge requests found
Pipeline
#24770
failed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/model/FirefighterBoard.java
+8
-27
8 additions, 27 deletions
src/main/java/model/FirefighterBoard.java
src/main/java/util/Tools.java
+5
-1
5 additions, 1 deletion
src/main/java/util/Tools.java
with
13 additions
and
28 deletions
src/main/java/model/FirefighterBoard.java
+
8
−
27
View file @
c77cbe67
...
@@ -13,42 +13,23 @@ import static util.Tools.addElement;
...
@@ -13,42 +13,23 @@ import static util.Tools.addElement;
public
class
FirefighterBoard
implements
Board
<
List
<
ModelElement
>>
{
public
class
FirefighterBoard
implements
Board
<
List
<
ModelElement
>>
{
private
final
int
columnCount
;
private
final
int
columnCount
;
private
final
int
rowCount
;
private
final
int
rowCount
;
private
final
int
initialFireCount
;
private
final
int
initialFirefighterCount
;
private
List
<
Position
>
firefighterPositions
;
private
Set
<
Position
>
firePositions
;
private
Map
<
Position
,
List
<
ModelElement
>>
board
;
private
Map
<
Position
,
List
<
ModelElement
>>
board
;
private
Map
<
ModelElement
,
Integer
>
intialboard
;
private
int
step
=
0
;
private
int
step
=
0
;
private
final
Random
randomGenerator
=
new
Random
();
private
final
Random
randomGenerator
=
new
Random
();
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
in
i
tial
FirefighterCount
)
{
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
Map
<
ModelElement
,
Integer
>
intial
board
)
{
this
.
columnCount
=
columnCount
;
this
.
columnCount
=
columnCount
;
this
.
rowCount
=
rowCount
;
this
.
rowCount
=
rowCount
;
this
.
initialFireCount
=
initialFireCount
;
this
.
initialFirefighterCount
=
initialFirefighterCount
;
board
=
new
HashMap
<>();
board
=
new
HashMap
<>();
initializeElements
();
initializeElements
(
new
Fire
);
}
public
void
initializeElements
()
{
firefighterPositions
=
new
ArrayList
<>();
firePositions
=
new
HashSet
<>();
for
(
int
index
=
0
;
index
<
initialFireCount
;
index
++)
firePositions
.
add
(
randomPosition
());
for
(
int
index
=
0
;
index
<
initialFirefighterCount
;
index
++)
firefighterPositions
.
add
(
randomPosition
());
for
(
Position
firefighterPosition:
firefighterPositions
)
{
addElement
(
firefighterPosition
,
board
,
new
FireFigther
());
}
for
(
Position
firePosition:
firePositions
)
{
addElement
(
firePosition
,
board
,
new
Fire
());
}
}
public
void
initializeElements
(
ModelElement
modelElement
)
{
for
(
int
index
=
0
;
index
<
intialboard
.
get
(
modelElement
);
index
++)
addElement
(
randomPosition
(),
board
,
modelElement
);
}
}
private
Position
randomPosition
()
{
private
Position
randomPosition
()
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/util/Tools.java
+
5
−
1
View file @
c77cbe67
...
@@ -20,12 +20,14 @@ public class Tools {
...
@@ -20,12 +20,14 @@ public class Tools {
Set
<
Position
>
seen
=
new
HashSet
<>();
Set
<
Position
>
seen
=
new
HashSet
<>();
HashMap
<
Position
,
Position
>
firstMove
=
new
HashMap
<>();
HashMap
<
Position
,
Position
>
firstMove
=
new
HashMap
<>();
Queue
<
Position
>
toVisit
=
new
LinkedList
<>(
neighbors
(
position
,
rowCount
,
columnCount
));
Queue
<
Position
>
toVisit
=
new
LinkedList
<>(
neighbors
(
position
,
rowCount
,
columnCount
));
for
(
Position
initialMove
:
toVisit
)
for
(
Position
initialMove
:
toVisit
)
{
firstMove
.
put
(
initialMove
,
initialMove
);
firstMove
.
put
(
initialMove
,
initialMove
);
}
while
(!
toVisit
.
isEmpty
())
{
while
(!
toVisit
.
isEmpty
())
{
Position
current
=
toVisit
.
poll
();
Position
current
=
toVisit
.
poll
();
if
(
board
.
containsKey
(
current
))
{
if
(
board
.
containsKey
(
current
))
{
if
(
board
.
get
(
current
).
contains
(
new
Fire
())){
if
(
board
.
get
(
current
).
contains
(
new
Fire
())){
System
.
out
.
println
(
"ok chef 4"
);
return
firstMove
.
get
(
current
);
return
firstMove
.
get
(
current
);
}
}
for
(
Position
adjacent
:
neighbors
(
current
,
rowCount
,
columnCount
))
{
for
(
Position
adjacent
:
neighbors
(
current
,
rowCount
,
columnCount
))
{
...
@@ -34,6 +36,7 @@ public class Tools {
...
@@ -34,6 +36,7 @@ public class Tools {
}
}
toVisit
.
add
(
adjacent
);
toVisit
.
add
(
adjacent
);
seen
.
add
(
adjacent
);
seen
.
add
(
adjacent
);
HashMap
<
Position
,
Position
>
firstMove
=
new
HashMap
firstMove
.
put
(
adjacent
,
firstMove
.
get
(
current
));
firstMove
.
put
(
adjacent
,
firstMove
.
get
(
current
));
}
}
...
@@ -63,4 +66,5 @@ public class Tools {
...
@@ -63,4 +66,5 @@ public class Tools {
board
.
put
(
position
,
elements
);
board
.
put
(
position
,
elements
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment