Skip to content

Commit 73ec811

Browse files
committed
intellij reformat
1 parent 3c88566 commit 73ec811

32 files changed

+835
-645
lines changed

src/ch/epfl/chacun/ActionEncoder.java

+35-23
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public static class IllegalActionException extends Exception {
2121
/**
2222
* Construct an IllegalActionException, with no message.
2323
*/
24-
public IllegalActionException() {}
24+
public IllegalActionException() {
25+
}
2526
}
2627

2728
/**
@@ -63,27 +64,30 @@ public IllegalActionException() {}
6364
/**
6465
* This class can not be instantiated.
6566
*/
66-
private ActionEncoder() {}
67+
private ActionEncoder() {
68+
}
6769

6870
/**
6971
* Get the fringe indexes of the given game state's board, in a list sorted by x and then y.
72+
*
7073
* @param gameState the game state to get the fringe indexes from
7174
* @return the list of ordered (x-precedence) fringe indexes of the game state
7275
*/
7376
private static List<Pos> fringeIndexes(GameState gameState) {
7477
Board board = gameState.board();
7578
return board.insertionPositions().stream()
76-
.sorted(Comparator.comparing(Pos::x).thenComparing(Pos::y))
77-
.toList();
79+
.sorted(Comparator.comparing(Pos::x).thenComparing(Pos::y))
80+
.toList();
7881
}
7982

