Advertisement
KK20

Max TER

Dec 19th, 2017
2,960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         MaxTER
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.3
  5. // @description  Adds a MAX TER button to /u/au_travail's Neopets Food Club page
  6. // @author       KK20
  7. // @match        http://neofoodclub.fr/*
  8. // @require      https://code.jquery.com/jquery-3.1.0.min.js
  9. // @grant        none
  10. // ==/UserScript==
  11. //  Note: Algorithm largely based on https://pastebin.com/322YjaZV, credits to the original author
  12. // Version 1.3
  13. //  - Now works with /oldpage.html
  14. //  -
  15. // Version 1.2
  16. //  - If using "custom" mode...
  17. //    - Use "Custom Odds" instead of "Current Odds" in calculations
  18. //    - Use "Custom Probabilities" instead of "Std Prob" in calculations
  19. // Version 1.1
  20. //  - Fixed ALWAYS_USE_MAX_BET bug; now properly ignores bets that have a max bet lower than your current max
  21.  
  22. //===[ C O N F I G U R E ]====================================================
  23. // Disregards any bets that use less than your max bet (either true or false)
  24. const ALWAYS_USE_MAX_BET = false;
  25. //============================================================================
  26.  
  27. this.$ = this.jQuery = jQuery.noConflict(true);
  28.  
  29. var old_page = window.location.pathname == '/oldpage.html'
  30.  
  31. // Initialize
  32. var maxbet, winnings, winchance, betcap, expectedratio, vm;
  33.  
  34. var pirate_combo = {};
  35. var betcaps = {};
  36. var top_ratios = [];
  37.  
  38. // Takes in 5 pirates and calculates the win rate, winnings, and net expected for each pirate
  39. function calculateCombination(a, b, c, d, e) {
  40.     var odds, probability, prob_denominator = 1;
  41.     if (vm.displayMode === "custom") {
  42.         odds = vm.customOdds;
  43.         probability = vm.customProbabilities;
  44.         var p = [a, b, c, d, e];
  45.         for (var i = 0; i < p.length; i++)
  46.             if (p[i] !== 0) prob_denominator *= 100;
  47.     } else {
  48.         odds = vm.currentOdds;
  49.         probability = vm.probabilities.std;
  50.     }
  51.     var netexpected;
  52.  
  53.     var total_odds = odds[0][a] * odds[1][b] * odds[2][c] * odds[3][d] * odds[4][e];
  54.     winnings = maxbet * total_odds;
  55.     if (winnings > 1000000)
  56.         winnings = 1000000;
  57.     winchance = probability[0][a] * probability[1][b] * probability[2][c] * probability[3][d] * probability[4][e] / prob_denominator;
  58.     betcap = Math.floor(1000000 / total_odds);
  59.     if (ALWAYS_USE_MAX_BET) {
  60.         if (betcap < maxbet) {
  61.             betcap = 0;
  62.             expectedratio = 0;
  63.             netexpected = 0;
  64.         } else {
  65.             betcap = maxbet;
  66.             expectedratio = winchance * winnings / betcap;
  67.             netexpected = (expectedratio - 1) * betcap;
  68.         }
  69.     } else {
  70.         if (betcap > maxbet) betcap = maxbet;
  71.         expectedratio = winchance * winnings / betcap;
  72.         netexpected = (expectedratio - 1) * betcap;
  73.     }
  74.     betcaps["" + a + b + c + d + e] = betcap;
  75.     pirate_combo["" + a + b + c + d + e] = netexpected;
  76. }
  77.  
  78. // The main method
  79. function calc_maxter() {
  80.     vm = window.wrappedJSObject.vm;
  81.     maxbet = vm.maxBet;
  82.     pirate_combo = {};
  83.     betcaps = {};
  84.     top_ratios = [];
  85.  
  86.     var index = 1;
  87.     var i;
  88.  
  89.     // Calculate all the winnings, odds, etc. for every pirate combination
  90.     var a_, b_, c_, d_, e_;
  91.     for (a_ = 0; a_ < 5; a_++) {
  92.         for (b_ = 0; b_ < 5; b_++) {
  93.             for (c_ = 0; c_ < 5; c_++) {
  94.                 for (d_ = 0; d_ < 5; d_++) {
  95.                     for (e_ = 0; e_ < 5; e_++) {
  96.                         calculateCombination(a_, b_, c_, d_, e_);
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.     }
  102.     // Sort by highest expected ratio (i.e. MAX TER)
  103.     for (var key in pirate_combo) top_ratios.push([key, pirate_combo[key]]);
  104.     top_ratios.sort(function(a, b) {
  105.         a = a[1];
  106.         b = b[1];
  107.         return b - a;
  108.     });
  109.  
  110.     var bet, arena, pirate;
  111.     var result = "";
  112.     for (bet = 0; bet < 10; bet++) {
  113.         // Set the bet amounts for each bet
  114.         vm.betAmounts[bet + 1] = betcaps[top_ratios[bet][0]];
  115.         // Parse the pirate combinations to generate a link containing the MAX TER bets
  116.         for (arena = 0; arena < 5; arena++) {
  117.             pirate = top_ratios[bet][0][arena];
  118.             if (old_page)
  119.                 check_radio(arena, pirate, bet);
  120.             else
  121.                 result += pirate;
  122.         }
  123.     }
  124.     if (old_page) return;
  125.  
  126.     var linkCode = "";
  127.     for (i = 0; i < result.length; i += 2) {
  128.         linkCode += String.fromCharCode(97 + parseInt(result.substring(i, i + 2), 5));
  129.     }
  130.     // Reload the page with the new bets
  131.     window.location = "http://neofoodclub.fr/#round=" + vm.round + "&b=" + linkCode;
  132. }
  133.  
  134. function check_radio(arena_id, pirate_row, bet_number) {
  135.     $("tbody:eq("+arena_id+") tr:eq("+pirate_row+") input:radio:eq("+(bet_number)+")").prop("checked", true).trigger("click");
  136. }
  137.  
  138. // Adds MAX TER button to the top of the page and sets an on-click action to call the main method
  139. $("div#el a:first").after('<br><input id="maxter" type="button" value="Max TER"/>');
  140. $("input#maxter").on("click", calc_maxter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement