Skip to content
Snippets Groups Projects
Commit 3f6a814e authored by MAAZOUZ Ilyas's avatar MAAZOUZ Ilyas
Browse files

dsfsdfsd

parent ab1b1ea5
No related branches found
No related tags found
No related merge requests found
Pipeline #24892 passed
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -2,5 +2,5 @@ package model;
//this class represents two types of constant Firefighter or fire
public enum ModelElement {
FIREFIGHTER, FIRE
FIREFIGHTER, FIRE ,
}
package newmodel;
import model.ModelElement;
import util.Position;
import view.ViewElement;
import java.util.*;
......@@ -31,12 +31,12 @@ public class Fboard {
public List<Position> updateToNextGeneration() {
List<Position> result = new ArrayList<>();
for(item item : items){
if(item.getID()==1){
if(item.getID()==1 && step % 2 ==0){
result.addAll(item.update(this));
}
}
for(item item : items){
if(item.getID()==0 && step % 2 ==0){
if(item.getID()==0){
result.addAll(item.update(this));
}
}
......@@ -53,12 +53,12 @@ public class Fboard {
}
public void initializeElements() {
for(item e: items) {
if(e.getID()==0){
if(e.getID()==1){
e.initialize();
}
}
for(item e:items){
if(e.getID()==1){
if(e.getID()==0){
e.initialize();
}
}
......@@ -67,7 +67,7 @@ public class Fboard {
public Fire getFire() {
Fire x = null;
for (item e : items) {
if (e.getID() == 0) {
if (e.getID() == 1) {
x = (Fire) e;
break;
}
......@@ -86,7 +86,7 @@ public class Fboard {
public Position neighborClosestToFire(Position position) {
Set<Position> seen = new HashSet<>();
HashMap<Position, Position> firstMove = new HashMap<>();
Queue<Position> toVisit = new LinkedList<>(this.neighbors(position)); //Queue is initialised with the neighbors of position
Queue<Position> toVisit = new LinkedList<>(this.neighbors(position));
for (Position initialMove : toVisit)
firstMove.put(initialMove, initialMove);
while (!toVisit.isEmpty()) {
......@@ -103,14 +103,19 @@ public class Fboard {
return position;
}
public List<ModelElement> getState(Position position){
List<ModelElement> result = new ArrayList<>();
for (item e :items) {
if (e.getPositions().contains(position) && e.getID() == 1) {
result.add(e.getState());break;
result.add(e.getState());
}
}
for (item e :items) {
if (e.getPositions().contains(position) && e.getID() == 0) {
result.add(e.getState());
}
if (e.getPositions().contains(position) && e.getID() == 0)
result.add(getFire().getState());break;
}
return result;
}
......
......@@ -13,7 +13,7 @@ public class Fire implements item {
private final ModelElement state;
private final Random randomGenerator = new Random();
private final int ID=0;
private final int ID=1;
public Fire(int initialFireCount) {
this.initialFireCount = initialFireCount;
......@@ -27,7 +27,7 @@ public class Fire implements item {
newFirePositions.addAll(board.neighbors(fire));
}
firePositions.addAll(newFirePositions);
return newFirePositions;
return firePositions;
}
......@@ -45,7 +45,7 @@ public class Fire implements item {
firePositions.add(randomPosition());
}
@Override
public List<Position> getPositions() {
return firePositions;
}
......
......@@ -4,7 +4,7 @@ import util.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import model.ModelElement;
public class FireFighter extends Extinguisher {
private final ModelElement state;
......@@ -13,7 +13,7 @@ public class FireFighter extends Extinguisher {
private final int initialFirefighterCount;
private int ID=1;
private final int ID=0;
public FireFighter(int initialFirefighterCount){
this.initialFirefighterCount=initialFirefighterCount;
......@@ -22,25 +22,26 @@ public class FireFighter extends Extinguisher {
public List<Position> update(Fboard board) {
List<Position> result = new ArrayList<>();
List<Position> modifiedPosition = new ArrayList<>();
List<Position> firefighterNewPositions = new ArrayList<>();
for (Position firefighterPosition : firefighterPositions) {
Position newFirefighterPosition = board.neighborClosestToFire(firefighterPosition);
firefighterNewPositions.add(newFirefighterPosition);
extinguish(newFirefighterPosition,board);
result.add(firefighterPosition);
result.add(newFirefighterPosition);
modifiedPosition.add(firefighterPosition);
modifiedPosition.add(newFirefighterPosition);
List<Position> neighborFirePositions = board.neighbors(newFirefighterPosition).stream()
.filter(board.getFire().getPositions()::contains).toList(); //this code create a list filtred with only the fire positions that are close to the newfirefighter position
for(Position firePosition : neighborFirePositions) //and exist in the firepositions list also
.filter(board.getFire().getPositions()::contains).toList();
for(Position firePosition : neighborFirePositions)
extinguish(firePosition,board);
result.addAll(neighborFirePositions);
modifiedPosition.addAll(neighborFirePositions);
}
firefighterPositions = firefighterNewPositions;
return result;
return modifiedPosition;
}
public void extinguish(Position position,Fboard board) {
board.getFire().extinguish(position);
}
......@@ -52,7 +53,6 @@ public class FireFighter extends Extinguisher {
// implementi liha pattern visiteur
public int getID() {
return this.ID;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment