Skip to content

Commit

Permalink
player is now allowed to place Phantom after placing Tower piece and …
Browse files Browse the repository at this point in the history
…taking no prisoner (with explicit skip)

fixes farin/JCloisterZone-Client#49
  • Loading branch information
farin committed Dec 31, 2022
1 parent 52f1b04 commit 68b7456
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 47 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Version history

## upcoming
* fix: player is now allowed to place Phantom after placing Tower piece and taking no prisoner (with explicit skip)
* fix: in some cases points breakdown in top bar wasn't cleared after turn confirmation by space key

## 5.10.2
*2022-11-20*
* farm hints are back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public GameStatePhaseReducer(GameSetup setup, double initialRandom) {
if (setup.contains(GoldminesCapability.class)) next = new GoldPiecePhase(randomGenerator, next);
next = tilePhase = new TilePhase(randomGenerator, next);
if (setup.contains(AbbeyCapability.class)) {
// if abbey is passed, commit commit action phase follows to change salt by following Commit message
// if abbey is passed, commit action phase follows to change salt by following Commit message
next = new CommitAbbeyPassPhase(randomGenerator, next);
next = abbeyPhase = new AbbeyPhase(randomGenerator, next);
}
Expand Down Expand Up @@ -111,13 +111,9 @@ private StepResult applyMessageOnPhase(Phase phase, GameState state, Message mes
assert m.getReturnType().equals(StepResult.class) : String.format("Bad return type %s.%s()", phase.getClass().getSimpleName(), m.getName());
StepResult res = (StepResult) m.invoke(phase, state, message);
boolean commited = message instanceof CommitMessage;
boolean passed = message instanceof PassMessage;
if (res.getState().isCommited() != commited) {
res = new StepResult(res.getState().setCommited(commited), res.getNext());
}
if (res.getState().isPassed() != passed) {
res = new StepResult(res.getState().setPassed(passed), res.getNext());
}
return res;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e.getCause() == null ? e : e.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PhantomPhase(RandomGenerator random, Phase defaultNext) {

@Override
public StepResult enter(GameState state) {
if (state.getFlags().contains(Flag.NO_PHANTOM) || state.isPassed()) {
if (state.getFlags().contains(Flag.NO_PHANTOM)) {
// The placement of a princess tile with removal of a knight from the city cannot be used as a first
// "follower move" and be followed by placement of the phantom (e.g. into the now-vacated city).
// As per the rules for the princess, "if a knight is removed from the city, the player may not deploy or
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/jcloisterzone/game/phase/Phase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jcloisterzone.game.phase;

import com.jcloisterzone.game.state.Flag;
import com.jcloisterzone.game.state.GameState;
import com.jcloisterzone.io.message.PassMessage;
import com.jcloisterzone.io.message.PayRansomMessage;
Expand Down Expand Up @@ -54,12 +55,10 @@ public StepResult handlePass(GameState state, PassMessage msg) {
}

state = clearActions(state);
if (getDefaultNext() instanceof PhantomPhase) {
//skip PhantomPhase if user pass turn
return getDefaultNext().next(state);
} else {
return next(state);
if (!(state.getPhase() instanceof TowerCapturePhase)) {
state = state.addFlag(Flag.NO_PHANTOM);
}
return next(state);
}

@PhaseMessageHandler
Expand Down
52 changes: 16 additions & 36 deletions src/main/java/com/jcloisterzone/game/state/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class GameState implements ActionsMixin, BoardMixin,
private final Phase phase;
private final int turnNumber;
private final boolean commited;
private final boolean passed;

public static GameState createInitial(
Map<Rule, Object> rules,
Expand All @@ -75,7 +74,6 @@ public static GameState createInitial(
Queue.empty(),
null,
1,
false,
false
);
}
Expand All @@ -95,8 +93,7 @@ public GameState(
Queue<PlayEvent> events,
Phase phase,
int turnNumber,
boolean commited,
boolean passed) {
boolean commited) {
this.rules = rules;
this.elements = elements;
this.capabilities = capabilities;
Expand All @@ -114,7 +111,6 @@ public GameState(
this.phase = phase;
this.turnNumber = turnNumber;
this.commited = commited;
this.passed = passed;
}

@Override
Expand All @@ -126,7 +122,7 @@ public GameState setCapabilities(CapabilitiesState capabilities) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -139,7 +135,7 @@ public GameState setPlayers(PlayersState players) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -151,7 +147,7 @@ public GameState setTilePack(TilePack tilePack) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -167,7 +163,7 @@ public GameState setDrawnTile(Tile drawnTile) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -180,7 +176,7 @@ public GameState setPlacedTiles(LinkedHashMap<Position, PlacedTile> placedTiles)
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -193,7 +189,7 @@ public GameState setFeatureMap(Map<Position, Map<FeaturePointer, Feature>> featu
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -205,7 +201,7 @@ public GameState setDiscardedTiles(List<Tile> discardedTiles) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -217,7 +213,7 @@ public GameState setNeutralFigures(NeutralFiguresState neutralFigures) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -233,7 +229,7 @@ public GameState setDeployedMeeples(LinkedHashMap<Meeple, FeaturePointer> deploy
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -246,7 +242,7 @@ public GameState setPlayerActions(ActionsState playerActions) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -263,7 +259,7 @@ public GameState setFlags(Set<Flag> flags) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -276,7 +272,7 @@ public GameState setEvents(Queue<PlayEvent> events) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -288,7 +284,7 @@ public GameState setPhase(Phase phase) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -300,7 +296,7 @@ public GameState setTurnNumber(int turnNumber) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand All @@ -312,19 +308,7 @@ public GameState setCommited(boolean commited) {
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
);
}

public GameState setPassed(boolean passed) {
if (passed == this.passed) return this;
return new GameState(
rules, elements, capabilities, players,
tilePack, drawnTile, placedTiles, discardedTiles,
featureMap, neutralFigures,
deployedMeeples, playerActions,
flags, events,
phase, turnNumber, commited, passed
phase, turnNumber, commited
);
}

Expand Down Expand Up @@ -403,8 +387,4 @@ public int getTurnNumber() {
public boolean isCommited() {
return commited;
}

public boolean isPassed() {
return passed;
}
}

0 comments on commit 68b7456

Please sign in to comment.