From 66ac2e9ad910db35538c4345257e9bd479604e78 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 14 Mar 2024 15:55:19 +0100 Subject: [PATCH] Preconditions refactor --- src/ch/epfl/chacun/Board.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ch/epfl/chacun/Board.java b/src/ch/epfl/chacun/Board.java index 28d3c43..2e4315c 100644 --- a/src/ch/epfl/chacun/Board.java +++ b/src/ch/epfl/chacun/Board.java @@ -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(); @@ -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()));