Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FirefighterStarter Mansour Chadi Chahine Rami
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
MANSOUR Chadi
FirefighterStarter Mansour Chadi Chahine Rami
Commits
4a693f33
Commit
4a693f33
authored
7 months ago
by
MANSOUR Chadi
Browse files
Options
Downloads
Patches
Plain Diff
the code works now but not correctly some modifications to the classes should be added
parent
e2fe178b
No related branches found
No related tags found
No related merge requests found
Pipeline
#40279
passed
7 months ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/model/FirefighterBoard.java
+64
-16
64 additions, 16 deletions
src/main/java/model/FirefighterBoard.java
with
64 additions
and
16 deletions
src/main/java/model/FirefighterBoard.java
+
64
−
16
View file @
4a693f33
package
model
;
import
util.Position
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.*
;
public
class
FirefighterBoard
implements
Board
<
List
<
ModelElement
>>
{
private
int
rowCount
;
private
int
columnCount
;
private
List
<
Position
>
firefighterPositions
;
private
Set
<
Position
>
firePositions
;
private
final
FireManager
fireManager
;
private
final
FirefighterManager
firefighterManager
;
private
final
NeighborManager
neighborManager
;
private
int
step
;
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
initialFirefighterCount
)
{
this
.
columnCount
=
columnCount
;
this
.
rowCount
=
rowCount
;
this
.
neighborManager
=
new
NeighborManager
(
rowCount
,
columnCount
);
this
.
fireManager
=
new
FireManager
(
new
SimpleFireSpreadStrategy
());
this
.
firefighterManager
=
new
FirefighterManager
(
new
SimpleFirefighterMovementStrategy
());
Random
random
=
new
Random
();
fire
fighterPositions
=
Firefighter
Manager
.
initializeFire
FightersPosition
s
(
initialFire
fighter
Count
,
rowCount
,
columnCount
,
random
);
fire
Positions
=
Fire
Manager
.
initializeFires
(
initialFireCount
,
rowCount
,
columnCount
,
random
);
// Initialize firefighters and fires (you can adapt this code as needed)
fireManager
.
initializeFires
(
initialFireCount
,
rowCount
,
columnCount
,
random
);
fire
fighter
Manager
.
initializeFire
FightersPosition
s
(
initialFire
fighter
Count
,
rowCount
,
columnCount
,
random
);
this
.
step
=
0
;
}
@Override
public
List
<
ModelElement
>
getState
(
Position
position
)
{
// Implement this method to return the state of the given position
return
null
;
// This is just a placeholder
List
<
ModelElement
>
elements
=
new
ArrayList
<>();
// Check if the position contains a fire
if
(
fireManager
.
getFirePositions
().
contains
(
position
))
{
elements
.
add
(
ModelElement
.
FIRE
);
}
// Check if the position contains a firefighter
if
(
firefighterManager
.
getFirefighterPositions
().
contains
(
position
))
{
elements
.
add
(
ModelElement
.
FIREFIGHTER
);
}
return
elements
;
}
@Override
public
void
setState
(
List
<
ModelElement
>
state
,
Position
position
)
{
// Implement this method to set the state of the given position
fireManager
.
extinguish
(
position
);
firefighterManager
.
getFirefighterPositions
().
remove
(
position
);
// Add elements based on the new state
for
(
ModelElement
element
:
state
)
{
switch
(
element
)
{
case
FIRE
->
fireManager
.
getFirePositions
().
add
(
position
);
case
FIREFIGHTER
->
firefighterManager
.
getFirefighterPositions
().
add
(
position
);
}
}
}
@Override
...
...
@@ -45,18 +70,41 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
@Override
public
List
<
Position
>
updateToNextGeneration
()
{
// Implement this method to return updated positions for the next generation
return
null
;
// This is just a placeholder
List
<
Position
>
modifiedPositions
=
new
ArrayList
<>();
// Spread the fires and update affected positions
modifiedPositions
.
addAll
(
fireManager
.
fireSpread
(
neighborManager
.
getNeighbors
()));
// Move firefighters and update affected positions
modifiedPositions
.
addAll
(
firefighterManager
.
moveFireFighters
(
fireManager
.
getFirePositions
(),
neighborManager
.
getNeighbors
()
));
// Increment the step count
step
++;
return
modifiedPositions
;
}
@Override
public
void
reset
()
{
// Implement this method to reset the board
// Reset step and reinitialize managers
this
.
step
=
0
;
Random
random
=
new
Random
();
fireManager
.
getFirePositions
().
clear
();
firefighterManager
.
getFirefighterPositions
().
clear
();
fireManager
.
initializeFires
(
fireManager
.
getFirePositions
().
size
(),
rowCount
,
columnCount
,
random
);
firefighterManager
.
initializeFireFightersPositions
(
firefighterManager
.
getFirefighterPositions
().
size
(),
rowCount
,
columnCount
,
random
);
}
@Override
public
int
stepNumber
()
{
return
0
;
// This is just a placeholder
return
step
;
}
}
...
...
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