From b29fe1513d3631d84d21597e88540bc1f61d5f88 Mon Sep 17 00:00:00 2001 From: Roman Krejcik Date: Wed, 12 Oct 2022 22:33:16 +0200 Subject: [PATCH] code review WIP --- .../action/MoveBlackDragonAction.java | 19 ------- .../engine/StateGsonBuilder.java | 38 +------------ .../event/NeutralFigureReturned.java | 16 +----- .../java/com/jcloisterzone/figure/Barn.java | 5 -- .../java/com/jcloisterzone/figure/Figure.java | 4 -- .../com/jcloisterzone/figure/Follower.java | 4 -- .../jcloisterzone/figure/neutral/BigTop.java | 5 -- .../jcloisterzone/figure/neutral/Count.java | 5 -- .../game/GameStatePhaseReducer.java | 1 - .../capability/BlackDragonCapability.java | 55 ++++--------------- .../BlackDragonCapabilityModel.java | 31 +++++++++++ .../game/phase/BlackDragonMovePhase.java | 34 +++++------- .../game/phase/BlackDragonPhase.java | 25 +++++++++ .../game/phase/BlackDragonPlacePhase.java | 42 ++++++++++---- .../game/phase/ScoringPhase.java | 9 --- .../reducers/AbstractUndeploy.java | 12 ---- .../reducers/ReturnNeutralFigure.java | 2 +- .../reducers/UndeployNeutralFigure.java | 34 ------------ 18 files changed, 115 insertions(+), 226 deletions(-) delete mode 100644 src/main/java/com/jcloisterzone/action/MoveBlackDragonAction.java create mode 100644 src/main/java/com/jcloisterzone/game/capability/BlackDragonCapabilityModel.java create mode 100644 src/main/java/com/jcloisterzone/game/phase/BlackDragonPhase.java delete mode 100644 src/main/java/com/jcloisterzone/reducers/UndeployNeutralFigure.java diff --git a/src/main/java/com/jcloisterzone/action/MoveBlackDragonAction.java b/src/main/java/com/jcloisterzone/action/MoveBlackDragonAction.java deleted file mode 100644 index b0c16dfc5..000000000 --- a/src/main/java/com/jcloisterzone/action/MoveBlackDragonAction.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.jcloisterzone.action; - -import com.jcloisterzone.board.Position; -import io.vavr.collection.Set; - -//TODO generic NeutralMeepleAction ? -public class MoveBlackDragonAction extends SelectTileAction { - - private final String figureId; - - public MoveBlackDragonAction(String figureId, Set options) { - super(options); - this.figureId = figureId; - } - - public String getFigureId() { - return figureId; - } -} \ No newline at end of file diff --git a/src/main/java/com/jcloisterzone/engine/StateGsonBuilder.java b/src/main/java/com/jcloisterzone/engine/StateGsonBuilder.java index 368bc47b0..0df526faf 100644 --- a/src/main/java/com/jcloisterzone/engine/StateGsonBuilder.java +++ b/src/main/java/com/jcloisterzone/engine/StateGsonBuilder.java @@ -73,7 +73,6 @@ public Gson create() { builder.registerTypeAdapter(RemoveMageOrWitchAction.class, new ActionSerializer("RemoveMageOrWitch")); builder.registerTypeAdapter(LittleBuildingAction.class, new LittleBuildingActionSerializer()); builder.registerTypeAdapter(ScoreAcrobatsAction.class, new SelectFeatureActionSerializer()); - builder.registerTypeAdapter(MoveBlackDragonAction.class, new MoveBlackDragonActionSerializer()); return builder.create(); } @@ -294,14 +293,14 @@ public JsonElement serializeNeutralFigures(GameState root, JsonSerializationCont } pos = state.getBlackDragonDeployment(); if (pos != null) { - Tuple3,Integer,Array> blackdragonmoves = root.getCapabilityModel(BlackDragonCapability.class); + BlackDragonCapabilityModel model = root.getCapabilityModel(BlackDragonCapability.class); JsonObject data = new JsonObject(); data.add("position", context.serialize(pos)); if (root.getPhase() instanceof BlackDragonMovePhase) { JsonArray visitedData = new JsonArray(); - blackdragonmoves._1.forEach(p -> visitedData.add(context.serialize(p))); + model.getVisited().forEach(p -> visitedData.add(context.serialize(p))); data.add("visited", visitedData); - data.addProperty("remaining", blackdragonmoves._2 - blackdragonmoves._1.length()); + data.addProperty("remaining", model.getMoves() - model.getVisited().length()); } neutral.add("blackdragon", data); } @@ -571,21 +570,6 @@ public JsonArray serializePlayEvents(GameState root, JsonSerializationContext co } continue; } - if (ev instanceof NeutralFigureReturned) { - NeutralFigureReturned nfr = (NeutralFigureReturned) ev; - if (nfr.isForced()) { - JsonObject data = new JsonObject(); - data.addProperty("type", "neutralfigure-returned"); - data.addProperty("neutralfigure", nfr.getNeutralFigure().getClass().getSimpleName().toLowerCase()); - Player nfrp = nfr.getPlayer(); - if (nfrp != null) { - data.addProperty("player", nfr.getPlayer().getIndex()); - } - data.add("from", context.serialize(nfr.getFrom())); - turnEvents.add(data); - } - continue; - } if (ev instanceof RansomPaidEvent) { RansomPaidEvent rev = (RansomPaidEvent) ev; JsonObject data = new JsonObject(); @@ -944,20 +928,4 @@ public JsonElement serialize(LittleBuildingAction action, Type type, JsonSeriali return json; } } - - private class MoveBlackDragonActionSerializer implements JsonSerializer { - @Override - public JsonElement serialize(MoveBlackDragonAction action, Type type, JsonSerializationContext context) { - JsonObject json = new JsonObject(); - json.addProperty("type", "MoveDragon"); - json.addProperty("figureId", action.getFigureId()); - JsonArray options = new JsonArray(); - action.getOptions().forEach(pos -> { - options.add(context.serialize(pos)); - }); - json.add("options", options); - return json; - } - } - } diff --git a/src/main/java/com/jcloisterzone/event/NeutralFigureReturned.java b/src/main/java/com/jcloisterzone/event/NeutralFigureReturned.java index f30911343..8197206b6 100644 --- a/src/main/java/com/jcloisterzone/event/NeutralFigureReturned.java +++ b/src/main/java/com/jcloisterzone/event/NeutralFigureReturned.java @@ -2,22 +2,16 @@ import com.jcloisterzone.board.pointer.BoardPointer; import com.jcloisterzone.figure.neutral.NeutralFigure; -import com.jcloisterzone.Player; public class NeutralFigureReturned extends PlayEvent { private final BoardPointer from; private final NeutralFigure neutralFigure; - private final boolean forced; - /** true if meeple is returned different way than scoring feature */ - private final Player player; - public NeutralFigureReturned(PlayEventMeta metadata, NeutralFigure neutralFigure, BoardPointer from, Boolean forced, Player player) { + public NeutralFigureReturned(PlayEventMeta metadata, NeutralFigure neutralFigure, BoardPointer from) { super(metadata); this.neutralFigure = neutralFigure; this.from = from; - this.forced = forced; - this.player = player; } public BoardPointer getFrom() { @@ -27,12 +21,4 @@ public BoardPointer getFrom() { public NeutralFigure getNeutralFigure() { return neutralFigure; } - - public boolean isForced() { - return forced; - } - - public Player getPlayer() { - return player; - } } diff --git a/src/main/java/com/jcloisterzone/figure/Barn.java b/src/main/java/com/jcloisterzone/figure/Barn.java index c04bd89c2..4ec68ed2b 100644 --- a/src/main/java/com/jcloisterzone/figure/Barn.java +++ b/src/main/java/com/jcloisterzone/figure/Barn.java @@ -19,11 +19,6 @@ public boolean canBeEatenByDragon(GameState state) { return false; } - @Override - public boolean canBeEatenByBlackDragon(GameState state) { - return false; - } - @Override public DeploymentCheckResult isDeploymentAllowed(GameState state, FeaturePointer fp, Structure feature) { if (!(feature instanceof Field)) { diff --git a/src/main/java/com/jcloisterzone/figure/Figure.java b/src/main/java/com/jcloisterzone/figure/Figure.java index 6e9d9c280..b4dd1ef3e 100644 --- a/src/main/java/com/jcloisterzone/figure/Figure.java +++ b/src/main/java/com/jcloisterzone/figure/Figure.java @@ -74,10 +74,6 @@ public boolean isInSupply(GameState state) { return !isDeployed(state); } - public boolean canBeEatenByBlackDragon(GameState state) { - return true; - } - @Override public int hashCode() { return id.hashCode(); diff --git a/src/main/java/com/jcloisterzone/figure/Follower.java b/src/main/java/com/jcloisterzone/figure/Follower.java index 92a85afbc..4cf781517 100644 --- a/src/main/java/com/jcloisterzone/figure/Follower.java +++ b/src/main/java/com/jcloisterzone/figure/Follower.java @@ -28,10 +28,6 @@ public boolean canBeEatenByDragon(GameState state) { return !(getFeature(state) instanceof Castle); } - @Override - public boolean canBeEatenByBlackDragon(GameState state) { - return !(getFeature(state) instanceof Castle); - } public boolean isCaptured(GameState state) { Array> model = state.getCapabilityModel(TowerCapability.class); return model != null && Stream.concat(model).find(f -> f == this).isDefined(); diff --git a/src/main/java/com/jcloisterzone/figure/neutral/BigTop.java b/src/main/java/com/jcloisterzone/figure/neutral/BigTop.java index 2e43a4678..a587d4a24 100644 --- a/src/main/java/com/jcloisterzone/figure/neutral/BigTop.java +++ b/src/main/java/com/jcloisterzone/figure/neutral/BigTop.java @@ -12,9 +12,4 @@ public class BigTop extends NeutralFigure { public BigTop(String id) { super(id); } - - @Override - public boolean canBeEatenByBlackDragon(GameState state) { - return false; - } } diff --git a/src/main/java/com/jcloisterzone/figure/neutral/Count.java b/src/main/java/com/jcloisterzone/figure/neutral/Count.java index 413164cb6..bb1939363 100644 --- a/src/main/java/com/jcloisterzone/figure/neutral/Count.java +++ b/src/main/java/com/jcloisterzone/figure/neutral/Count.java @@ -12,9 +12,4 @@ public class Count extends NeutralFigure { public Count(String id) { super(id); } - - @Override - public boolean canBeEatenByBlackDragon(GameState state) { - return false; - } } diff --git a/src/main/java/com/jcloisterzone/game/GameStatePhaseReducer.java b/src/main/java/com/jcloisterzone/game/GameStatePhaseReducer.java index 3546ffbe9..0ee44e4d5 100644 --- a/src/main/java/com/jcloisterzone/game/GameStatePhaseReducer.java +++ b/src/main/java/com/jcloisterzone/game/GameStatePhaseReducer.java @@ -47,7 +47,6 @@ public GameStatePhaseReducer(GameSetup setup, double initialRandom) { if (setup.contains(CornCircleCapability.class)) next = new CornCirclePhase(randomGenerator, next); if (setup.contains(BlackDragonCapability.class)) next = new BlackDragonPlacePhase(randomGenerator, next); - if (setup.contains(DragonCapability.class) && "after-scoring".equals(setup.getStringRule(Rule.DRAGON_MOVEMENT))) { next = new DragonPhase(randomGenerator, next); } diff --git a/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapability.java b/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapability.java index 5432d829b..fc2a803c0 100644 --- a/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapability.java +++ b/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapability.java @@ -2,28 +2,21 @@ import com.jcloisterzone.Immutable; import com.jcloisterzone.board.Position; -import com.jcloisterzone.board.pointer.BoardPointer; import com.jcloisterzone.board.pointer.FeaturePointer; import com.jcloisterzone.feature.Completable; import com.jcloisterzone.figure.Meeple; import com.jcloisterzone.figure.neutral.BlackDragon; -import com.jcloisterzone.figure.neutral.NeutralFigure; import com.jcloisterzone.game.Capability; import com.jcloisterzone.game.state.GameState; import com.jcloisterzone.reducers.MoveNeutralFigure; import com.jcloisterzone.reducers.UndeployMeeple; -import com.jcloisterzone.reducers.UndeployNeutralFigure; -import io.vavr.collection.Array; import io.vavr.collection.Vector; import io.vavr.Tuple2; -import io.vavr.Tuple3; -/** - * @model Tuple3,Integer,Array : visited tiles by black dragon, count of finished features, score on start of turn - */ + @Immutable -public class BlackDragonCapability extends Capability,Integer,Array>> { +public class BlackDragonCapability extends Capability { private static final long serialVersionUID = 1L; @@ -32,7 +25,7 @@ public class BlackDragonCapability extends Capability,In @Override public GameState onStartGame(GameState state) { state = state.mapNeutralFigures(nf -> nf.setBlackDragon(new BlackDragon("blackdragon.1"))); - state = setInitialTurnState(state); + state = setModel(state, new BlackDragonCapabilityModel(EMPTY_VISITED, 0)); return state; } @@ -43,58 +36,30 @@ public boolean isMeepleDeploymentAllowed(GameState state, Position pos) { @Override public GameState beforeCompletableScore(GameState state, java.util.Set features) { - Tuple3,Integer,Array> model = getModel(state); - state = setModel(state, new Tuple3<>(EMPTY_VISITED,features.size(),model._3)); + if (features.size() > 0) { + state = setModel(state, new BlackDragonCapabilityModel(EMPTY_VISITED, features.size())); + } return state; } - - @Override - public GameState onTurnPartCleanUp(GameState state) { - return setInitialTurnState(state); - } - - public GameState setInitialTurnState(GameState state) { - return setModel(state, new Tuple3<>(EMPTY_VISITED,0,state.getPlayers().getScore())); - } - - public Vector getVisitedPositions(GameState state) { - Vector visitedpositions = getModel(state)._1; - return visitedpositions == null ? BlackDragonCapability.EMPTY_VISITED : visitedpositions; - } - - public Integer getMoves(GameState state) { - Integer finishedfeatures = getModel(state)._2; - return finishedfeatures == null ? 0 : finishedfeatures; - } - - public Array getScore(GameState state) { - return getModel(state)._3; - } public GameState moveBlackDragon(GameState state, Position pos) { state = ( new MoveNeutralFigure<>(state.getNeutralFigures().getBlackDragon(), pos) ).apply(state); - state = blackDragonOnTile(state, pos); + state = clearTile(state, pos); return state; } - public GameState blackDragonOnTile(GameState state, Position pos) { + public GameState clearTile(GameState state, Position pos) { for (Tuple2 t: state.getDeployedMeeples()) { Meeple m = t._1; FeaturePointer fp = t._2; - if (pos.equals(fp.getPosition()) && m.canBeEatenByBlackDragon(state)) { + if (pos.equals(fp.getPosition()) && m.canBeEatenByDragon(state)) { state = (new UndeployMeeple(m, true)).apply(state); } } - for (Tuple2, BoardPointer> t: state.getNeutralFigures().getDeployedNeutralFigures().toSet()) { - NeutralFigure nf = t._1; - BoardPointer bp = t._2; - if (pos.equals(bp.getPosition()) && state.getNeutralFigures().getBlackDragon() != nf && nf.canBeEatenByBlackDragon(state)) { - state = (new UndeployNeutralFigure(nf, true)).apply(state); - } - } + return state; } } diff --git a/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapabilityModel.java b/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapabilityModel.java new file mode 100644 index 000000000..aacf32ecd --- /dev/null +++ b/src/main/java/com/jcloisterzone/game/capability/BlackDragonCapabilityModel.java @@ -0,0 +1,31 @@ +package com.jcloisterzone.game.capability; + +import com.jcloisterzone.board.Position; +import io.vavr.collection.Vector; + +public class BlackDragonCapabilityModel { + + private final Vector visited; + private final int moves; + + public BlackDragonCapabilityModel(Vector visited, int moves) { + this.visited = visited; + this.moves = moves; + } + + public Vector getVisited() { + return visited; + } + + public BlackDragonCapabilityModel setVisited(Vector visited) { + return new BlackDragonCapabilityModel(visited, moves); + } + + public int getMoves() { + return moves; + } + + public BlackDragonCapabilityModel setMoves(int moves) { + return new BlackDragonCapabilityModel(visited, moves); + } +} diff --git a/src/main/java/com/jcloisterzone/game/phase/BlackDragonMovePhase.java b/src/main/java/com/jcloisterzone/game/phase/BlackDragonMovePhase.java index e9a1992d9..6b081fcc0 100644 --- a/src/main/java/com/jcloisterzone/game/phase/BlackDragonMovePhase.java +++ b/src/main/java/com/jcloisterzone/game/phase/BlackDragonMovePhase.java @@ -1,11 +1,11 @@ package com.jcloisterzone.game.phase; -import com.jcloisterzone.Player; -import com.jcloisterzone.action.MoveBlackDragonAction; +import com.jcloisterzone.action.MoveDragonAction; import com.jcloisterzone.board.Position; import com.jcloisterzone.board.pointer.BoardPointer; import com.jcloisterzone.figure.neutral.BlackDragon; import com.jcloisterzone.figure.neutral.NeutralFigure; +import com.jcloisterzone.game.capability.BlackDragonCapabilityModel; import com.jcloisterzone.game.capability.CountCapability; import com.jcloisterzone.game.capability.BlackDragonCapability; import com.jcloisterzone.game.state.ActionsState; @@ -15,7 +15,6 @@ import com.jcloisterzone.io.message.MoveNeutralFigureMessage; import com.jcloisterzone.random.RandomGenerator; import com.jcloisterzone.reducers.MoveNeutralFigure; -import io.vavr.Tuple3; import io.vavr.collection.HashSet; import io.vavr.collection.Set; import io.vavr.collection.Vector; @@ -28,27 +27,23 @@ public BlackDragonMovePhase(RandomGenerator random, Phase defaultNext) { @Override public StepResult enter(GameState state) { - BlackDragonCapability blackdragonCap = state.getCapabilities().get(BlackDragonCapability.class); - Vector visited = blackdragonCap.getVisitedPositions(state); - Integer moves = blackdragonCap.getMoves(state); - if (visited.size() == moves) { + BlackDragonCapabilityModel model = state.getCapabilityModel(BlackDragonCapability.class); + if (model.getVisited().size() == model.getMoves()) { return next(endBlackDragonMove(state)); } - Set availMoves = getAvailBlackDragonMoves(state, visited); + Set availMoves = getAvailBlackDragonMoves(state, model.getVisited()); if (availMoves.isEmpty()) { return next(endBlackDragonMove(state)); } BlackDragon blackdragon = state.getNeutralFigures().getBlackDragon(); return promote(state.setPlayerActions( - new ActionsState(state.getTurnPlayer(), new MoveBlackDragonAction(blackdragon.getId(), availMoves), false) + new ActionsState(state.getTurnPlayer(), new MoveDragonAction(blackdragon.getId(), availMoves), false) )); } private GameState endBlackDragonMove(GameState state) { state = state.addFlag(Flag.BLACK_DRAGON_MOVED); - state = state.mapCapabilityModel(BlackDragonCapability.class, blackdragon -> { - return new Tuple3<>(BlackDragonCapability.EMPTY_VISITED,0,blackdragon._3); - }); + state = state.setCapabilityModel(BlackDragonCapability.class, new BlackDragonCapabilityModel(BlackDragonCapability.EMPTY_VISITED, 0)); state = clearActions(state); return state; } @@ -80,27 +75,26 @@ public StepResult handleMoveNeutralFigure(GameState state, MoveNeutralFigureMess throw new IllegalArgumentException("Illegal neutral figure move"); } - BlackDragonCapability blackdragonCap = state.getCapabilities().get(BlackDragonCapability.class); + BlackDragonCapability cap = state.getCapabilities().get(BlackDragonCapability.class); + BlackDragonCapabilityModel model = state.getCapabilityModel(BlackDragonCapability.class); - Vector visited = blackdragonCap.getVisitedPositions(state); + Vector visited = model.getVisited(); Set availMoves = getAvailBlackDragonMoves(state, visited); - Position pos = ptr.getPosition(); + final Position pos = ptr.getPosition(); if (!availMoves.contains(pos)) { throw new IllegalArgumentException("Invalid black dragon move."); } - Position blackdragonPosition = state.getNeutralFigures().getBlackDragonDeployment(); - state = ( new MoveNeutralFigure<>((BlackDragon) fig, pos, state.getActivePlayer()) ).apply(state); - state = state.mapCapabilityModel(BlackDragonCapability.class, blackdragon -> { - return new Tuple3<>(blackdragon._1.append(blackdragonPosition),blackdragon._2,blackdragon._3); + state = state.mapCapabilityModel(BlackDragonCapability.class, m -> { + return m.setVisited(m.getVisited().append(pos)); }); - state = blackdragonCap.blackDragonOnTile(state, pos); + state = cap.clearTile(state, pos); return enter(state); } } diff --git a/src/main/java/com/jcloisterzone/game/phase/BlackDragonPhase.java b/src/main/java/com/jcloisterzone/game/phase/BlackDragonPhase.java new file mode 100644 index 000000000..2d31cc3b6 --- /dev/null +++ b/src/main/java/com/jcloisterzone/game/phase/BlackDragonPhase.java @@ -0,0 +1,25 @@ +package com.jcloisterzone.game.phase; + +import com.jcloisterzone.game.capability.BlackDragonCapability; +import com.jcloisterzone.game.capability.BlackDragonCapabilityModel; +import com.jcloisterzone.game.state.GameState; +import com.jcloisterzone.random.RandomGenerator; + +public class BlackDragonPhase extends Phase { + + private BlackDragonMovePhase blackDragonMovePhase; + + public BlackDragonPhase(RandomGenerator random, Phase defaultNext) { + super(random, defaultNext); + blackDragonMovePhase = new BlackDragonMovePhase(random, defaultNext); + } + + @Override + public StepResult enter(GameState state) { + BlackDragonCapabilityModel model = state.getCapabilityModel(BlackDragonCapability.class); + if (model.getMoves() > 0) { + return next(state, blackDragonMovePhase); + } + return next(state); + } +} diff --git a/src/main/java/com/jcloisterzone/game/phase/BlackDragonPlacePhase.java b/src/main/java/com/jcloisterzone/game/phase/BlackDragonPlacePhase.java index 3fc324db5..3116e5560 100644 --- a/src/main/java/com/jcloisterzone/game/phase/BlackDragonPlacePhase.java +++ b/src/main/java/com/jcloisterzone/game/phase/BlackDragonPlacePhase.java @@ -1,10 +1,14 @@ package com.jcloisterzone.game.phase; import com.jcloisterzone.Player; +import com.jcloisterzone.event.ScoreEvent; import com.jcloisterzone.game.capability.BlackDragonCapability; import com.jcloisterzone.game.state.GameState; import com.jcloisterzone.random.RandomGenerator; -import io.vavr.collection.Array; +import io.vavr.Predicates; +import io.vavr.collection.Stream; + +import java.util.HashMap; public class BlackDragonPlacePhase extends Phase { @@ -14,17 +18,31 @@ public BlackDragonPlacePhase(RandomGenerator random, Phase defaultNext) { @Override public StepResult enter(GameState state) { - Array scoreOnStart = state.getCapabilityModel(BlackDragonCapability.class)._3; - BlackDragonCapability blackdragonCap = state.getCapabilities().get(BlackDragonCapability.class); - - for(Player player : state.getPlayers().getPlayers() ) { - Integer scoreBefore = scoreOnStart.get(player.getIndex()); - Integer scoreCurrent = state.getPlayers().getScore().get(player.getIndex()); - Integer diff = scoreCurrent - scoreBefore; - if (diff>0 && ((scoreBefore % 50) + diff > 50)) { - state = blackdragonCap.moveBlackDragon(state, state.getLastPlaced().getPosition()); - break; - } + BlackDragonCapability cap = state.getCapabilities().get(BlackDragonCapability.class); + + java.util.Map receivedScore = new HashMap<>(); + for (Player player : state.getPlayers().getPlayers() ) { + receivedScore.put(player, 0); + } + + Stream.ofAll(state.getCurrentTurnPartEvents()) + .filter(Predicates.instanceOf(ScoreEvent.class)) + .map(ev -> (ScoreEvent) ev) + .forEach(ev -> { + for (ScoreEvent.ReceivedPoints rp : ev.getPoints()) { + receivedScore.put(rp.getPlayer(), receivedScore.get(rp.getPlayer()) + rp.getPoints()); + } + }); + + for (Player player : state.getPlayers().getPlayers() ) { + int playerReceivedPoints = receivedScore.get(player); + if (playerReceivedPoints > 0) { + int scoreCurrent = state.getPlayers().getScore().get(player.getIndex()); + if (scoreCurrent / 50 > (scoreCurrent - playerReceivedPoints) / 50) { + state = cap.moveBlackDragon(state, state.getLastPlaced().getPosition()); + break; + } + } } return next(state); diff --git a/src/main/java/com/jcloisterzone/game/phase/ScoringPhase.java b/src/main/java/com/jcloisterzone/game/phase/ScoringPhase.java index c9ae3df78..75f17f4b0 100644 --- a/src/main/java/com/jcloisterzone/game/phase/ScoringPhase.java +++ b/src/main/java/com/jcloisterzone/game/phase/ScoringPhase.java @@ -135,15 +135,6 @@ public StepResult enter(GameState state) { } } - BlackDragonCapability blackdragonCap = state.getCapabilities().get(BlackDragonCapability.class); - - Array scoreOnStart = state.getPlayers().getScore(); - - if (blackdragonCap != null && completedMutable.keySet().size()>0 && !state.hasFlag(Flag.BLACK_DRAGON_MOVED)) { - state = blackdragonCap.setModel(state, new Tuple3<>(blackdragonCap.EMPTY_VISITED,completedMutable.keySet().size(),blackdragonCap.getScore(state))); - return next(state, blackdragonMovePhase); - } - Map deployedWagonsBefore = getDeployedWagons(state); for (Capability cap : state.getCapabilities().toSeq()) { diff --git a/src/main/java/com/jcloisterzone/reducers/AbstractUndeploy.java b/src/main/java/com/jcloisterzone/reducers/AbstractUndeploy.java index 1dbed1bcc..8414968be 100644 --- a/src/main/java/com/jcloisterzone/reducers/AbstractUndeploy.java +++ b/src/main/java/com/jcloisterzone/reducers/AbstractUndeploy.java @@ -46,16 +46,4 @@ protected GameState undeployLonelySpecials(GameState state, Follower meeple, Fea return state; } - - protected GameState undeploy(GameState state, PlayEvent.PlayEventMeta meta, NeutralFigure figure, BoardPointer source, boolean forced, Player player) { - - NeutralFiguresState nfState = state.getNeutralFigures(); - nfState = nfState.setDeployedNeutralFigures(nfState.getDeployedNeutralFigures().remove(figure)); - state = state.setNeutralFigures(nfState); - - state = state.appendEvent( - new NeutralFigureReturned(meta, figure, source, forced, player) - ); - return state; - } } diff --git a/src/main/java/com/jcloisterzone/reducers/ReturnNeutralFigure.java b/src/main/java/com/jcloisterzone/reducers/ReturnNeutralFigure.java index 7e0896705..8d68d24ba 100644 --- a/src/main/java/com/jcloisterzone/reducers/ReturnNeutralFigure.java +++ b/src/main/java/com/jcloisterzone/reducers/ReturnNeutralFigure.java @@ -32,7 +32,7 @@ public GameState apply(GameState state) { ); state = state.setNeutralFigures(nfState); state = state.appendEvent( - new NeutralFigureReturned(PlayEventMeta.createWithPlayer(triggeringPlayer), figure, from, true, triggeringPlayer) + new NeutralFigureReturned(PlayEventMeta.createWithPlayer(triggeringPlayer), figure, from) ); return state; } diff --git a/src/main/java/com/jcloisterzone/reducers/UndeployNeutralFigure.java b/src/main/java/com/jcloisterzone/reducers/UndeployNeutralFigure.java deleted file mode 100644 index f1db09905..000000000 --- a/src/main/java/com/jcloisterzone/reducers/UndeployNeutralFigure.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.jcloisterzone.reducers; - -import com.jcloisterzone.board.pointer.BoardPointer; -import com.jcloisterzone.board.pointer.FeaturePointer; -import com.jcloisterzone.event.PlayEvent.PlayEventMeta; -import com.jcloisterzone.figure.neutral.NeutralFigure; -import com.jcloisterzone.game.state.GameState; -import com.jcloisterzone.game.state.NeutralFiguresState; - -public class UndeployNeutralFigure extends AbstractUndeploy { - - private final NeutralFigure figure; - /** true if meep le is returned different way than scoring feature */ - private final boolean forced; - - public UndeployNeutralFigure(NeutralFigure figure, boolean forced) { - this.figure = figure; - this.forced = forced; - } - - @Override - public GameState apply(GameState state) { - BoardPointer source = figure.getDeployment(state); - - PlayEventMeta metaWithPlayer = PlayEventMeta.createWithActivePlayer(state); - state = undeploy(state, metaWithPlayer, figure, source, forced, state.getActivePlayer()); - - return state; - } - - public boolean isForced() { - return forced; - } -}