Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FirefighterStarter
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NDIAYE Ousseynou
FirefighterStarter
Commits
0aedffc2
Commit
0aedffc2
authored
5 months ago
by
ousseyn01
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of Mountain in fighfighterboard
parent
6e4fddf6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/model/FirefighterBoard.java
+30
-5
30 additions, 5 deletions
src/main/java/model/FirefighterBoard.java
with
30 additions
and
5 deletions
src/main/java/model/FirefighterBoard.java
+
30
−
5
View file @
0aedffc2
...
...
@@ -10,16 +10,18 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
private
final
int
initialFireCount
;
private
final
int
initialFirefighterCount
;
private
final
int
initialCloudCount
;
private
final
int
initialMountainCount
=
3
;
private
final
model
.
TargetStrategy
targetStrategy
=
new
model
.
TargetStrategy
();
private
List
<
Firefighter
>
firefighters
;
private
Fire
fire
;
private
final
Map
<
Position
,
List
<
Position
>>
neighbors
=
new
HashMap
<>();
private
List
<
Cloud
>
clouds
;
private
List
<
Mountain
>
mountains
;
private
final
Position
[][]
positions
;
private
int
step
=
0
;
private
final
Random
randomGenerator
=
new
Random
();
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
initialFirefighterCount
,
int
initialCloudCount
)
{
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
initialFirefighterCount
,
int
initialCloudCount
,
int
initialMountainCount
)
{
this
.
columnCount
=
columnCount
;
this
.
rowCount
=
rowCount
;
this
.
positions
=
new
Position
[
rowCount
][
columnCount
];
...
...
@@ -44,6 +46,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
public
void
initializeElements
()
{
firefighters
=
new
ArrayList
<>();
clouds
=
new
ArrayList
<>();
mountains
=
new
ArrayList
<>();
Set
<
Position
>
firePositions
=
new
HashSet
<>();
for
(
int
index
=
0
;
index
<
initialCloudCount
;
index
++)
{
clouds
.
add
(
new
Cloud
(
randomPosition
(),
neighbors
));
...
...
@@ -56,6 +59,26 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
for
(
int
index
=
0
;
index
<
initialCloudCount
;
index
++)
{
clouds
.
add
(
new
Cloud
(
randomPosition
(),
neighbors
));
}
for
(
int
i
=
0
;
i
<
initialMountainCount
;
i
++)
{
Position
position
=
randomPosition
();
if
(
isPositionOccupied
(
position
))
continue
;
mountains
.
add
(
new
Mountain
(
position
));
}
}
private
boolean
isPositionOccupied
(
Position
position
)
{
// Vérifie si la position est occupée par une montagne
for
(
Mountain
mountain
:
mountains
)
{
if
(
mountain
.
getPosition
().
equals
(
position
))
return
true
;
}
// Vérifie les autres éléments
for
(
Firefighter
firefighter
:
firefighters
)
{
if
(
firefighter
.
getPosition
().
equals
(
position
))
return
true
;
}
for
(
Cloud
cloud
:
clouds
)
{
if
(
cloud
.
getPosition
().
equals
(
position
))
return
true
;
}
return
fire
.
getFirePositions
().
contains
(
position
);
}
private
Position
randomPosition
()
{
...
...
@@ -70,6 +93,11 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
result
.
add
(
ModelElement
.
CLOUD
);
}
}
for
(
Mountain
mountain
:
mountains
){
if
(
mountain
.
getPosition
().
equals
(
position
)){
result
.
add
(
ModelElement
.
MOUNTAIN
);
}
}
for
(
Firefighter
firefighter
:
firefighters
)
if
(
firefighter
.
getPosition
().
equals
(
position
))
...
...
@@ -97,12 +125,8 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
}
// Déplacer les nuages et éteindre les feux
for
(
Cloud
cloud
:
clouds
)
{
//cloud.moveRandomly();
//cloud.extinguishFire(fire);
cloud
.
moveAndExtinguishFire
(
fire
);
cloud
.
extinguishFireCloud
(
fire
);
//modifiedPositions.addAll(fire.spreadFire());
}
step
++;
...
...
@@ -157,6 +181,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
case
FIRE
->
fire
.
getFirePositions
().
add
(
position
);
case
FIREFIGHTER
->
firefighters
.
add
(
new
Firefighter
(
position
));
case
CLOUD
->
clouds
.
add
(
new
Cloud
(
position
,
neighbors
));
case
MOUNTAIN
->
mountains
.
add
(
new
Mountain
(
position
));
}
}
}
...
...
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