Game: fixed mulligan's copy code (can potentially fix empty hands or loses on game start in rare use cases, e.g. with AI);

This commit is contained in:
Oleg Agafonov 2021-07-06 13:58:04 +04:00
parent fa8c0259d0
commit bb4f36fddf
6 changed files with 35 additions and 14 deletions

View file

@ -390,5 +390,4 @@ public class LondonMulliganTest extends MulliganTestBase {
scenario.assertSizes(0, 40); scenario.assertSizes(0, 40);
}); });
} }
} }

View file

@ -15,9 +15,10 @@ public class CanadianHighlanderMulligan extends VancouverMulligan {
super(freeMulligans); super(freeMulligans);
} }
@Override CanadianHighlanderMulligan(final CanadianHighlanderMulligan mulligan) {
public CanadianHighlanderMulligan copy() { super(mulligan);
return new CanadianHighlanderMulligan(getFreeMulligans());
this.usedMulligans.putAll(mulligan.usedMulligans);
} }
private String getNextMulligan(String mulligan) { private String getNextMulligan(String mulligan) {
@ -116,9 +117,13 @@ public class CanadianHighlanderMulligan extends VancouverMulligan {
} }
game.fireInformEvent(new StringBuilder(player.getLogName()) game.fireInformEvent(new StringBuilder(player.getLogName())
.append(" mulligans to ") .append(" mulligans to ")
.append(Integer.toString(numToMulliganTo)) .append(numToMulliganTo)
.append(numToMulliganTo == 1 ? " card" : " cards").toString()); .append(numToMulliganTo == 1 ? " card" : " cards").toString());
player.drawCards(numToMulliganTo, null, game); player.drawCards(numToMulliganTo, null, game);
} }
@Override
public CanadianHighlanderMulligan copy() {
return new CanadianHighlanderMulligan(this);
}
} }

View file

@ -21,6 +21,13 @@ public class LondonMulligan extends Mulligan {
super(freeMulligans); super(freeMulligans);
} }
LondonMulligan(final LondonMulligan mulligan) {
super(mulligan);
this.startingHandSizes.putAll(mulligan.startingHandSizes);
this.openingHandSizes.putAll(mulligan.openingHandSizes);
}
@Override @Override
public void executeMulliganPhase(Game game, int startingHandSize) { public void executeMulliganPhase(Game game, int startingHandSize) {
/* /*
@ -115,9 +122,6 @@ public class LondonMulligan extends Mulligan {
@Override @Override
public LondonMulligan copy() { public LondonMulligan copy() {
LondonMulligan mulligan = new LondonMulligan(getFreeMulligans()); return new LondonMulligan(this);
mulligan.openingHandSizes.putAll(openingHandSizes);
mulligan.startingHandSizes.putAll(startingHandSizes);
return mulligan;
} }
} }

View file

@ -16,6 +16,12 @@ public abstract class Mulligan implements Serializable {
this.freeMulligans = freeMulligans; this.freeMulligans = freeMulligans;
} }
Mulligan(final Mulligan mulligan) {
super();
this.freeMulligans = mulligan.freeMulligans;
this.usedFreeMulligans.putAll(mulligan.usedFreeMulligans);
}
public void executeMulliganPhase(Game game, int startingHandSize) { public void executeMulliganPhase(Game game, int startingHandSize) {
/* /*
* 103.4. Each player draws a number of cards equal to their starting hand size, * 103.4. Each player draws a number of cards equal to their starting hand size,

View file

@ -11,6 +11,10 @@ public class ParisMulligan extends Mulligan {
super(freeMulligans); super(freeMulligans);
} }
ParisMulligan(final ParisMulligan mulligan) {
super(mulligan);
}
@Override @Override
public int mulliganDownTo(Game game, UUID playerId) { public int mulliganDownTo(Game game, UUID playerId) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
@ -57,11 +61,11 @@ public class ParisMulligan extends Mulligan {
} }
@Override @Override
public void endMulligan(Game game, UUID playerId) {} public void endMulligan(Game game, UUID playerId) {
}
@Override @Override
public ParisMulligan copy() { public ParisMulligan copy() {
return new ParisMulligan(getFreeMulligans()); return new ParisMulligan(this);
} }
} }

View file

@ -11,6 +11,10 @@ public class VancouverMulligan extends ParisMulligan {
super(freeMulligans); super(freeMulligans);
} }
VancouverMulligan(final VancouverMulligan mulligan) {
super(mulligan);
}
@Override @Override
public void executeMulliganPhase(Game game, int startingHandSize) { public void executeMulliganPhase(Game game, int startingHandSize) {
super.executeMulliganPhase(game, startingHandSize); super.executeMulliganPhase(game, startingHandSize);
@ -30,7 +34,6 @@ public class VancouverMulligan extends ParisMulligan {
@Override @Override
public VancouverMulligan copy() { public VancouverMulligan copy() {
return new VancouverMulligan(getFreeMulligans()); return new VancouverMulligan(this);
} }
} }