From bb4f36fddf321c9dade87f3cbfd90d6991f16d37 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 6 Jul 2021 13:58:04 +0400 Subject: [PATCH] Game: fixed mulligan's copy code (can potentially fix empty hands or loses on game start in rare use cases, e.g. with AI); --- .../org/mage/test/mulligan/LondonMulliganTest.java | 1 - .../game/mulligan/CanadianHighlanderMulligan.java | 13 +++++++++---- .../java/mage/game/mulligan/LondonMulligan.java | 12 ++++++++---- Mage/src/main/java/mage/game/mulligan/Mulligan.java | 6 ++++++ .../main/java/mage/game/mulligan/ParisMulligan.java | 10 +++++++--- .../java/mage/game/mulligan/VancouverMulligan.java | 7 +++++-- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/mulligan/LondonMulliganTest.java b/Mage.Tests/src/test/java/org/mage/test/mulligan/LondonMulliganTest.java index 03dc1a6747..99b329ee01 100644 --- a/Mage.Tests/src/test/java/org/mage/test/mulligan/LondonMulliganTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/mulligan/LondonMulliganTest.java @@ -390,5 +390,4 @@ public class LondonMulliganTest extends MulliganTestBase { scenario.assertSizes(0, 40); }); } - } diff --git a/Mage/src/main/java/mage/game/mulligan/CanadianHighlanderMulligan.java b/Mage/src/main/java/mage/game/mulligan/CanadianHighlanderMulligan.java index 7ded68c343..29e6e579c4 100644 --- a/Mage/src/main/java/mage/game/mulligan/CanadianHighlanderMulligan.java +++ b/Mage/src/main/java/mage/game/mulligan/CanadianHighlanderMulligan.java @@ -15,9 +15,10 @@ public class CanadianHighlanderMulligan extends VancouverMulligan { super(freeMulligans); } - @Override - public CanadianHighlanderMulligan copy() { - return new CanadianHighlanderMulligan(getFreeMulligans()); + CanadianHighlanderMulligan(final CanadianHighlanderMulligan mulligan) { + super(mulligan); + + this.usedMulligans.putAll(mulligan.usedMulligans); } private String getNextMulligan(String mulligan) { @@ -116,9 +117,13 @@ public class CanadianHighlanderMulligan extends VancouverMulligan { } game.fireInformEvent(new StringBuilder(player.getLogName()) .append(" mulligans to ") - .append(Integer.toString(numToMulliganTo)) + .append(numToMulliganTo) .append(numToMulliganTo == 1 ? " card" : " cards").toString()); player.drawCards(numToMulliganTo, null, game); } + @Override + public CanadianHighlanderMulligan copy() { + return new CanadianHighlanderMulligan(this); + } } diff --git a/Mage/src/main/java/mage/game/mulligan/LondonMulligan.java b/Mage/src/main/java/mage/game/mulligan/LondonMulligan.java index 7bf13dccab..99bc94d36d 100644 --- a/Mage/src/main/java/mage/game/mulligan/LondonMulligan.java +++ b/Mage/src/main/java/mage/game/mulligan/LondonMulligan.java @@ -21,6 +21,13 @@ public class LondonMulligan extends Mulligan { super(freeMulligans); } + LondonMulligan(final LondonMulligan mulligan) { + super(mulligan); + + this.startingHandSizes.putAll(mulligan.startingHandSizes); + this.openingHandSizes.putAll(mulligan.openingHandSizes); + } + @Override public void executeMulliganPhase(Game game, int startingHandSize) { /* @@ -115,9 +122,6 @@ public class LondonMulligan extends Mulligan { @Override public LondonMulligan copy() { - LondonMulligan mulligan = new LondonMulligan(getFreeMulligans()); - mulligan.openingHandSizes.putAll(openingHandSizes); - mulligan.startingHandSizes.putAll(startingHandSizes); - return mulligan; + return new LondonMulligan(this); } } diff --git a/Mage/src/main/java/mage/game/mulligan/Mulligan.java b/Mage/src/main/java/mage/game/mulligan/Mulligan.java index 52bab013f7..6f8a2863bf 100644 --- a/Mage/src/main/java/mage/game/mulligan/Mulligan.java +++ b/Mage/src/main/java/mage/game/mulligan/Mulligan.java @@ -16,6 +16,12 @@ public abstract class Mulligan implements Serializable { this.freeMulligans = freeMulligans; } + Mulligan(final Mulligan mulligan) { + super(); + this.freeMulligans = mulligan.freeMulligans; + this.usedFreeMulligans.putAll(mulligan.usedFreeMulligans); + } + public void executeMulliganPhase(Game game, int startingHandSize) { /* * 103.4. Each player draws a number of cards equal to their starting hand size, diff --git a/Mage/src/main/java/mage/game/mulligan/ParisMulligan.java b/Mage/src/main/java/mage/game/mulligan/ParisMulligan.java index 33b2ae0b76..37f933a2d5 100644 --- a/Mage/src/main/java/mage/game/mulligan/ParisMulligan.java +++ b/Mage/src/main/java/mage/game/mulligan/ParisMulligan.java @@ -11,6 +11,10 @@ public class ParisMulligan extends Mulligan { super(freeMulligans); } + ParisMulligan(final ParisMulligan mulligan) { + super(mulligan); + } + @Override public int mulliganDownTo(Game game, UUID playerId) { Player player = game.getPlayer(playerId); @@ -57,11 +61,11 @@ public class ParisMulligan extends Mulligan { } @Override - public void endMulligan(Game game, UUID playerId) {} + public void endMulligan(Game game, UUID playerId) { + } @Override public ParisMulligan copy() { - return new ParisMulligan(getFreeMulligans()); + return new ParisMulligan(this); } - } diff --git a/Mage/src/main/java/mage/game/mulligan/VancouverMulligan.java b/Mage/src/main/java/mage/game/mulligan/VancouverMulligan.java index 9a131224d9..790702d63d 100644 --- a/Mage/src/main/java/mage/game/mulligan/VancouverMulligan.java +++ b/Mage/src/main/java/mage/game/mulligan/VancouverMulligan.java @@ -11,6 +11,10 @@ public class VancouverMulligan extends ParisMulligan { super(freeMulligans); } + VancouverMulligan(final VancouverMulligan mulligan) { + super(mulligan); + } + @Override public void executeMulliganPhase(Game game, int startingHandSize) { super.executeMulliganPhase(game, startingHandSize); @@ -30,7 +34,6 @@ public class VancouverMulligan extends ParisMulligan { @Override public VancouverMulligan copy() { - return new VancouverMulligan(getFreeMulligans()); + return new VancouverMulligan(this); } - }