function settleBet(address gambler) public {
        
        ActiveBet storage bet = activeBets[gambler];
        require (bet.amount != 0);

        
        require (block.number > bet.placeBlockNumber + BLOCK_DELAY);
        require (block.number <= bet.placeBlockNumber + BET_EXPIRATION_BLOCKS);

        
        
        
        bytes32 entropy = keccak256(gambler, blockhash(bet.placeBlockNumber + BLOCK_DELAY));

        uint256 diceWin = 0;
        uint256 jackpotWin = 0;

        
        uint256 rollModulo = getRollModulo(bet.gameId);
        uint256 dice = uint256(entropy) % rollModulo;

        uint256 rollUnder = getRollUnder(rollModulo, bet.mask);
        uint256 diceWinAmount = getDiceWinAmount(bet.amount, rollModulo, rollUnder);

        
        if ((2 ** dice) & bet.mask != 0) {
            diceWin = diceWinAmount;
        }

        
        lockedInBets -= uint128(diceWinAmount);

        
        if (bet.amount >= MIN_JACKPOT_BET) {
            
            
            uint256 jackpotRng = (uint256(entropy) / rollModulo) % JACKPOT_MODULO;

            
            if (jackpotRng == 0) {
                jackpotWin = jackpotSize;
                jackpotSize = 0;
            }
        }

        
        delete activeBets[gambler];

        
        uint256 totalWin = diceWin + jackpotWin;

        if (totalWin == 0) {
            totalWin = 1 wei;
        }

        if (jackpotWin > 0) {
            emit JackpotPayment(gambler, jackpotWin);
        }

        
        sendFunds(gambler, totalWin, diceWin);
    }