8083
/**
8184
* Encode an action where the given tile is placed on the board of the given game state.
85+
*
8286
* @param gameState the initial game state
83-
* @param tile the tile to place
87+
* @param tile the tile to place
8488
* @return the new game state resulting from the action and the encoded action
8589
*/
86-
public static StateAction withPlacedTile(GameState gameState, PlacedTile tile){
90+
public static StateAction withPlacedTile(GameState gameState, PlacedTile tile) {
8791
List<Pos> fringeIndexes = fringeIndexes(gameState);
8892
//todo: check if the tile is in the fringe?
8993
int indexToEncode = fringeIndexes.indexOf(tile.pos()); // a number between 0 and 189
@@ -95,13 +99,15 @@ public static StateAction withPlacedTile(GameState gameState, PlacedTile tile){
9599

96100
/**
97101
* Encode an action where the given occupant is placed on the board of the given game state.
102+
*
98103
* @param gameState the initial game state
99-
* @param occupant the occupant to place
104+
* @param occupant the occupant to place
100105
* @return the new game state resulting from the action and the encoded action
101106
*/
102107
public static StateAction withNewOccupant(GameState gameState, Occupant occupant) {
103108
// if the occupant is null, we encode 11111, which means that there is no occupant to place
104-
if (occupant == null) return new StateAction(gameState.withNewOccupant(null), Base32.encodeBits5(WITH_NO_OCCUPANT));
109+
if (occupant == null)
110+
return new StateAction(gameState.withNewOccupant(null), Base32.encodeBits5(WITH_NO_OCCUPANT));
105111
int kindToEncode = occupant.kind().ordinal(); // a number between 0 and 1
106112
int zoneToEncode = Zone.localId(occupant.zoneId());
107113
int toEncode = kindToEncode << WITH_NEW_OCCUPANT_KIND_SHIFT | zoneToEncode;
@@ -110,14 +116,16 @@ public static StateAction withNewOccupant(GameState gameState, Occupant occupant
110116

111117
/**
112118
* Encode an action where the given occupant is removed from the board of the given game state.
119+
*
113120
* @param gameState the initial game state
114-
* @param occupant the occupant to remove
121+
* @param occupant the occupant to remove
115122
* @return the new game state resulting from the action and the encoded action
116123
*/
117124
public static StateAction withOccupantRemoved(GameState gameState, Occupant occupant) {
118-
if (occupant == null) return new StateAction(gameState.withOccupantRemoved(null), Base32.encodeBits5(WITH_NO_OCCUPANT));
125+
if (occupant == null)
126+
return new StateAction(gameState.withOccupantRemoved(null), Base32.encodeBits5(WITH_NO_OCCUPANT));
119127
List<Occupant> occupants = gameState.board().occupants().stream()
120-
.sorted(Comparator.comparingInt(Occupant::zoneId)).toList();
128+
.sorted(Comparator.comparingInt(Occupant::zoneId)).toList();
121129
int indexToEncode = occupants.indexOf(occupant); // a number between 0 and 24
122130
return new StateAction(gameState.withOccupantRemoved(occupant), Base32.encodeBits5(indexToEncode));
123131
}
@@ -126,8 +134,9 @@ public static StateAction withOccupantRemoved(GameState gameState, Occupant occu
126134
* Decode and apply the given action encoded in Base32 to the given game state,
127135
* throwing an IllegalActionException if the action is invalid.
128136
* This method lets the caller handle the exception, to choose what to do in case of an invalid action.
137+
*
129138
* @param gameState the initial game state
130-
* @param action the Base32-code for the action to decode and apply
139+
* @param action the Base32-code for the action to decode and apply
131140
* @return the new game state resulting from the action and the decoded action
132141
* @throws IllegalActionException if the action is invalid for the given game state
133142
*/
@@ -147,7 +156,7 @@ private static StateAction decodeAndApplyWithException(GameState gameState, Stri
147156
Pos pos = fringeIndexes.get(tileInFringeIdx);
148157
Tile tile = gameState.tileToPlace();
149158
PlacedTile placedTile = new PlacedTile(
150-
tile, gameState.currentPlayer(), Rotation.ALL.get(rotationIdx), pos
159+
tile, gameState.currentPlayer(), Rotation.ALL.get(rotationIdx), pos
151160
);
152161
Preconditions.checkValidAction(gameState.board().canAddTile(placedTile));
153162
yield new StateAction(gameState.withPlacedTile(placedTile), action);
@@ -160,19 +169,19 @@ private static StateAction decodeAndApplyWithException(GameState gameState, Stri
160169
int localId = decoded & WITH_NEW_OCCUPANT_ZONE_MASK;
161170
Occupant.Kind kind = Occupant.Kind.ALL.get(kindIdx);
162171
Occupant occupant = gameState.lastTilePotentialOccupants().stream()
163-
.filter(occ -> occ.kind() == kind && Zone.localId(occ.zoneId()) == localId)
164-
.findFirst()
165-
.orElseThrow(IllegalActionException::new);
172+
.filter(occ -> occ.kind() == kind && Zone.localId(occ.zoneId()) == localId)
173+
.findFirst()
174+
.orElseThrow(IllegalActionException::new);
166175
yield new StateAction(gameState.withNewOccupant(occupant), action);
167176
}
168177
case RETAKE_PAWN -> {
169178
Preconditions.checkValidAction(action.length() == WITH_OCCUPANT_REMOVED_ACTION_LENGTH);
170179
int decoded = Base32.decode(action);
171180
if (decoded == WITH_NO_OCCUPANT) yield new StateAction(gameState.withOccupantRemoved(null), action);
172181
List<Occupant> occupants = gameState.board().occupants()
173-
.stream()
174-
.sorted(Comparator.comparingInt(Occupant::zoneId))
175-
.toList();
182+
.stream()
183+
.sorted(Comparator.comparingInt(Occupant::zoneId))
184+
.toList();
176185
Preconditions.checkValidAction(occupants.size() > decoded);
177186
Occupant occupant = occupants.get(decoded);
178187
Preconditions.checkValidAction(occupant.kind() == Occupant.Kind.PAWN);
@@ -187,10 +196,11 @@ private static StateAction decodeAndApplyWithException(GameState gameState, Stri
187196

188197
/**
189198
* Decode and apply the given action encoded in Base32 to the given game state.
199+
*
190200
* @param gameState the initial game state
191-
* @param action the Base32-code for the action to decode and apply
201+
* @param action the Base32-code for the action to decode and apply
192202
* @return the new game state resulting from the action and the decoded action,
193-
* or null if the action is invalid
203+
* or null if the action is invalid
194204
*/
195205
public static StateAction decodeAndApply(GameState gameState, String action) {
196206
// we catch the exception and return null if the action is invalid
@@ -204,8 +214,10 @@ public static StateAction decodeAndApply(GameState gameState, String action) {
204214
/**
205215
* A record to represent a pair of a game state and an action, used in this program
206216
* to return a game state resulting from an action and the Base32 encoded action itself.
217+
*
207218
* @param gameState the game state
208-
* @param action the action
219+
* @param action the action
209220
*/
210-
public record StateAction(GameState gameState, String action) {}
221+
public record StateAction(GameState gameState, String action) {
222+
}
211223
}

src/ch/epfl/chacun/Animal.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22

33
/**
44
* Represents an animal in the game
5-
* @param id non-negative, the id of the animal
6-
* @param kind non-null, the kind of animal
75
*
6+
* @param id non-negative, the id of the animal
7+
* @param kind non-null, the kind of animal
88
* @author Valerio De Santis (373247)
99
* @author Simon Lefort (371918)
1010
*/
11-
public record Animal (int id, Kind kind) {
11+
public record Animal(int id, Kind kind) {
1212

1313
/**
1414
* Returns the id of the tile where the animal is
15+
*
1516
* @return the id of the tile where the animal is
1617
*/
17-
public int tileId () {
18+
public int tileId() {
1819
return Zone.tileId(zoneId());
1920
}
2021

2122
/**
2223
* we do a right shift to get the zone id,
2324
* as the id of the animal is the zone id * 10 + the local id
25+
*
2426
* @return the zone id of the animal
2527
*/
26-
private int zoneId () {
28+
private int zoneId() {
2729
return id / 10;
2830
}
2931

0 commit comments

Comments
 (0)