Skip to content
Snippets Groups Projects
Commit 27a8ce52 authored by Anthony Viola's avatar Anthony Viola
Browse files

Firefighter rebuild finished

parent c6c509e0
No related branches found
No related tags found
No related merge requests found
Pipeline #24653 passed
......@@ -17,10 +17,10 @@ public class SimulatorApplication extends javafx.application.Application {
private static final int COLUMN_COUNT = 20;
private static final int SQUARE_WIDTH = 50;
private static final int SQUARE_HEIGHT = 50;
public static final int INITIAL_FIRE_COUNT = 3;
public static final int INITIAL_FIREFIGHTER_COUNT = 0;
public static final int INITIAL_FIRE_COUNT = 1;
public static final int INITIAL_FIREFIGHTER_COUNT = 4;
public static final int INITIAL_CLOUD_COUNT = 3;
public static final int INITIAL_CLOUD_COUNT = 4;
private Stage primaryStage;
private Parent view;
......
......@@ -73,7 +73,7 @@ public class Controller {
}
private void updateBoard2(){
board.testScreen();
List<Position> updatedPositions = board.updateToNextGeneration2();
List<Position> updatedClearSquares = new ArrayList<>();
List<Item> updatedSquares = new ArrayList<>();
......@@ -86,6 +86,7 @@ public class Controller {
}
grid.repaint2(updatedSquares, updatedClearSquares);
updateGenerationLabel(board.stepNumber());
//board.testScreen();
}
private void repaintGrid(){
......
......@@ -16,18 +16,19 @@ public class Cloud extends Extinguisher implements Item {
List<Position> move(FirefighterBoard board) {
List<Position> result = new ArrayList<>();
List<Position> finalNeighborsList = new ArrayList<>();
List<Position> neighborsList = board.neighbors(position);
for (Position neighborPosition: neighborsList) {
if (board.getItemByPosition(neighborPosition) != null){
neighborsList.remove(neighborPosition);
if (board.getItemByPosition(neighborPosition) == null){
finalNeighborsList.add(neighborPosition);
}
}
if (neighborsList.isEmpty()){
return null;
if (finalNeighborsList.isEmpty()){
return new ArrayList<Position>();
}
Random ran = new Random();
result.add(position);
position = neighborsList.get(ran.nextInt(neighborsList.size()));
position = finalNeighborsList.get(ran.nextInt(finalNeighborsList.size()));
result.add(position);
return result;
}
......
......@@ -22,7 +22,7 @@ public class Firefighter extends Extinguisher implements Item{
firstMove.put(initialMove, initialMove);
toVisit.add(initialMove);
}
if (board.getItemByPosition(initialMove) instanceof Fire) return null;
if (board.getItemByPosition(initialMove) instanceof Fire) return new ArrayList<Position>();
}
while (!toVisit.isEmpty()) {
Position current = toVisit.poll();
......@@ -39,11 +39,10 @@ public class Firefighter extends Extinguisher implements Item{
firstMove.put(adjacent, firstMove.get(current));
}
}
return null;
return new ArrayList<Position>();
}
public String toString(){
return "Pompier position : [" + position.row() + ", " + position.column()+ "]";
}
}
......@@ -224,6 +224,9 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
}
public void testScreen(){
Position position;
//System.out.println(itemList.toString());
for (int row = 0; row < rowCount; row++){
for (int column = 0; column < columnCount; column++){
......
package model;
import javafx.scene.paint.Color;
import util.Position;
import java.util.List;
import java.util.*;
public class MotorFirefighter extends Extinguisher implements Item{
public MotorFirefighter(Position position) {
super(position);
this.color = Color.PURPLE;
}
public List<Position> move(FirefighterBoard board) {
List<Position> result = new ArrayList<>();
Set<Position> seen = new HashSet<>();
HashMap<Position, Position> firstMove = new HashMap<>();
Queue<Position> toVisit = new LinkedList<>();
for (int i = 0; i < 2; i++){
for (Position initialMove : board.neighbors(position)) {
if (board.getItemByPosition(initialMove) == null) {
firstMove.put(initialMove, initialMove);
toVisit.add(initialMove);
}
if (board.getItemByPosition(initialMove) instanceof Fire) return new ArrayList<Position>();
}
}
while (!toVisit.isEmpty()) {
Position current = toVisit.poll();
if (board.getItemByPosition(current) instanceof Fire) {
result.add(position);
position = firstMove.get(current);
result.add(position);
return result;
}
for (Position adjacent : board.neighbors(current)) {
if (seen.contains(adjacent)) continue;
toVisit.add(adjacent);
seen.add(adjacent);
firstMove.put(adjacent, firstMove.get(current));
}
}
return new ArrayList<Position>();
}
public String toString(){
return "Pompier position : [" + position.row() + ", " + position.column()+ "]";
}
}
......@@ -104,6 +104,9 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
this.squareHeight = squareHeight;
this.columnCount = columnCount;
this.rowCount = rowCount;
super.setWidth(squareWidth*columnCount);
super.setHeight(squareHeight*rowCount);
}
private void paintLines(){
......@@ -123,22 +126,22 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
private void paintSquare(int row, int column, Color color){
getGraphicsContext2D().setFill(color);
getGraphicsContext2D().fillRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth);
getGraphicsContext2D().fillRect(column*squareWidth,row*squareHeight, squareWidth, squareHeight);
}
public void paintTriangle(int row, int column, Color color){
getGraphicsContext2D().setFill(color);
getGraphicsContext2D().fillPolygon(new double[]{row*squareHeight , row*squareHeight + squareHeight/2, (row+1)*squareHeight},
new double[]{(column+1)*squareWidth , column*squareHeight, (column+1)*squareHeight},
getGraphicsContext2D().fillPolygon(new double[]{column*squareWidth , column*squareWidth + squareWidth/2, (column+1)*squareWidth},
new double[]{(row+1)*squareHeight , row*squareHeight, (row+1)*squareHeight},
3);
}
public void paintCircle(int row, int column, Color color){
getGraphicsContext2D().setFill(color);
getGraphicsContext2D().fillOval(row*squareHeight, column*squareWidth, squareHeight, squareWidth);
getGraphicsContext2D().fillOval(column*squareWidth, row*squareHeight, squareHeight, squareWidth);
}
private void clearSquare(int row, int column){
getGraphicsContext2D().clearRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth);
getGraphicsContext2D().clearRect(column*squareWidth,row*squareHeight, squareWidth, squareHeight);
}
}
\ No newline at end of file
......@@ -33,7 +33,7 @@
mnemonicParsing="false" onAction="#pauseToggleButtonAction" prefHeight="24.0"
prefWidth="200.0" styleClass="button" text="Pause"/>
</VBox>
<FirefighterGrid fx:id="grid" width="1000.0" height="1000.0"
<FirefighterGrid fx:id="grid"
xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml">
</FirefighterGrid>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment