Test framework: added support for flip coin tests (command: setFlipCoinResult);

This commit is contained in:
Oleg Agafonov 2020-12-14 03:00:38 +04:00
parent fde24f349f
commit c1dfbbda63
12 changed files with 162 additions and 24 deletions

View file

@ -444,6 +444,8 @@ public interface Player extends MageItem, Copyable<Player> {
boolean flipCoin(Ability source, Game game, boolean winnable, List<UUID> appliedEffects);
boolean flipCoinResult(Game game);
int rollDice(Ability source, Game game, int numSides);
int rollDice(Ability source, Game game, List<UUID> appliedEffects, int numSides);

View file

@ -2752,7 +2752,7 @@ public abstract class PlayerImpl implements Player, Serializable {
chosen = this.chooseUse(Outcome.Benefit, "Heads or tails?", "", "Heads", "Tails", source, game);
game.informPlayers(getLogName() + " chose " + CardUtil.booleanToFlipName(chosen));
}
boolean result = RandomUtil.nextBoolean();
boolean result = this.flipCoinResult(game);
FlipCoinEvent event = new FlipCoinEvent(playerId, source, result, chosen, winnable);
event.addAppliedEffects(appliedEffects);
game.replaceEvent(event);
@ -2762,7 +2762,7 @@ public abstract class PlayerImpl implements Player, Serializable {
boolean canChooseHeads = event.getResult();
boolean canChooseTails = !event.getResult();
for (int i = 1; i < event.getFlipCount(); i++) {
boolean tempFlip = RandomUtil.nextBoolean();
boolean tempFlip = this.flipCoinResult(game);
canChooseHeads = canChooseHeads || tempFlip;
canChooseTails = canChooseTails || !tempFlip;
game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(tempFlip));
@ -2789,6 +2789,15 @@ public abstract class PlayerImpl implements Player, Serializable {
return event.getResult();
}
/**
* Return result for next flip coint try (can be contolled in tests)
* @return
*/
@Override
public boolean flipCoinResult(Game game) {
return RandomUtil.nextBoolean();
}
@Override
public int rollDice(Ability source, Game game, int numSides) {
return this.rollDice(source, game, null, numSides);