From 61ab8e781f4a347a656b8efd233570acd792221e Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 14 Mar 2024 10:28:37 +0100 Subject: [PATCH] WIP step 5 --- src/ch/epfl/chacun/Board.java | 24 +++++++- src/ch/epfl/sigcheck/SignatureChecks_5.java | 66 +++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/ch/epfl/sigcheck/SignatureChecks_5.java diff --git a/src/ch/epfl/chacun/Board.java b/src/ch/epfl/chacun/Board.java index b68865c..b5f4384 100644 --- a/src/ch/epfl/chacun/Board.java +++ b/src/ch/epfl/chacun/Board.java @@ -82,7 +82,7 @@ public PlacedTile tileWithId(int tileId) { */ public Set cancelledAnimals() { // Defensive copy - return new HashSet<>(cancelledAnimals); + return Set.copyOf(cancelledAnimals); } /** @@ -193,6 +193,7 @@ public int occupantCount(PlayerColor player, Occupant.Kind occupantKind) { int occupantCount = 0; for (int placedTileIndex : tileIndices) { PlacedTile placedTile = placedTiles[placedTileIndex]; + // If a tile has an occupant, it has been placed by the tile placer if (placedTile.occupant().kind() == occupantKind && placedTile.placer() == player) { occupantCount++; } @@ -314,7 +315,7 @@ public Board withNewTile(PlacedTile tile) { System.arraycopy(tileIndices, 0, newTileIndices, 0, tileIndices.length); newTileIndices[tileIndices.length] = newTileIndex; // Create a new board with the new tile - return new Board(newPlacedTiles, newTileIndices, zonePartitions, Set.copyOf(cancelledAnimals)); + return new Board(newPlacedTiles, newTileIndices, zonePartitions, cancelledAnimals()); } public Board withOccupant(Occupant occupant) { @@ -322,6 +323,11 @@ public Board withOccupant(Occupant occupant) { return null; } + public Board withoutOccupant(Occupant occupant) { + // TODO: implement this method + return null; + } + /** * Returns the same board but without any occupants in the given forests and rivers. * @@ -340,6 +346,18 @@ public Board withoutGatherersOrFishersIn(Set> forests, Set newlyCancelledAnimals) { + Set newCancelledAnimals = new HashSet<>(cancelledAnimals()); + newCancelledAnimals.addAll(newlyCancelledAnimals); + return new Board(placedTiles.clone(), tileIndices.clone(), zonePartitions, newCancelledAnimals); } } \ No newline at end of file diff --git a/src/ch/epfl/sigcheck/SignatureChecks_5.java b/src/ch/epfl/sigcheck/SignatureChecks_5.java new file mode 100644 index 0000000..f0c608b --- /dev/null +++ b/src/ch/epfl/sigcheck/SignatureChecks_5.java @@ -0,0 +1,66 @@ +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_5 { + private SignatureChecks_5() {} + + void checkBoard() throws Exception { + v01 = ch.epfl.chacun.Board.EMPTY; + v02 = ch.epfl.chacun.Board.REACH; + v05 = v01.adjacentMeadow(v03, v04); + v07 = v01.canAddTile(v06); + v08 = v01.cancelledAnimals(); + v07 = v01.couldPlaceTile(v09); + v07 = v01.equals(v10); + v12 = v01.forestArea(v11); + v13 = v01.forestsClosedByLastTile(); + v02 = v01.hashCode(); + v14 = v01.insertionPositions(); + v06 = v01.lastPlacedTile(); + v05 = v01.meadowArea(v04); + v15 = v01.meadowAreas(); + v02 = v01.occupantCount(v16, v17); + v18 = v01.occupants(); + v20 = v01.riverArea(v19); + v22 = v01.riverSystemArea(v21); + v23 = v01.riverSystemAreas(); + v24 = v01.riversClosedByLastTile(); + v06 = v01.tileAt(v03); + v06 = v01.tileWithId(v02); + v01 = v01.withMoreCancelledAnimals(v08); + v01 = v01.withNewTile(v06); + v01 = v01.withOccupant(v25); + v01 = v01.withoutGatherersOrFishersIn(v13, v24); + v01 = v01.withoutOccupant(v25); + } + + ch.epfl.chacun.Board v01; + int v02; + ch.epfl.chacun.Pos v03; + ch.epfl.chacun.Zone.Meadow v04; + ch.epfl.chacun.Area v05; + ch.epfl.chacun.PlacedTile v06; + boolean v07; + java.util.Set v08; + ch.epfl.chacun.Tile v09; + java.lang.Object v10; + ch.epfl.chacun.Zone.Forest v11; + ch.epfl.chacun.Area v12; + java.util.Set> v13; + java.util.Set v14; + java.util.Set> v15; + ch.epfl.chacun.PlayerColor v16; + ch.epfl.chacun.Occupant.Kind v17; + java.util.Set v18; + ch.epfl.chacun.Zone.River v19; + ch.epfl.chacun.Area v20; + ch.epfl.chacun.Zone.Water v21; + ch.epfl.chacun.Area v22; + java.util.Set> v23; + java.util.Set> v24; + ch.epfl.chacun.Occupant v25; +}