Skip to content

Commit

Permalink
Add Board.couldPlaceTile, Board.withNewTile and Board.withoutGatherer…
Browse files Browse the repository at this point in the history
…sOrFishersIn
  • Loading branch information
Max committed Mar 14, 2024
1 parent 44b1f4d commit a7d1c7c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/ch/epfl/chacun/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,22 @@ public boolean canAddTile(PlacedTile tile) {
return true;
}

/**
* Returns whether if the given tile could be placed on one of the board's
* insertion positions, possibly after rotation, or not.
*
* @param tile the tile to check for placement possibilities
* @return whether the given tile could be placed on one of the board's insertion positions or not
*/
public boolean couldPlaceTile(Tile tile) {
// TODO: implement this method
for (Pos insertionPosition : insertionPositions()) {
for (Rotation rotation : Rotation.ALL) {
PlacedTile placedTile = new PlacedTile(tile, null, rotation, insertionPosition);
if (canAddTile(placedTile)) {
return true;
}
}
}
return false;
}

Expand Down Expand Up @@ -307,4 +321,25 @@ public Board withOccupant(Occupant occupant) {
// TODO: implement this method
return null;
}

/**
* Returns the same board but without any occupants in the given forests and rivers.
*
* @param forests the forest areas to remove gatherers from
* @param rivers the river areas to remove fishers from
* @return the same board but without any occupants in the given forests and rivers
*/
public Board withoutGatherersOrFishersIn(Set<Area<Zone.Forest>> forests, Set<Area<Zone.River>> rivers) {
ZonePartitions.Builder builder = new ZonePartitions.Builder(zonePartitions);
// Remove gatherers from all given areas
for (Area<Zone.Forest> forest : forests) {
builder.clearGatherers(forest);
}
// Remove fishers from all given areas
for (Area<Zone.River> river : rivers) {
builder.clearFishers(river);
}
// Create the new board
return new Board(placedTiles.clone(), tileIndices.clone(), builder.build(), Set.copyOf(cancelledAnimals));
}
}

0 comments on commit a7d1c7c

Please sign in to comment.