@Override
public void onPlayerChips(PlayerChips playerChips) {
try {
//update sitting players
PlayerId id = getId(playerChips);
PlayerState player = getGameState().getPlayer(id);
if(player!= null && inWinnerZone.get()){
int prevStack = player.getStack();
if(prevStack != playerChips.getMoney()){
dispatch(new WinnerEvent(ImmutableSet.of(new Winner(id,playerChips.getMoney()-prevStack))));
}
}
//refresh state
player = getGameState().getPlayer(id);
//sanity checks
if(player!=null){
if(player.getStack()!=playerChips.getMoney()){
String msg = "Stack of "+id+" is "+player.getStack()+" but should be "+playerChips.getMoney();
throw new IllegalStateException(msg);
}
if(!endLastRound.get() && player.getBet()!=playerChips.getBet()){
String msg = "Bet of "+id+" is "+player.getBet()+" but should be "+playerChips.getBet();
throw new IllegalStateException(msg);
}
}
///update arrivedPlayers