Skip to content

Commit

Permalink
Fix comments and add sigcheck for step 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Max committed Mar 26, 2024
1 parent 51c2eb4 commit 48dfb18
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/ch/epfl/chacun/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static int riverFishCount(Area<Zone.River> river) {
}

/**
* Counts the number of fish swimming in the given river system
* Counts the number of fish swimming in the given river system.
*
* @param riverSystem the river system area to count fish in
* @return the total number of fish in the river system
Expand Down
1 change: 1 addition & 0 deletions src/ch/epfl/chacun/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class Board {
* An empty board.
*/
public static final Board EMPTY = new Board(new PlacedTile[625], new int[0], ZonePartitions.EMPTY, Set.of());

private static final int SIZE = 25;
private final ZonePartitions zonePartitions;
private final PlacedTile[] placedTiles;
Expand Down
8 changes: 6 additions & 2 deletions src/ch/epfl/chacun/Direction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ public enum Direction {
S,
W;

// All the values of Direction.
/**
* All possible Direction values.
*/
public static final List<Direction> ALL = List.of(Direction.values());

// The number of elements of Direction.
/**
* The number of elements of Direction.
*/
public static final int COUNT = ALL.size();

/**
Expand Down
54 changes: 29 additions & 25 deletions src/ch/epfl/chacun/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,45 @@
*/
public record GameState(List<PlayerColor> players, TileDecks tileDecks, Tile tileToPlace, Board board,
Action nextAction, MessageBoard messageBoard) {
// The id of the tile containing the shaman


/**
* The id of the tile containing the shaman
*/
private static final int SHAMAN_ID = 88;
// The id of the tile containing the hunting trap

/**
* The id of the tile containing the hunting trap
*/
private static final int HUNTING_TRAP_ID = 94;
// The id of the tile containing the logboat

/**
* The id of the tile containing the logboat
*/
private static final int LOGBOAT_ID = 93;
// The id of the tile containing the wildfire

/**
* The id of the tile containing the wildfire
*/
private static final int WILD_FIRE_ID = 85;
// The id of the tile containing the pit trap

/**
* The id of the tile containing the pit trap
*/
private static final int PIT_TRAP_ID = 92;

/**
* Checks the validity of the arguments.
* <p>
* Checks that there is at least two players and that either the tile to be placed is null,
* or the next action is PLACE_TILE, throws {@link IllegalArgumentException} if not.
* Checks that the tile decks, the board, the message board or the next action are not null or throws
* {@link NullPointerException} if null.
* Checks that either the tile to be placed is null, or the next action is PLACE_TILE.
* Checks that the tile decks, the board, the message board or the next action are not null.
*
* @throws IllegalArgumentException if invalid player number or next action
* @throws NullPointerException if null arguments
*/
public GameState {
Preconditions.checkArgument(players.size() >= 2);
Preconditions.checkArgument(tileToPlace != null && nextAction != Action.PLACE_TILE);
Preconditions.checkArgument(tileToPlace == null ^ nextAction == Action.PLACE_TILE);
Objects.requireNonNull(tileDecks);
Objects.requireNonNull(board);
Objects.requireNonNull(messageBoard);
Expand Down Expand Up @@ -72,9 +86,8 @@ public static GameState initial(List<PlayerColor> players, TileDecks tileDecks,
* @return the current player
*/
public PlayerColor currentPlayer() {
if (nextAction() != Action.START_GAME || nextAction != Action.END_GAME) {
if (nextAction() != Action.START_GAME || nextAction != Action.END_GAME)
return players.getFirst();
}
return null;
}

Expand All @@ -90,8 +103,7 @@ public int freeOccupantsCount(PlayerColor player, Occupant.Kind kind) {
}

/**
* Returns the set of all the potential occupants of the last placed tile or throws
* {@link IllegalArgumentException} if the board is empty.
* Returns the set of all the potential occupants of the last placed tile.
*
* @return the set of all the potential occupants of the last placed tile
* @throws IllegalArgumentException if the board is empty
Expand Down Expand Up @@ -149,9 +161,8 @@ private Set<Animal> determineCancelledAnimals(Area<Zone.Meadow> meadowArea, int
// Find tigers
Set<Animal> tigers = getAnimalsOfKind(animals, Animal.Kind.TIGER);
// Fix the number of tigers to
if (specifiedTigerNb <= 0) {
if (specifiedTigerNb <= 0)
specifiedTigerNb = tigers.size();
}
// Compute the number of deers to cancel
int cancelledDeersNb = Math.min(specifiedTigerNb, deers.size());
Set<Animal> cancelledAnimals = new HashSet<>();
Expand All @@ -165,18 +176,14 @@ private Set<Animal> determineCancelledAnimals(Area<Zone.Meadow> meadowArea, int
}

private Set<Animal> getAnimalsOfKind(Set<Animal> animals, Animal.Kind kind) {
return animals.stream()
.filter(a -> a.kind() == kind)
.collect(Collectors.toSet());
return animals.stream().filter(a -> a.kind() == kind).collect(Collectors.toSet());
}

/**
* Manages all the transitions from PLACE_TILE.
* <p>
* Adds the given placed tile to the board, attributes the eventual points given by a logboat or a
* hunting trap and determines the next action.
* Throws {@link IllegalArgumentException} if the given next action is not PLACE_TILE or if the given
* placed tile is already occupied.
*
* @param placedTile the placed tile to add
* @return a new game state with the specified modifications
Expand Down Expand Up @@ -230,8 +237,6 @@ public GameState withPlacedTile(PlacedTile placedTile) {
* <p>
* Removes the given occupant from the board, unless it is null, which means the player does not want
* to retake a pawn.
* Checks that the next action is RETAKE_PAWN and that the given occupant is neither null nor a pawn,
* throws {@link IllegalArgumentException} if it is not.
*
* @param occupant the occupant
* @return a new game state with the specified modifications
Expand All @@ -257,7 +262,6 @@ public GameState withOccupantRemoved(Occupant occupant) {
* <p>
* Adds the given occupant to the last placed tile, unless it is null, which means that the player does
* not want to place an occupant.
* Checks that the next action is OCCUPY_TILE, throws {@link IllegalArgumentException} if it is not.
*
* @param occupant the occupant to add
* @return a new game state with the specified modifications
Expand Down Expand Up @@ -295,7 +299,7 @@ private GameState withTurnFinishedIfOccupationImpossible() {
* - Pass to the next player if the current one can't play again.
* - Ends the game when the there is no more normal tiles to place.
*
* @return a new game state with the specified modifications
* @return an updated game state
*/
private GameState withTurnFinished() {
// Determine the forests closed by last placed tile
Expand Down
4 changes: 3 additions & 1 deletion src/ch/epfl/chacun/PlayerColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public enum PlayerColor {
YELLOW,
PURPLE;

// All possible colors of a player
/**
* All possible colors of a player
*/
public static final List<PlayerColor> ALL = List.of(PlayerColor.values());

}
3 changes: 1 addition & 2 deletions src/ch/epfl/chacun/Points.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public final class Points {
/**
* Private constructor to prevent instantiation.
*/
private Points() {
}
private Points() {}

/**
* Returns the number of points obtained by the majority pickers in a closed
Expand Down
4 changes: 3 additions & 1 deletion src/ch/epfl/chacun/Pos.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*/
public record Pos(int x, int y) {

// The origin of the board
/**
* The origin of the board
*/
public final static Pos ORIGIN = new Pos(0, 0);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ch/epfl/chacun/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private Preconditions() {
}

/**
* Throws an IllegalArgumentException if the given precondition is false.
* Check if the given precondition has been satisfied.
*
* @param precondition the precondition to check
* @throws IllegalArgumentException if the precondition is false
Expand Down
9 changes: 7 additions & 2 deletions src/ch/epfl/chacun/Rotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public enum Rotation {
HALF_TURN, // 180 degrees
LEFT; // 270 degrees

// All the possible rotations
/**
* All the possible rotations
*/
public static final List<Rotation> ALL = List.of(Rotation.values());
// The number of different rotations

/**
* The number of different rotations
*/
public static final int COUNT = ALL.size();

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ch/epfl/chacun/ZonePartitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
public record ZonePartitions(ZonePartition<Zone.Forest> forests, ZonePartition<Zone.Meadow> meadows,
ZonePartition<Zone.River> rivers, ZonePartition<Zone.Water> riverSystems) {

// Represent a group of four empty partitions
/**
* Represent a group of four empty partitions
*/
public final static ZonePartitions EMPTY = new ZonePartitions(new ZonePartition<>(), new ZonePartition<>(), new ZonePartition<>(), new ZonePartition<>());

/**
Expand Down
60 changes: 60 additions & 0 deletions src/ch/epfl/sigcheck/SignatureChecks_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ch.epfl.sigcheck;

// Attention : cette classe n'est *pas* un test JUnit, et son code n'est pas
// destiné à être exécuté. Son seul but est de vérifier, autant que possible,
// que les noms et les types des différentes entités à définir pour cette
// étape du projet sont corrects.

final class SignatureChecks_6 {
private SignatureChecks_6() {}

void checkGameState() throws Exception {
v01 = new ch.epfl.chacun.GameState(v08, v03, v04, v05, v06, v07);
v01 = ch.epfl.chacun.GameState.initial(v08, v03, v09);
v05 = v01.board();
v10 = v01.currentPlayer();
v12 = v01.equals(v11);
v14 = v01.freeOccupantsCount(v10, v13);
v14 = v01.hashCode();
v15 = v01.lastTilePotentialOccupants();
v07 = v01.messageBoard();
v06 = v01.nextAction();
v08 = v01.players();
v03 = v01.tileDecks();
v04 = v01.tileToPlace();
v16 = v01.toString();
v01 = v01.withNewOccupant(v17);
v01 = v01.withOccupantRemoved(v17);
v01 = v01.withPlacedTile(v18);
v01 = v01.withStartingTilePlaced();
}

void checkGameState_Action() throws Exception {
v06 = ch.epfl.chacun.GameState.Action.END_GAME;
v06 = ch.epfl.chacun.GameState.Action.OCCUPY_TILE;
v06 = ch.epfl.chacun.GameState.Action.PLACE_TILE;
v06 = ch.epfl.chacun.GameState.Action.RETAKE_PAWN;
v06 = ch.epfl.chacun.GameState.Action.START_GAME;
v06 = ch.epfl.chacun.GameState.Action.valueOf(v16);
v19 = ch.epfl.chacun.GameState.Action.values();
}

ch.epfl.chacun.GameState v01;
ch.epfl.chacun.TileDecks v03;
ch.epfl.chacun.Tile v04;
ch.epfl.chacun.Board v05;
ch.epfl.chacun.GameState.Action v06;
ch.epfl.chacun.MessageBoard v07;
java.util.List<ch.epfl.chacun.PlayerColor> v08;
ch.epfl.chacun.TextMaker v09;
ch.epfl.chacun.PlayerColor v10;
Object v11;
boolean v12;
ch.epfl.chacun.Occupant.Kind v13;
int v14;
java.util.Set<ch.epfl.chacun.Occupant> v15;
String v16;
ch.epfl.chacun.Occupant v17;
ch.epfl.chacun.PlacedTile v18;
ch.epfl.chacun.GameState.Action[] v19;
}

0 comments on commit 48dfb18

Please sign in to comment.