Skip to content

Commit

Permalink
Preconditions refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mw3y committed Mar 14, 2024
1 parent ad1f6d8 commit 66ac2e9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/ch/epfl/chacun/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ public boolean couldPlaceTile(Tile tile) {
*/
public Board withNewTile(PlacedTile tile) {
// Check if the tile can be placed on the board
if (placedTiles.length != 0 && !canAddTile(tile)) {
throw new IllegalArgumentException("The tile cannot be placed on the board.");
}
Preconditions.checkArgument(placedTiles.length == 0 || canAddTile(tile) );
// Create the new placed tiles array
int newTileIndex = calculateRowMajorIndex(tile.pos());
PlacedTile[] newPlacedTiles = placedTiles.clone();
Expand Down Expand Up @@ -337,9 +335,8 @@ public Board withNewTile(PlacedTile tile) {
public Board withOccupant(Occupant occupant) {
int tileId = Zone.tileId(occupant.zoneId());
PlacedTile placedTile = tileWithId(tileId);
if (placedTile.occupant() != null) {
throw new IllegalArgumentException("The tile already has an occupant.");
}
// Check if there's already an occupant
Preconditions.checkArgument(placedTile.occupant() == null);
// Update zone partitions
ZonePartitions.Builder builder = new ZonePartitions.Builder(zonePartitions);
builder.addInitialOccupant(placedTile.placer(), occupant.kind(), placedTile.zoneWithId(occupant.zoneId()));
Expand Down

0 comments on commit 66ac2e9

Please sign in to comment.