Skip to content
Snippets Groups Projects
Commit e3bd9855 authored by MANSOUR Chadi's avatar MANSOUR Chadi
Browse files

fixed isuues with initial code

added BoardManager Class
parent 8427201a
No related branches found
No related tags found
No related merge requests found
Pipeline #38157 passed
package model;
import util.Position;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BoardManager implements Board<List<ModelElement>> {
private final int rowCount;
private final int columnCount;
private final Map<Position, List<ModelElement>> boardState = new HashMap<>();
public BoardManager(int rowCount, int columnCount) {
this.rowCount = rowCount;
this.columnCount = columnCount;
initializeBoard();
}
private void initializeBoard() {
for (int row = 0; row < rowCount; row++) {
for (int column = 0; column < columnCount; column++) {
boardState.put(new Position(row, column), new ArrayList<>());
}
}
}
/**
* Get the state of the board at a specific position.
*
* @param position The position on the board for which to retrieve the state.
* @return The state at the specified position.
*/
@Override
public List<ModelElement> getState(Position position) {
return boardState.getOrDefault(position, new ArrayList<>());
}
/**
* Set the state of a specific position on the board to the specified state.
*
* @param state The state to set for the given position.
* @param position The position on the board for which to set the state.
*/
@Override
public void setState(List<ModelElement> state, Position position) {
boardState.put(position, new ArrayList<>(state));
}
/**
* Get the number of rows in the board.
*
* @return The number of rows in the board.
*/
@Override
public int rowCount() {
return rowCount;
}
/**
* Get the number of columns in the board.
*
* @return The number of columns in the board.
*/
@Override
public int columnCount() {
return columnCount;
}
/**
* 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.
*/
@Override
public List<Position> updateToNextGeneration() {
return new ArrayList<>();
}
/**
* Reset the board to its initial state.
*/
@Override
public void reset() {
boardState.clear();
initializeBoard();
}
/**
* Get the current step number or generation of the board.
*
* @return The current step number or generation.
*/
@Override
public int stepNumber() {
return 0;
}
}
package model;
import util.Position;
import util.*;
import java.util.*;
......
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>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment