public BetState(final GameState gameState, final BetEvent event) {
super(gameState);
this.event = event;
PlayerState oldPlayerState = super.getPlayer(event.getPlayerId());
betAfterBlindCase = Round.PREFLOP.equals(gameState.getRound());
if(betAfterBlindCase && gameState.getDeficit(event.getPlayerId())>0)
throw new IllegalStateException("Can't bet in the preflop round when you have a deficit to pay.");
final int newStack = oldPlayerState.getStack() - event.getAmount();
this.newPotSize = super.getRoundPotSize() + event.getAmount();
this.playerState = new ForwardingPlayerState(oldPlayerState) {
@Override
public int getStack() {
return newStack;
}
@Override
public int getBet() {
if(betAfterBlindCase){
return super.getBet()+BetState.this.event.getAmount();
}
return BetState.this.event.getAmount();
}
@Override
public int getTotalInvestment() {
return super.getTotalInvestment()+BetState.this.event.getAmount();
}
@Override
public PlayerId getPlayerId() {
return BetState.this.event.getPlayerId();
}
@Override
public boolean hasFolded() {
return false;
}
@Override
public boolean hasBeenDealt() {
return true;
}
/**
* {@inheritDoc}
*/
@Override
public List<Integer> getBetProgression() {
if(betAfterBlindCase){
List<Integer> result = new ArrayList<Integer>();
PlayerId lastBettorId = gameState.getLastBettor();
PlayerState lastBettor = gameState.getPlayer(lastBettorId);
List<Integer> previousBetProgression = lastBettor.getBetProgression();
result.addAll(previousBetProgression);
result.add(event.getAmount());
return Collections.unmodifiableList(result);
}
return Collections.singletonList(getBet());