Jump to content

How to simplify this JavaScript into something useable?


Lukeidiot
Go to solution Solved by requinix,

Recommended Posts

I am trying to make this complicated JavaScript into a more simple, workable approach.

 

Here is a link to the full source code:


 

I am trying to accomplish the following stats:

666ff1b8fa8065f0b37d9fff64be6e71.png

 

End Goal: Calculate Profit for Roll High and Roll Low

 

Here is the function I believe is responsible for calculating:

 

   namespace("Rollin.Casino.Dice.Stats", function() {
        var t, e;
        return t = namespace.use("Rollin.Casino.Dice.Dice"), e = function() {
            function e(t, e) {
                this.number = t, this.dice = e
            }
            return e.prototype.decimal = 5, e.prototype.getData = function(e, n, r) {
                var i, o, s, a, u;
                switch (r > t.MAX_NUMBER - 1 && (r = t.MAX_NUMBER - 1), r < t.MIN_NUMBER + 1 && (r = t.MIN_NUMBER + 1), i = this.dice.getFee(), n) {
                    case t.PREDICTION_BIGGER:
                        o = (100 - i) / (t.MAX_NUMBER - r), s = t.MAX_NUMBER - r;
                        break;
                    default:
                        o = (100 - i) / r, s = r
                }
                return a = e * o, u = a - e, a > 99999 && (a = 99999), u > 99999 && (u = 99999), a = this.number.floorDecimal(a, this.decimal), u = this.number.floorDecimal(u, this.decimal), this.number.isNaN(a) && (a = 0), this.number.isNaN(u) && (u = 0), {
                    multiplier: o,
                    odds: s,
                    payout: a,
                    profit: u
                }
            }, e
        }()
    }),

 

Here is the same function being used:

 

   t.prototype.changeStats_ = function() {
                var t, n, r, i;
                return t = this.dice.betAmount, i = this.dice.betNumber, n = this.stats.getData(t, e.PREDICTION_BIGGER, i), r = this.stats.getData(t, e.PREDICTION_SMALLER, i), this.element.find(".stats.high .profit").text(n.profit), this.element.find(".stats.high .odds").text(n.odds + "%"), this.element.find(".stats.low .profit").text(r.profit), this.element.find(".stats.low .odds").text(r.odds + "%")
            }

 

So, how can I make a simple function where I can calculate the profit by using something

 

such as this: calculateRollHighProfile(betsize, predictionNumber, houseEdge);

 

Live example: https://rollin.io

 

Please note: Profits are affected by house edges below:

5aaf071d24f43c8a33e4f44f50c5af07.png

Link to comment
Share on other sites

  • Solution

Remember this?

expected profit = bet * odds of losing / odds of winning
Let's revise that a little bit to be more clear what it means. (It was late night when I wrote that and it made sense to me.)

expected profit = bet * (odds of not winning - house edge) / odds of winning
If you predict 88 then your high roll must be within 89-99 to win. That's 99 - 88 = 11 out of 100 (or 100% - 88% - 1% = 11%). Not winning would thus be 89%. If you wager 5 and the house gets 0.96% then

expected profit = 5 * (89 - 0.96) / 11 = 40.01818
Look familiar? I imagine that logic is buried somewhere in the Javascript, though it looks like they're using an alternative form that calculates gross and not net winnings. Same difference. Edited by requinix
  • Like 1
Link to comment
Share on other sites

Remember this?

expected profit = bet * odds of losing / odds of winning
Let's revise that a little bit to be more clear what it means. (It was late night when I wrote that and it made sense to me.)

expected profit = bet * (odds of not winning - house edge) / odds of winning
If you predict 88 then your high roll must be within 89-99 to win. That's 99 - 88 = 11 out of 100 (or 100% - 88% - 1% = 11%). Not winning would thus be 89%. If you wager 5 and the house gets 0.96% then

expected profit = 5 * (89 - 0.96) / 11 = 40.01818
Look familiar? I imagine that logic is buried somewhere in the Javascript, though it looks like they're using an alternative form that calculates gross and not net winnings. Same difference.

 

 

Here is what I managed to come up with:

 

    function calculateRollLowProfit(game_int, bet, house_edge){


        var roll = game_int - 1;
        var game_int = 100 - game_int;
        var chance = (100 - game_int);
        var multiplier = (house_edge / chance);


        payout = bet * multiplier - bet;
        payout = toFixed(payout, 5);
        payout = parseFloat(payout);


        $('.low .profit2').text(payout);


    }
    function calculateRollHighProfit(game_int, bet, house_edge){


        var roll = game_int - 1;
        var chance = (99 - game_int);
        var multiplier = (house_edge / chance);


        payout = bet * multiplier - bet;
        payout = toFixed(payout, 5);
        payout = parseFloat(payout);


        $('.high .profit2').text(payout);


    }
Preview: <site> Edited by requinix
removing site because I'm peeved
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.