Lukeidiot Posted May 25, 2016 Share Posted May 25, 2016 I am trying to make this complicated JavaScript into a more simple, workable approach. Here is a link to the full source code: http://paste.ubuntu.com/16651803/ I am trying to accomplish the following stats: 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: Link to comment https://forums.phpfreaks.com/topic/301259-how-to-simplify-this-javascript-into-something-useable/ Share on other sites More sharing options...
Solution requinix Posted May 25, 2016 Solution Share Posted May 25, 2016 (edited) Remember this? expected profit = bet * odds of losing / odds of winningLet'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 winningIf 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.01818Look 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 May 25, 2016 by requinix 1 Link to comment https://forums.phpfreaks.com/topic/301259-how-to-simplify-this-javascript-into-something-useable/#findComment-1533243 Share on other sites More sharing options...
Lukeidiot Posted May 25, 2016 Author Share Posted May 25, 2016 (edited) Remember this? expected profit = bet * odds of losing / odds of winningLet'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 winningIf 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.01818Look 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 May 26, 2016 by requinix removing site because I'm peeved Link to comment https://forums.phpfreaks.com/topic/301259-how-to-simplify-this-javascript-into-something-useable/#findComment-1533246 Share on other sites More sharing options...
requinix Posted May 26, 2016 Share Posted May 26, 2016 Cloning websites is copyright infringement. I'll be locking any other threads I see about this. Link to comment https://forums.phpfreaks.com/topic/301259-how-to-simplify-this-javascript-into-something-useable/#findComment-1533247 Share on other sites More sharing options...
Recommended Posts