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
OUALAN Yanis
FirefighterStarter
Commits
79d86b7b
Commit
79d86b7b
authored
6 months ago
by
Yanis O
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de variants pour les Virus, qui rendent la guérison par les médecin plus compliquée
parent
8df52999
No related branches found
No related tags found
No related merge requests found
Pipeline
#41136
passed
6 months ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/model/doctorviruspatient/Doctor.java
+68
-23
68 additions, 23 deletions
src/main/java/model/doctorviruspatient/Doctor.java
src/main/java/model/doctorviruspatient/Virus.java
+10
-2
10 additions, 2 deletions
src/main/java/model/doctorviruspatient/Virus.java
with
78 additions
and
25 deletions
src/main/java/model/doctorviruspatient/Doctor.java
+
68
−
23
View file @
79d86b7b
package
model.doctorviruspatient
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
javafx.scene.paint.Color
;
...
...
@@ -13,10 +15,14 @@ import util.PositionUtil;
public
class
Doctor
implements
Entity
{
private
final
int
priority
=
1
;
Position
position
;
private
Position
position
;
private
int
age
;
private
final
Color
viewColor
=
Color
.
RED
;
// Statique car les médecins partagent les connaissances et les recherches
private
static
List
<
Integer
>
knownVirusVariant
=
new
ArrayList
<
Integer
>();
private
static
Map
<
Integer
,
Double
>
currentResearch
=
new
HashMap
<>();
// Map<variantId, % de recherche>
public
Doctor
(
Position
p
)
{
this
.
position
=
p
;
}
...
...
@@ -28,12 +34,39 @@ public class Doctor implements Entity {
@Override
public
List
<
Position
>
nextTurn
(
Board
<
Square
>
board
)
{
// Mettre à jour les recherches en cours
updateCurrentResearch
();
// Interagir avec les positions adjacentes
interactWithAdjacentPositions
(
PositionUtil
.
generateAllAdjacentPositions
(
position
,
board
),
board
);
return
List
.
of
();
}
/**
* Met à jour toutes les recherches en cours en augmentant leur avancement de x%.
* Si une recherche atteint ou dépasse 100%, elle est terminée.
*/
private
void
updateCurrentResearch
()
{
List
<
Integer
>
completedResearch
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
Integer
,
Double
>
entry
:
currentResearch
.
entrySet
())
{
int
variantId
=
entry
.
getKey
();
double
progress
=
entry
.
getValue
()
+
2.0
;
if
(
progress
>=
100.0
)
{
progress
=
100.0
;
completedResearch
.
add
(
variantId
);
}
currentResearch
.
put
(
variantId
,
progress
);
}
// Traiter les recherches complétées
for
(
int
variantId
:
completedResearch
)
{
currentResearch
.
remove
(
variantId
);
knownVirusVariant
.
add
(
variantId
);
System
.
out
.
println
(
"Recherche terminée pour le variant ID: "
+
variantId
);
}
}
private
List
<
Position
>
interactWithAdjacentPositions
(
List
<
Position
>
adjacentPositions
,
Board
<
Square
>
board
)
{
List
<
Position
>
result
=
new
ArrayList
<>();
...
...
@@ -47,13 +80,27 @@ private List<Position> interactWithAdjacentPositions(List<Position> adjacentPosi
private
void
handleEncounterWithPatient
(
Position
p
,
Board
<
Square
>
board
)
{
if
(
board
.
doesSquareContainEntity
(
p
,
Patient
.
class
))
{
Patient
patient
=
(
Patient
)
board
.
getStates
(
p
).
getEntities
().
stream
().
filter
(
e
->
e
instanceof
Patient
).
findFirst
().
get
();
if
(
patient
.
isInfected
()){
Patient
patient
=
(
Patient
)
board
.
getStates
(
p
).
getEntities
().
stream
()
.
filter
(
e
->
e
instanceof
Patient
)
.
findFirst
()
.
orElse
(
null
);
if
(
patient
!=
null
&&
patient
.
isInfected
())
{
Virus
virus
=
patient
.
getVirus
();
if
(
virus
!=
null
)
{
int
variantId
=
virus
.
getVariantId
();
if
(
knownVirusVariant
.
contains
(
variantId
))
{
patient
.
cure
();
}
else
{
// Si la variante n'est pas connue et pas en cours de recherche, l'ajouter à la recherche
if
(!
currentResearch
.
containsKey
(
variantId
))
{
currentResearch
.
put
(
variantId
,
0.0
);
System
.
out
.
println
(
"Nouvelle variante détectée! Variant ID: "
+
variantId
+
". Recherche commencée."
);
}
}
}
}
}
}
@Override
public
Position
getPosition
()
{
...
...
@@ -63,7 +110,6 @@ private void handleEncounterWithPatient(Position p, Board<Square> board) {
@Override
public
void
setPosition
(
Position
p
)
{
this
.
position
=
p
;
}
@Override
...
...
@@ -91,20 +137,19 @@ private void handleEncounterWithPatient(Position p, Board<Square> board) {
return
this
.
priority
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
instanceof
Doctor
)
{
Doctor
other
=
(
Doctor
)
obj
;
return
this
.
position
==
other
.
getPosition
();
return
this
.
position
.
equals
(
other
.
getPosition
()
)
;
}
else
{
return
false
;
}
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
position
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/model/doctorviruspatient/Virus.java
+
10
−
2
View file @
79d86b7b
...
...
@@ -2,6 +2,7 @@ package model.doctorviruspatient;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Random
;
import
javafx.scene.paint.Color
;
import
model.Board
;
...
...
@@ -42,7 +43,7 @@ public class Virus implements Entity {
@Override
public
List
<
Position
>
nextTurn
(
Board
<
Square
>
board
)
{
if
(
board
.
getStepNumber
()
%
5
0
==
0
){
if
(
board
.
getStepNumber
()
%
10
0
==
0
){
evolve
();
}
// Génère un nouveau chemin si nécessaire
...
...
@@ -94,8 +95,15 @@ public class Virus implements Entity {
// Les autres méthodes restent inchangées
private
void
evolve
(){
this
.
variantId
++;
Random
r
=
new
Random
();
this
.
health
=
r
.
nextInt
(
100
);
}
public
int
getVariantId
(){
return
this
.
variantId
;
}
@Override
public
Position
getPosition
()
{
return
this
.
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