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);
});
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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,

View file

@ -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);
}
}

View file

@ -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);
}
}