Skip to content

Commit

Permalink
add more preconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed May 24, 2024
1 parent 3c4a00d commit d67f0ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ch/epfl/chacun/ActionEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Comparator;
import java.util.List;
import java.util.Objects;

/**
* A utility class that offers methods
Expand Down Expand Up @@ -91,6 +92,7 @@ private static List<Occupant> sortedOccupants(GameState gameState) {
* @return the new game state resulting from the action and the encoded action
*/
public static StateAction withPlacedTile(GameState gameState, PlacedTile tile) {
Objects.requireNonNull(tile);
List<Pos> fringeIndexes = fringeIndexes(gameState);
int indexToEncode = fringeIndexes.indexOf(tile.pos()); // a number between 0 and 189
int rotationToEncode = tile.rotation().ordinal(); // a number between 0 and 3
Expand Down
3 changes: 3 additions & 0 deletions src/ch/epfl/chacun/gui/ImageLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.epfl.chacun.gui;

import ch.epfl.chacun.Preconditions;
import javafx.scene.image.Image;

import java.util.FormatProcessor;
Expand Down Expand Up @@ -62,6 +63,7 @@ private static Image imageForTile(int tileId, int pixelSize) {
* @return the normal image for the tile with the given tile id
*/
public static Image normalImageForTile(int tileId) {
Preconditions.checkArgument(tileId >= 0);
return imageForTile(tileId, NORMAL_TILE_PIXEL_SIZE);
}

Expand All @@ -72,6 +74,7 @@ public static Image normalImageForTile(int tileId) {
* @return the large image for the tile with the given tile id
*/
public static Image largeImageForTile(int tileId) {
Preconditions.checkArgument(tileId >= 0);
return imageForTile(tileId, LARGE_TILE_PIXEL_SIZE);
}

Expand Down

0 comments on commit d67f0ee

Please sign in to comment.