Skip to content
Snippets Groups Projects
Commit cac78e2b authored by Yanis O's avatar Yanis O Committed by melizzzz
Browse files

Changement de la logique de taille dans FireFighterScenario

parent 3f56cf62
No related branches found
No related tags found
No related merge requests found
package model; package model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import util.Matrix; import util.Matrix;
...@@ -8,19 +9,22 @@ import util.Position; ...@@ -8,19 +9,22 @@ import util.Position;
public class FireFighterScenario implements Board<Entity>{ public class FireFighterScenario implements Board<Entity>{
private Matrix<Entity> matrix private Matrix<Entity> matrix;
private int step;
public FireFighterScenario(int boardSize){ public FireFighterScenario(int boardSize){
this.matrix = new Matrix(); this.matrix = new Matrix<Entity>();
this.step = 0;
} }
public Entity getState(Position position){ public Entity getState(Position position){
if(position.x() > matrix.size() || position.y() > matrix.get(0).size()){ if(position.x() > matrix.size() || position.y() > matrix.size()){
throw new IllegalArgumentException("The position x:" + position.x() + " y:" + position.y() + " is out of the board."); throw new IllegalArgumentException("The position x:" + position.x() + " y:" + position.y() + " is out of the board.");
} }
return matrix.get(position.x()).get(position.y()); return matrix.get(position.x(), position.y());
} }
public void setState(Entity state, Position position){ public void setState(Entity state, Position position){
matrix.get(position.x()).set(position.y(), state);
matrix.set(position.x(), position.y(), state);
} }
...@@ -29,38 +33,33 @@ public class FireFighterScenario implements Board<Entity>{ ...@@ -29,38 +33,33 @@ public class FireFighterScenario implements Board<Entity>{
} }
public int columnCount(){ public int columnCount(){
return matrix.get(0).size(); return matrix.size(); // On considère que la matrice est toujours une matrice carré
} }
/**
* Update the board to its next generation or state. This method may modify the
* internal state of the board and return a list of positions that have changed
* during the update.
*
* @return A list of positions that have changed during the update.
*/
public List<Position> updateToNextGeneration() { public List<Position> updateToNextGeneration() {
for(ArrayList<Entity> l : matrix){ ArrayList<Position> changedPositions = new ArrayList<>();
for(Entity e : l){ Iterator<Entity> iterator = matrix.iterator();
while (iterator.hasNext()) {
Entity e = iterator.next();
Position p = new Position(e.getPosition().x(), e.getPosition().y());
e.nextTurn(this); e.nextTurn(this);
if (!e.getPosition().equals(p)) {
changedPositions.add(p);
} }
} }
return matrix; return changedPositions;
} }
/**
* Reset the board to its initial state.
*/
public void reset(){ public void reset(){
throw new IllegalStateException("Method not implemented"); matrix.clear();
} }
/**
* Get the current step number or generation of the board.
*
* @return The current step number or generation.
*/
public int stepNumber(){ public int stepNumber(){
return 0; return this.step;
} }
} }
...@@ -17,7 +17,7 @@ public class TargetStrategy { ...@@ -17,7 +17,7 @@ public class TargetStrategy {
* @param targets positions that are targeted. * @param targets positions that are targeted.
* @return the position next to the current position that is on the path to the closest target. * @return the position next to the current position that is on the path to the closest target.
*/ */
Position neighborClosestToFire(Position position, Collection<Position> targets, public Position neighborClosestToFire(Position position, Collection<Position> targets,
Map<Position,List<Position>>neighbors) { Map<Position,List<Position>>neighbors) {
Set<Position> seen = new HashSet<Position>(); Set<Position> seen = new HashSet<Position>();
HashMap<Position, Position> firstMove = new HashMap<Position, Position>(); HashMap<Position, Position> firstMove = new HashMap<Position, Position>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment