Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • variant
2 results

Target

Select target project
  • l22015417/firefighterstarter
  • m19023837/firefighter-starter-mansour-chadi-chahine-rami
  • r24025701/firefighterstarter
  • n24026202/firefighterstarter
  • couetoux.b/firefighterstarter
  • b23027938/firefighterstarter
  • z20039716/fire-fighter
  • a18023913/firefighterstarter
  • o22010261/firefighterstarter
  • b22015516/firefighterstarter
  • alaboure/firefighter-template
  • p21211679/firefighter-luis-parra-yanis-lounadi
  • v23014723/firefighter-project
  • k20014011/firefighter-template
  • m23022217/firefighter-template
  • p20006624/firefighter-template
  • l21221596/firefighter-template
  • s21232465/firefighter-template
  • y21224754/firefighter-template
  • w21225935/firefighter-template
  • h22023886/firefighter-template
  • b21221604/firefighter-template-boucenna-yacine-zeghar-mohamed-lamine
  • c23025119/firefighterstarter
  • b20031964/firefighterstarter
24 results
Select Git revision
  • main
  • variant
2 results
Show changes
package model;
public enum ModelElement {
FIREFIGHTER, FIRE
}
......@@ -4,5 +4,6 @@ module firefighter {
requires javafx.graphics;
opens controller to javafx.fxml;
exports app;
exports view;
opens app to javafx.fxml;
}
package util;
import model.Board.Board;
import java.util.*;
public class Neighbour {
private final Random randomGenerator = new Random();
private final Map<Position, List<Position>> neighbors = new HashMap<>();
Board board;
public Neighbour(Board board){
this.board = board;
initializeNeighbour();
}
private void initializeNeighbour(){
for (int column = 0; column < board.columnCount(); column++) {
for (int row = 0; row < board.rowCount(); row++) {
neighbors.put(new Position(row,column), calculateNeighbors(row, column));
}
}
}
public List<Position> calculateNeighbors(int row, int column) {
List<Position> list = new ArrayList<>();
if (row > 0) list.add(new Position(row-1,column));
if (column > 0) list.add(new Position(row,column-1));
if (row < board.rowCount() - 1) list.add(new Position(row+1,column));
if (column < board.columnCount() - 1) list.add(new Position(row,column+1));
return list;
}
public Position randomNeighbor(Position position) {
List<Position> neighborPositions = neighbors.get(position);
return neighborPositions.get(randomGenerator.nextInt(neighborPositions.size()));
}
public Map<Position, List<Position>> getNeighbors() {
return this.neighbors;
}
}
......@@ -2,4 +2,5 @@ package util;
public record Position(int row, int column) {
}
package model;
package util;
import util.Position;
......@@ -12,7 +12,7 @@ public class TargetStrategy {
* @param targets positions that are targeted.
* @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) {
Set<Position> seen = new HashSet<Position>();
HashMap<Position, Position> firstMove = new HashMap<Position, Position>();
......
......@@ -10,8 +10,10 @@ import java.util.List;
public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
private void paintElementAtPosition(ViewElement element, Position position) {
System.out.println("Painting " + element + " at " + position);
paintBox(position.row(), position.column(), element.color);
}
private int boxWidth;
private int boxHeight;
private int columnCount;
......
......@@ -3,7 +3,15 @@ package view;
import javafx.scene.paint.Color;
public enum ViewElement {
FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE);
FIREFIGHTER(Color.BLUE),
FIRE(Color.RED),
CLOUD(Color.LIGHTSKYBLUE),
ROAD(Color.BLACK),
MOUNTAIN(Color.BROWN),
ROCAILLE(Color.GRAY),
MOTORIZEDFIREFIGHTER(Color.PURPLE),
EMPTY(Color.WHITE);
final Color color;
ViewElement(Color color) {
this.color = color;
......
package model;
import model.Board.Board;
import model.Board.FirefighterBoard;
import model.Elements.ModelElement;
import org.junit.jupiter.api.Test;
import util.Position;
......@@ -10,17 +13,17 @@ import static org.assertj.core.api.Assertions.*;
public class FirefighterBoardTest {
@Test
void testColumnCount(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3);
Board<List<ModelElement>> board = new FirefighterBoard(20, 10);
assertThat(board.columnCount()).isEqualTo(20);
}
@Test
void testRowCount(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3);
Board<List<ModelElement>> board = new FirefighterBoard(20, 10);
assertThat(board.rowCount()).isEqualTo(10);
}
@Test
void testStepNumber(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3);
Board<List<ModelElement>> board = new FirefighterBoard(20, 10);
for(int index = 0; index < 10; index++){
assertThat(board.stepNumber()).isEqualTo(index);
board.updateToNextGeneration();
......@@ -29,7 +32,7 @@ public class FirefighterBoardTest {
}
@Test
void testGetState_afterSet(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 0, 0);
Board<List<ModelElement>> board = new FirefighterBoard(20, 10);
Position position = new Position(1,2);
assertThat(board.getState(position)).isEmpty();
board.setState(List.of(ModelElement.FIRE), position);
......