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
004aad73
Commit
004aad73
authored
6 months ago
by
ousseyn01
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of firefighter for moving to the best position without touching Mountain
parent
d3558510
No related branches found
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/Firefighter.java
+22
-1
22 additions, 1 deletion
src/main/java/model/Firefighter.java
with
22 additions
and
1 deletion
src/main/java/model/Firefighter.java
+
22
−
1
View file @
004aad73
...
...
@@ -24,9 +24,30 @@ public class Firefighter {
this
.
position
=
position
;
}
public
Position
moveToBestPosition
(
TargetStrategy
targetStrategy
,
Set
<
Position
>
firePositions
,
Map
<
Position
,
List
<
Position
>>
neighbors
)
{
/*
public Position moveToBestPosition(TargetStrategy targetStrategy, Set<Position> firePositions, Map<Position, List<Position>> neighbors) {
return targetStrategy.neighborClosestToFire(position, firePositions, neighbors);
}*/
public
Position
moveToBestPosition
(
Set
<
Position
>
firePositions
,
Map
<
Position
,
List
<
Position
>>
neighbors
,
Set
<
Position
>
mountains
)
{
Position
currentPosition
=
getPosition
();
Position
bestPosition
=
currentPosition
;
int
minDistance
=
Integer
.
MAX_VALUE
;
for
(
Position
neighbor
:
neighbors
.
get
(
currentPosition
))
{
if
(
mountains
.
contains
(
neighbor
))
continue
;
// Ignore les montagnes
// Rechercher le feu le plus proche depuis le voisin
for
(
Position
firePosition
:
firePositions
)
{
int
distance
=
Math
.
abs
(
firePosition
.
row
()
-
neighbor
.
row
())
+
Math
.
abs
(
firePosition
.
column
()
-
neighbor
.
column
());
if
(
distance
<
minDistance
)
{
minDistance
=
distance
;
bestPosition
=
neighbor
;
}
}
}
return
bestPosition
;
// Retourne la meilleure position parmi les voisines
}
public
void
extinguish
(
Position
position
,
Set
<
Position
>
firePositions
)
{
firePositions
.
remove
(
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