raises = 0;
notifyBoardUpdated();
while (playersToAct > 0) {
rotateActor();
Action action = null;
if (actor.isAllIn()) {
// Player is all-in, so must check.
action = Action.CHECK;
playersToAct--;
} else {
// Otherwise allow client to act.
Set<Action> allowedActions = getAllowedActions(actor);
action = actor.getClient().act(minBet, bet, allowedActions);
// Verify chosen action to guard against broken clients (accidental or on purpose).
if (!allowedActions.contains(action)) {
if (!(action instanceof BetAction && allowedActions.contains(Action.BET)) && !(action instanceof RaiseAction && allowedActions.contains(Action.RAISE))) {
throw new IllegalStateException(String.format("Player '%s' acted with illegal %s action", actor, action));
}
}
playersToAct--;
if (action == Action.CHECK) {
// Do nothing.
} else if (action == Action.CALL) {
int betIncrement = bet - actor.getBet();
if (betIncrement > actor.getCash()) {
betIncrement = actor.getCash();
}
actor.payCash(betIncrement);
actor.setBet(actor.getBet() + betIncrement);
contributePot(betIncrement);
} else if (action instanceof BetAction) {
int amount = (tableType == TableType.FIXED_LIMIT) ? minBet : action.getAmount();
if (amount < minBet && amount < actor.getCash()) {
throw new IllegalStateException("Illegal client action: bet less than minimum bet!");
}
if (amount > actor.getCash() && actor.getCash() >= minBet) {
throw new IllegalStateException("Illegal client action: bet more cash than you own!");
}
bet = amount;
minBet = amount;
int betIncrement = bet - actor.getBet();
if (betIncrement > actor.getCash()) {
betIncrement = actor.getCash();
}
actor.setBet(bet);
actor.payCash(betIncrement);
contributePot(betIncrement);
lastBettor = actor;
playersToAct = (tableType == TableType.FIXED_LIMIT) ? activePlayers.size() : (activePlayers.size() - 1);
} else if (action instanceof RaiseAction) {
int amount = (tableType == TableType.FIXED_LIMIT) ? minBet : action.getAmount();
if (amount < minBet && amount < actor.getCash()) {
throw new IllegalStateException("Illegal client action: raise less than minimum bet!");
}
if (amount > actor.getCash() && actor.getCash() >= minBet) {
throw new IllegalStateException("Illegal client action: raise more cash than you own!");