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
3b908ed8
Commit
3b908ed8
authored
4 months ago
by
ousseyn01
Browse files
Options
Downloads
Patches
Plain Diff
FirefighterBoard.java is MODIFIED in order to do respect OCP
parent
5b2edb32
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/model/FirefighterBoard.java
+28
-45
28 additions, 45 deletions
src/main/java/model/FirefighterBoard.java
with
28 additions
and
45 deletions
src/main/java/model/FirefighterBoard.java
+
28
−
45
View file @
3b908ed8
package
model
;
package
model
;
import
model.elements.*
;
import
model.update.NextGenerationUpdater
;
import
model.update.NextGenerationUpdater
;
import
util.Position
;
import
util.Position
;
...
@@ -25,6 +26,9 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
...
@@ -25,6 +26,9 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
private
NextGenerationUpdater
nextGenerationUpdater
;
private
NextGenerationUpdater
nextGenerationUpdater
;
private
List
<
TerrainElement
>
terrainElements
;
private
List
<
TerrainElement
>
terrainElements
;
private
final
List
<
ElementHandler
>
handlers
=
new
ArrayList
<>();
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
initialFirefighterCount
,
int
initialCloudCount
,
int
initialMountainCount
)
{
public
FirefighterBoard
(
int
columnCount
,
int
rowCount
,
int
initialFireCount
,
int
initialFirefighterCount
,
int
initialCloudCount
,
int
initialMountainCount
)
{
...
@@ -60,7 +64,13 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
...
@@ -60,7 +64,13 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
Position
position
=
randomPosition
();
Position
position
=
randomPosition
();
terrainElements
.
add
(
new
Rocaille
(
position
));
terrainElements
.
add
(
new
Rocaille
(
position
));
}
}
}
handlers
.
add
(
new
FireHandler
(
fire
));
handlers
.
add
(
new
FirefighterHandler
(
firefighters
));
handlers
.
add
(
new
CloudHandler
(
clouds
,
neighbors
));
handlers
.
add
(
new
MountainHandler
(
mountains
));
handlers
.
add
(
new
TerrainHandler
(
terrainElements
,
Route
.
class
,
ModelElement
.
ROUTE
));
handlers
.
add
(
new
TerrainHandler
(
terrainElements
,
Rocaille
.
class
,
ModelElement
.
ROCAILLE
));
}
public
void
initializeElements
()
{
public
void
initializeElements
()
{
firefighters
=
new
ArrayList
<>();
firefighters
=
new
ArrayList
<>();
...
@@ -118,38 +128,6 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
...
@@ -118,38 +128,6 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
return
new
Position
(
randomGenerator
.
nextInt
(
rowCount
),
randomGenerator
.
nextInt
(
columnCount
));
return
new
Position
(
randomGenerator
.
nextInt
(
rowCount
),
randomGenerator
.
nextInt
(
columnCount
));
}
}
@Override
public
List
<
ModelElement
>
getState
(
Position
position
)
{
List
<
ModelElement
>
result
=
new
ArrayList
<>();
for
(
Cloud
cloud
:
clouds
)
{
if
(
cloud
.
getPosition
().
equals
(
position
))
{
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
))
result
.
add
(
ModelElement
.
FIREFIGHTER
);
if
(
fire
.
getFirePositions
().
contains
(
position
))
result
.
add
(
ModelElement
.
FIRE
);
for
(
TerrainElement
element
:
terrainElements
)
{
if
(
element
.
getPosition
().
equals
(
position
))
{
if
(
element
instanceof
Route
)
{
result
.
add
(
ModelElement
.
ROUTE
);
}
else
if
(
element
instanceof
Rocaille
)
{
result
.
add
(
ModelElement
.
ROCAILLE
);
}
}
}
return
result
;
}
@Override
@Override
public
int
rowCount
()
{
public
int
rowCount
()
{
...
@@ -167,7 +145,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
...
@@ -167,7 +145,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
public
List
<
Position
>
updateToNextGeneration
()
{
public
List
<
Position
>
updateToNextGeneration
()
{
List
<
Position
>
updatedPositions
=
nextGenerationUpdater
.
updateToNextGeneration
();
List
<
Position
>
updatedPositions
=
nextGenerationUpdater
.
updateToNextGeneration
();
step
++;
// Incrémentation du compteur de génération
step
++;
return
updatedPositions
;
return
updatedPositions
;
//return nextGenerationUpdater.updateToNextGeneration();
//return nextGenerationUpdater.updateToNextGeneration();
}
}
...
@@ -178,22 +156,27 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
...
@@ -178,22 +156,27 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
nextGenerationUpdater
.
resetStep
();
nextGenerationUpdater
.
resetStep
();
}
}
@Override
public
List
<
ModelElement
>
getState
(
Position
position
)
{
List
<
ModelElement
>
result
=
new
ArrayList
<>();
for
(
ElementHandler
handler
:
handlers
)
{
if
(
handler
.
hasElement
(
position
))
{
result
.
add
(
handler
.
getModelElement
());
}
}
return
result
;
}
@Override
@Override
public
void
setState
(
List
<
ModelElement
>
state
,
Position
position
)
{
public
void
setState
(
List
<
ModelElement
>
state
,
Position
position
)
{
f
ire
.
getFirePositions
().
remove
(
position
);
f
or
(
ElementHandler
handler
:
handlers
)
{
firefight
er
s
.
remove
If
(
f
->
f
.
getPosition
().
equals
(
position
)
)
;
handl
er
.
remove
Element
(
position
);
clouds
.
removeIf
(
c
->
c
.
getPosition
().
equals
(
position
));
}
for
(
ModelElement
element
:
state
)
{
for
(
ModelElement
element
:
state
)
{
switch
(
element
)
{
handlers
.
stream
()
case
FIRE
->
fire
.
getFirePositions
().
add
(
position
);
.
filter
(
handler
->
handler
.
getModelElement
()
==
element
)
case
FIREFIGHTER
->
firefighters
.
add
(
new
Firefighter
(
position
));
.
forEach
(
handler
->
handler
.
addElement
(
position
));
case
CLOUD
->
clouds
.
add
(
new
Cloud
(
position
,
neighbors
));
case
MOUNTAIN
->
mountains
.
add
(
new
Mountain
(
position
));
case
ROUTE
->
terrainElements
.
add
(
new
Route
(
position
));
case
ROCAILLE
->
terrainElements
.
add
(
new
Rocaille
(
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