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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CHERCHEM Sarah
FirefighterStarter
Commits
2e6fc89a
Commit
2e6fc89a
authored
7 months ago
by
AREZKI Celia
Browse files
Options
Downloads
Patches
Plain Diff
Add a spreadFire method to prevent fire from spreading across mountains.
parent
1d51f176
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/app/SimulatorMain.java
+1
-0
1 addition, 0 deletions
src/main/java/app/SimulatorMain.java
src/main/java/model/FireManager.java
+41
-0
41 additions, 0 deletions
src/main/java/model/FireManager.java
with
42 additions
and
0 deletions
src/main/java/app/SimulatorMain.java
+
1
−
0
View file @
2e6fc89a
...
...
@@ -4,4 +4,5 @@ public class SimulatorMain {
public
static
void
main
(
String
[]
args
){
SimulatorApplication
.
main
(
args
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/model/FireManager.java
+
41
−
0
View file @
2e6fc89a
package
model
;
import
util.Position
;
import
view.ViewElement
;
import
java.util.*
;
...
...
@@ -37,6 +38,46 @@ public class FireManager implements FireBehavior, FireProperties{
}
return
newFirePositions
;
}
public
void
spreadFire
(
ViewElement
[][]
grid
)
{
int
rows
=
grid
.
length
;
int
columns
=
grid
[
0
].
length
;
ViewElement
[][]
newGrid
=
new
ViewElement
[
rows
][
columns
];
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
System
.
arraycopy
(
grid
[
i
],
0
,
newGrid
[
i
],
0
,
columns
);
}
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
for
(
int
j
=
0
;
j
<
columns
;
j
++)
{
if
(
grid
[
i
][
j
]
==
ViewElement
.
FIRE
)
{
// Tenter de propager le feu sur les voisins
for
(
Position
neighbor
:
getNeighbors
(
i
,
j
,
rows
,
columns
))
{
if
(
grid
[
neighbor
.
row
()][
neighbor
.
column
()]
==
ViewElement
.
EMPTY
)
{
newGrid
[
neighbor
.
row
()][
neighbor
.
column
()]
=
ViewElement
.
FIRE
;
}
// Empêcher la propagation sur les montagnes
if
(
grid
[
neighbor
.
row
()][
neighbor
.
column
()]
==
ViewElement
.
MOUNTAIN
)
{
newGrid
[
neighbor
.
row
()][
neighbor
.
column
()]
=
ViewElement
.
MOUNTAIN
;
}
}
}
}
}
// Mise à jour de la grille
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
System
.
arraycopy
(
newGrid
[
i
],
0
,
grid
[
i
],
0
,
columns
);
}
}
private
List
<
Position
>
getNeighbors
(
int
row
,
int
column
,
int
rows
,
int
columns
)
{
List
<
Position
>
neighbors
=
new
ArrayList
<>();
if
(
row
>
0
)
neighbors
.
add
(
new
Position
(
row
-
1
,
column
));
if
(
row
<
rows
-
1
)
neighbors
.
add
(
new
Position
(
row
+
1
,
column
));
if
(
column
>
0
)
neighbors
.
add
(
new
Position
(
row
,
column
-
1
));
if
(
column
<
columns
-
1
)
neighbors
.
add
(
new
Position
(
row
,
column
+
1
));
return
neighbors
;
}
// Extinguish a fire at a specific 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