Skip to content
Snippets Groups Projects
Commit daf3602c authored by BACHTARZI Imed eddine's avatar BACHTARZI Imed eddine
Browse files

made test for some classes.

made the javaDoc for all interfaces and some classes.
modified the UML diagrams.
Final commit.
parent 65dbe78a
No related branches found
No related tags found
No related merge requests found
Showing
with 494 additions and 39 deletions
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - Package model</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>Package model</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt; model</div>
<div id="summary">
<table>
<tr>
<td>
<div class="summaryGroup">
<table>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">3</div>
<p>tests</p>
</div>
</td>
<td>
<div class="infoBox" id="failures">
<div class="counter">0</div>
<p>failures</p>
</div>
</td>
<td>
<div class="infoBox" id="ignored">
<div class="counter">0</div>
<p>ignored</p>
</div>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.100s</div>
<p>duration</p>
</div>
</td>
</tr>
</table>
</div>
</td>
<td>
<div class="infoBox success" id="successRate">
<div class="percent">100%</div>
<p>successful</p>
</div>
</td>
</tr>
</table>
</div>
<div id="tabs">
<ul class="tabLinks">
<li>
<a href="#tab0">Classes</a>
</li>
</ul>
<div id="tab0" class="tab">
<h2>Classes</h2>
<table>
<thead>
<tr>
<th>Class</th>
<th>Tests</th>
<th>Failures</th>
<th>Ignored</th>
<th>Duration</th>
<th>Success rate</th>
</tr>
</thead>
<tr>
<td class="success">
<a href="../classes/model.ChargerBehaviorTest.html">ChargerBehaviorTest</a>
</td>
<td>3</td>
<td>0</td>
<td>0</td>
<td>0.100s</td>
<td class="success">100%</td>
</tr>
</table>
</div>
</div>
<div id="footer">
<p>
<div>
<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 8.10.2</a> at 29 nov. 2024, 22:12:59</p>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="model.ChargerBehaviorTest" tests="3" skipped="0" failures="0" errors="0" timestamp="2024-11-29T21:12:59" hostname="DESKTOP-ETSE1TF" time="0.102">
<properties/>
<testcase name="testChargerBehaviorForTwoFires()" classname="model.ChargerBehaviorTest" time="0.096"/>
<testcase name="testChargerBehaviorForOneFire()" classname="model.ChargerBehaviorTest" time="0.002"/>
<testcase name="testChargerBehaviorForOneQuickFire()" classname="model.ChargerBehaviorTest" time="0.002"/>
<system-out><![CDATA[]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>
File added
File added
model(complex).png

699 KiB | W: | H:

model(complex).png

1.86 MiB | W: | H:

model(complex).png
model(complex).png
model(complex).png
model(complex).png
  • 2-up
  • Swipe
  • Onion skin
model(simple).png

607 KiB | W: | H:

model(simple).png

178 KiB | W: | H:

model(simple).png
model(simple).png
model(simple).png
model(simple).png
  • 2-up
  • Swipe
  • Onion skin
...@@ -4,11 +4,37 @@ import util.Position; ...@@ -4,11 +4,37 @@ import util.Position;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* Interface defining the behavior of elements on a board.
* Provides methods for updating elements and determining legal neighboring positions.
*/
public interface Behavior { public interface Behavior {
/**
* Update the state of an element when placed on the board.
*
* @param boardData The current state of the board.
* @param element The element to update.
* @return A list of positions representing where the new generation of elements is located.
*/
public List<Position> update(BoardData boardData, Element element); public List<Position> update(BoardData boardData, Element element);
/**
* Get a list of neighboring positions that are legal for an element to occupy.
*
* @param boardData The current state of the board.
* @param position The current position of the element.
* @return A list of neighboring positions that are considered legal for the element.
*/
public List<Position> legalNeighbors(BoardData boardData, Position position); public List<Position> legalNeighbors(BoardData boardData, Position position);
/**
* Get a map of all neighboring positions on the board where movement is legal.
* Each key in the map represents a position, and the corresponding value is a list
* of legal neighboring positions for that position.
*
* @param boardData The current state of the board.
* @return A map where each key is a position, and the value is a list of legal neighboring positions.
*/
public Map<Position, List<Position>> allLegalNeighbors(BoardData boardData); public Map<Position, List<Position>> allLegalNeighbors(BoardData boardData);
} }
\ No newline at end of file
...@@ -6,16 +6,94 @@ import util.Position; ...@@ -6,16 +6,94 @@ import util.Position;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* Interface representing a generic board or grid structure.
* Provides methods to interact with the board elements, neighbors, and state.
*/
public interface BoardData { public interface BoardData {
/**
* Get all elements on the board as a 2D list.
*
* @return A list of lists representing the elements on the board.
* Each sublist corresponds to a row.
*/
public List<List<Element>> getElements(); public List<List<Element>> getElements();
/**
* Get the cell at a specific position on the board.
*
* @param position The position of the cell to retrieve.
* @return The cell containing the element at the specified position.
*/
public Cell<Element> getCell(Position position); public Cell<Element> getCell(Position position);
/**
* Add an element to the board.
*
* @param element The element to add to the board.
* @return True if the element was successfully added, false otherwise.
*/
public Boolean addElement(Element element); public Boolean addElement(Element element);
/**
* Remove an element from the board.
*
* @param element The element to remove from the board.
*/
public void removeElement(Element element); public void removeElement(Element element);
/**
* Get a map of all positions on the board to their respective neighbors.
*
* @return A map where each key is a position on the board, and the value is a list of neighboring positions.
*/
public Map<Position, List<Position>> getNeighbors(); public Map<Position, List<Position>> getNeighbors();
/**
* Get the neighbors of a specific position on the board.
*
* @param position The position for which to retrieve the neighbors.
* @return A list of neighboring positions.
*/
public List<Position> getNeighbor(Position position); public List<Position> getNeighbor(Position position);
/**
* Get the current step of the board.
*
* This is typically used in simulations or games to track progression.
*
* @return The current step.
*/
public int getStep(); public int getStep();
/**
* Set the current step of the board.
*
* @param step The step value to set.
*/
public void setStep(int step); public void setStep(int step);
/**
* Initialize the board.
*
* This method prepares the board for use, potentially placing initial elements
* or resetting its state.
*/
public void initialize(); public void initialize();
/**
* Get the number of columns in the board.
*
* @return The number of columns.
*/
public int getColumnCount(); public int getColumnCount();
/**
* Get the number of rows in the board.
*
* @return The number of rows.
*/
public int getRowCount(); public int getRowCount();
} }
...@@ -2,10 +2,32 @@ package model; ...@@ -2,10 +2,32 @@ package model;
import model.firefighter.ModelElement; import model.firefighter.ModelElement;
import util.Position; import util.Position;
/**
* Interface representing an element on the board.
* Provides methods for retrieving the position, type, and behavior of the element.
*/
public interface Element { public interface Element {
/**
* Get the position of the element on the board.
*
* @return The position of the element on the board.
*/
Position getPosition(); Position getPosition();
/**
* Get the type of the element.
* This typically represents the classification or kind of element (e.g., a specific object or unit).
*
* @return The type of the element as a {@code ModelElement}.
*/
ModelElement getType(); ModelElement getType();
Behavior getBehavior();
/**
* Get the behavior of the element.
* This defines how the element interacts with the board and other elements.
*
* @return The behavior associated with the element.
*/
Behavior getBehavior();
} }
\ No newline at end of file
...@@ -5,7 +5,18 @@ import util.Position; ...@@ -5,7 +5,18 @@ import util.Position;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* Factory interface for creating new elements on a board.
* Provides a method to generate elements at a specific position on the board.
*/
public interface ElementFactory { public interface ElementFactory {
public Element getNewElement(BoardData boardData, Position position);
/**
* Create a new element for the board at a specific position.
*
* @param boardData The current state of the board where the new element will be placed.
* @param position The position on the board where the new element should be created.
* @return A new instance of an {@code Element} to be added to the board.
*/
public Element getNewElement(BoardData boardData, Position position);
} }
\ No newline at end of file
...@@ -4,8 +4,17 @@ import util.Position; ...@@ -4,8 +4,17 @@ import util.Position;
import java.util.List; import java.util.List;
/**
* Interface for updating all elements on the board.
* Provides a method to update all elements based on the current state of the board.
*/
public interface Updater { public interface Updater {
/**
* Update all elements on the board based on the current state.
*
* @param boardData The current state of the board to use for updating elements.
* @return A list of positions where the elements have been updated or changed.
*/
public List<Position> updateAll(BoardData boardData); public List<Position> updateAll(BoardData boardData);
} }
\ No newline at end of file
package model.elementTokens; package model.elementTokens;
/**
* Interface for elements that have a chargeable counter.
* Provides methods for managing the charge state of the element.
*/
public interface Chargable { public interface Chargable {
/**
* Get the current value of the charge counter.
*
* @return The current counter value, representing the charge level of the element.
*/
public int getCounter(); public int getCounter();
/**
* Increment the charge counter by one.
* Typically used to increase the charge level of the element.
*/
public void incrementCounter(); public void incrementCounter();
/**
* Reset the charge counter to zero.
* This method can be used to fully discharge the element.
*/
public void resetCounter(); public void resetCounter();
/**
* Check if the element is fully charged.
*
* @return {@code true} if the element is fully charged, {@code false} otherwise.
*/
public boolean isCharged(); public boolean isCharged();
} }
package model.elementTokens; package model.elementTokens;
/**
* Interface for elements that can be charged, extending the {@link Chargable} interface.
* This interface marks the element as a target for charging operations.
*/
public interface ChargeTarget extends Chargable { public interface ChargeTarget extends Chargable {
} }
...@@ -3,6 +3,19 @@ package model.elementTokens; ...@@ -3,6 +3,19 @@ package model.elementTokens;
import model.Element; import model.Element;
import model.ElementFactory; import model.ElementFactory;
/**
* Interface représentant un élément du modèle qui peut être associé à une fabrique d'éléments.
* <p>
* Cette interface étend l'interface {@link Element} et ajoute la capacité de fournir une fabrique
* qui peut être utilisée pour créer de nouveaux éléments similaires à celui qui l'implémente.
* </p>
*/
public interface ConnexElement extends Element { public interface ConnexElement extends Element {
/**
* Récupère la fabrique associée à cet élément.
*
* @return La fabrique qui peut être utilisée pour créer de nouveaux éléments du même type.
*/
public ElementFactory getFactory(); public ElementFactory getFactory();
} }
...@@ -4,6 +4,15 @@ import util.Position; ...@@ -4,6 +4,15 @@ import util.Position;
import java.util.List; import java.util.List;
/**
* Interface marquant un élément qui peut être imprimé ou affiché.
* <p>
* Cette interface sert à identifier les éléments qui ont un comportement d'affichage spécifique,
* comme les éléments qui peuvent être rendus graphiquement ou textuellement.
* Elle ne contient aucune méthode, mais son but est de marquer les éléments
* pouvant être imprimés ou affichés dans une vue.
* </p>
*/
public interface Printable { public interface Printable {
} }
...@@ -5,6 +5,25 @@ import util.Position; ...@@ -5,6 +5,25 @@ import util.Position;
import java.util.List; import java.util.List;
/**
* Interface représentant un élément pouvant être mis à jour sur le plateau.
* <p>
* Cette interface définit la méthode nécessaire pour permettre à un élément d'être mis à jour
* à chaque étape du jeu ou à chaque cycle de simulation. L'élément met à jour son état en fonction
* des données du plateau.
* </p>
*/
public interface Updatable { public interface Updatable {
/**
* Met à jour l'état de l'élément sur le plateau.
* <p>
* Cette méthode permet à l'élément d'effectuer ses propres mises à jour en fonction des données
* du plateau de jeu. Elle est généralement appelée à chaque étape du jeu ou de la simulation.
* </p>
*
* @param boardData Les données du plateau de jeu qui sont utilisées pour la mise à jour de l'élément.
* @return Une liste des positions qui ont été modifiées par cette mise à jour.
*/
public List<Position> updateSelf(BoardData boardData); public List<Position> updateSelf(BoardData boardData);
} }
...@@ -6,6 +6,24 @@ import util.Position; ...@@ -6,6 +6,24 @@ import util.Position;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* Interface représentant un élément qui dépend d'une zone spécifique pour sa création.
* <p>
* Cette interface est utilisée pour des éléments dont la création ou le comportement
* est influencé ou lié à une zone particulière du plateau. Elle fournit un moyen d'obtenir
* une fabrique associée pour la création de nouveaux éléments dépendant de cette zone.
* </p>
*/
public interface ZoneDependent { public interface ZoneDependent {
/**
* Récupère la fabrique associée à cet élément.
* <p>
* Cette fabrique est utilisée pour créer de nouveaux éléments en fonction de la zone
* dans laquelle l'élément actuel se trouve ou de toute autre logique spécifique à la zone.
* </p>
*
* @return La fabrique associée à cet élément.
*/
public ElementFactory getFactory(); public ElementFactory getFactory();
} }
...@@ -7,23 +7,58 @@ import util.Position; ...@@ -7,23 +7,58 @@ import util.Position;
import java.util.*; import java.util.*;
/**
* Classe représentant les données d'un plateau de jeu dans le modèle de simulation de pompiers.
* <p>
* Cette classe gère l'état du plateau, y compris la position des éléments, les voisins d'une case,
* et les actions liées au placement et à la suppression des éléments.
* </p>
*/
public class FFBoardData implements BoardData { public class FFBoardData implements BoardData {
/** Liste des éléments répartis sur le plateau par type d'élément. */
private List<List<Element>> elementList; private List<List<Element>> elementList;
private Map<Position, List<Position>> neighbors = new HashMap<Position, List<Position>>();
/** Carte des voisins pour chaque position sur le plateau. */
private Map<Position, List<Position>> neighbors = new HashMap<>();
/** Étape actuelle du jeu. */
private int step; private int step;
public int columnCount,rowCount;
/** Nombre de colonnes du plateau. */
public int columnCount;
/** Nombre de lignes du plateau. */
public int rowCount;
/** Liste des cellules représentant chaque position du plateau. */
private List<List<Cell<Element>>> cells; private List<List<Cell<Element>>> cells;
/**
* Constructeur de la classe {@link FFBoardData}.
* <p>
* Initialise un plateau avec le nombre spécifié de lignes et de colonnes.
* </p>
*
* @param columnCount Nombre de colonnes du plateau.
* @param rowCount Nombre de lignes du plateau.
*/
public FFBoardData(int columnCount, int rowCount) { public FFBoardData(int columnCount, int rowCount) {
this.columnCount = columnCount; this.columnCount = columnCount;
this.rowCount = rowCount; this.rowCount = rowCount;
initialize(); initialize();
} }
/**
* Initialise les données du plateau : positionnement des cases, voisins, et liste d'éléments.
*/
public void initialize() { public void initialize() {
step = 0; step = 0;
neighbors = new HashMap<Position, List<Position>>(); neighbors = new HashMap<>();
Position[][] ps = new Position[rowCount][columnCount]; Position[][] ps = new Position[rowCount][columnCount];
cells = new ArrayList<>(); cells = new ArrayList<>();
// Initialisation des cellules et positions
for (int column = 0; column < columnCount; column++) { for (int column = 0; column < columnCount; column++) {
cells.add(new ArrayList<>()); cells.add(new ArrayList<>());
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++) {
...@@ -31,7 +66,9 @@ public class FFBoardData implements BoardData { ...@@ -31,7 +66,9 @@ public class FFBoardData implements BoardData {
cells.get(column).add(new Cell<>(ps[row][column])); cells.get(column).add(new Cell<>(ps[row][column]));
} }
} }
for (int column = 0; column < columnCount; column++)
// Initialisation des voisins pour chaque position
for (int column = 0; column < columnCount; column++) {
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++) {
List<Position> list = new ArrayList<>(); List<Position> list = new ArrayList<>();
if (row > 0) list.add(ps[row - 1][column]); if (row > 0) list.add(ps[row - 1][column]);
...@@ -40,6 +77,9 @@ public class FFBoardData implements BoardData { ...@@ -40,6 +77,9 @@ public class FFBoardData implements BoardData {
if (column < columnCount - 1) list.add(ps[row][column + 1]); if (column < columnCount - 1) list.add(ps[row][column + 1]);
getNeighbors().put(ps[row][column], list); getNeighbors().put(ps[row][column], list);
} }
}
// Initialisation de la liste des éléments pour chaque type d'élément
elementList = new ArrayList<>(); elementList = new ArrayList<>();
for (int i = 0; i < ModelElement.values().length; i++) { for (int i = 0; i < ModelElement.values().length; i++) {
elementList.add(new ArrayList<>()); elementList.add(new ArrayList<>());
...@@ -56,14 +96,21 @@ public class FFBoardData implements BoardData { ...@@ -56,14 +96,21 @@ public class FFBoardData implements BoardData {
return rowCount; return rowCount;
} }
@Override @Override
public List<List<Element>> getElements() { public List<List<Element>> getElements() {
return elementList; return elementList;
} }
/**
* Récupère la cellule correspondant à une position donnée.
*
* @param position La position pour laquelle récupérer la cellule.
* @return La cellule correspondant à la position donnée.
*/
public Cell<Element> getCell(Position position) { public Cell<Element> getCell(Position position) {
return cells.get(position.column()).get(position.row()); return cells.get(position.column()).get(position.row());
} }
@Override @Override
public int getStep() { public int getStep() {
return step; return step;
...@@ -73,27 +120,52 @@ public class FFBoardData implements BoardData { ...@@ -73,27 +120,52 @@ public class FFBoardData implements BoardData {
public void setStep(int step) { public void setStep(int step) {
this.step = step; this.step = step;
} }
@Override
public Map<Position, List<Position>> getNeighbors() { public Map<Position, List<Position>> getNeighbors() {
return neighbors; return neighbors;
} }
@Override
public List<Position> getNeighbor(Position position) { public List<Position> getNeighbor(Position position) {
return neighbors.get(position); return neighbors.get(position);
} }
/**
* Ajoute un élément au plateau à la position de l'élément.
* <p>
* Avant d'ajouter l'élément, la méthode vérifie si la position est légale en fonction du comportement de l'élément.
* Si l'élément a un comportement tangible, sa légalité est vérifiée via la méthode {@link TangibleBehavior#isLegal(BoardData, Position)}.
* </p>
*
* @param element L'élément à ajouter au plateau.
* @return {@code true} si l'élément a été ajouté avec succès, {@code false} sinon.
*/
public Boolean addElement(Element element) { public Boolean addElement(Element element) {
if(element==null){ return false;} if (element == null) {
if (element.getBehavior()!=null)
if (element.getBehavior() instanceof TangibleBehavior<?>)
if (!((TangibleBehavior)element.getBehavior()).isLegal(this,element.getPosition()))
return false; return false;
}
if (element.getBehavior() != null) {
if (element.getBehavior() instanceof TangibleBehavior<?>) {
if (!((TangibleBehavior) element.getBehavior()).isLegal(this, element.getPosition())) {
return false;
}
}
}
elementList.get(element.getType().ordinal()).add(element); elementList.get(element.getType().ordinal()).add(element);
getCell(element.getPosition()).Content.add(element); getCell(element.getPosition()).Content.add(element);
FFUpdater.modifiedPositions.add(element.getPosition()); FFUpdater.modifiedPositions.add(element.getPosition());
return true; return true;
} }
/**
* Supprime un élément du plateau.
*
* @param element L'élément à supprimer.
*/
public void removeElement(Element element) { public void removeElement(Element element) {
FFUpdater.modifiedPositions.add(element.getPosition()); FFUpdater.modifiedPositions.add(element.getPosition());
elementList.get(element.getType().ordinal()).remove(element); elementList.get(element.getType().ordinal()).remove(element);
getCell(element.getPosition()).Content.remove(element); getCell(element.getPosition()).Content.remove(element);
} }
} }
...@@ -9,25 +9,61 @@ import util.Position; ...@@ -9,25 +9,61 @@ import util.Position;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Classe responsable de la mise à jour des éléments dans le modèle de simulation de lutte contre les incendies.
* Elle implémente l'interface {@link Updater} et gère une liste d'éléments {@link Updatable} pour effectuer
* des mises à jour sur le plateau de jeu.
* <p>
* Cette classe est utilisée pour coordonner les mises à jour des éléments du modèle en appelant la méthode
* {@link Updatable#updateSelf(BoardData)} sur chaque élément qui peut être mis à jour.
* </p>
*/
public class FFUpdater implements Updater { public class FFUpdater implements Updater {
List<Updatable> updatables;
/** Liste des éléments pouvant être mis à jour. */
private List<Updatable> updatables;
/** Liste des positions qui ont été modifiées durant la mise à jour. */
static List<Position> modifiedPositions = new ArrayList<>(); static List<Position> modifiedPositions = new ArrayList<>();
/**
* Constructeur qui initialise la liste des éléments à mettre à jour.
*/
public FFUpdater() { public FFUpdater() {
updatables = new ArrayList<>(); updatables = new ArrayList<>();
} }
/**
* Prépare la liste des éléments à mettre à jour et réinitialise les positions modifiées.
* Cette méthode parcourt les éléments du modèle pour ajouter ceux qui sont de type {@link Updatable}
* à la liste {@code updatables}. Elle réinitialise également la liste des positions modifiées.
*
* @param boardData L'état actuel du plateau de jeu utilisé pour récupérer les éléments à mettre à jour.
*/
public void updateSetup(BoardData boardData) { public void updateSetup(BoardData boardData) {
updatables.clear(); updatables.clear();
modifiedPositions=new ArrayList<Position>(); modifiedPositions = new ArrayList<>();
// Parcours de tous les éléments du modèle pour vérifier ceux qui sont updatables
for (ModelElement modelElement : ModelElement.values()) { for (ModelElement modelElement : ModelElement.values()) {
if (modelElement.isUpdatable()) if (modelElement.isUpdatable()) {
for (Element e : boardData.getElements().get(modelElement.ordinal())) { for (Element e : boardData.getElements().get(modelElement.ordinal())) {
updatables.add((Updatable) e); updatables.add((Updatable) e);
} }
} }
} }
}
/**
* Effectue la mise à jour de tous les éléments sur le plateau de jeu.
* <p>
* Cette méthode appelle {@link Updatable#updateSelf(BoardData)} pour chaque élément {@link Updatable},
* puis retourne une liste des positions qui ont été modifiées durant la mise à jour.
* </p>
*
* @param boardData L'état actuel du plateau de jeu utilisé pour effectuer la mise à jour des éléments.
* @return Une liste des positions qui ont été modifiées durant la mise à jour des éléments.
*/
@Override @Override
public List<Position> updateAll(BoardData boardData) { public List<Position> updateAll(BoardData boardData) {
updateSetup(boardData); updateSetup(boardData);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment