diff --git a/src/ch/epfl/chacun/Board.java b/src/ch/epfl/chacun/Board.java index 7eb34b0..b68865c 100644 --- a/src/ch/epfl/chacun/Board.java +++ b/src/ch/epfl/chacun/Board.java @@ -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; } @@ -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> forests, Set> rivers) { + ZonePartitions.Builder builder = new ZonePartitions.Builder(zonePartitions); + // Remove gatherers from all given areas + for (Area forest : forests) { + builder.clearGatherers(forest); + } + // Remove fishers from all given areas + for (Area river : rivers) { + builder.clearFishers(river); + } + // Create the new board + return new Board(placedTiles.clone(), tileIndices.clone(), builder.build(), Set.copyOf(cancelledAnimals)); + } } \ No newline at end of file