Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.45 KB | None | 0 0
  1. var config = {
  2. baseBet: { type: 'balance', label: 'BaseBet', value: 500 },
  3. betMult: { type: 'multiplier', label: 'BetMulti', value: 1.1 },
  4. frompayout: { type: 'multiplier', label: 'From Payout', value: 10 },
  5. topayout: { type: 'multiplier', label: 'To Payout', value: 10 },
  6. calcPrc: { type: 'text', label: 'Precision', value: '1e3' },
  7. betProb: { type: 'text', label: 'Confidence', value: '1.0' },
  8. intervalling: { type: 'number', value: 0 },
  9. whenToStop: { type: "number", label: "Reset bet on Loss balance less than < %", value: 0 },
  10. whenToStopProfit: { type: "number", label: "Reset bet on Profit, when balance higher than > %", value: 0 },
  11. stopScript: { type: "checkbox", label: "Stop Script after reach %", value: false },
  12. };
  13.  
  14. /** ----------- -RULES- ------------------------ */
  15. var rules_allow_max_streak = false;
  16.  
  17. var rules_max_streak = 35;
  18. var rules_how_long_recover_attempts = 3;
  19. var rules_confident_recover = Number(eval(config.betProb.value)) + 0.01;
  20.  
  21. var recovery_mul = 2;
  22.  
  23. /** ------------ ----- ------------------------- */
  24.  
  25. var Targets = [], engine = this, game = 0, debug = false;
  26. var session_profit = 0, profit_total = 0, PROFIT = 0;
  27.  
  28. /** ------------ -RULES VARS- ------------------ */
  29.  
  30. var recovery_attempt = 0;
  31. var global_playing = 0;
  32.  
  33. /** ------------ ----- ------------------------- */
  34.  
  35. var req = Number(eval(config.betProb.value));
  36. var prc = Number(config.calcPrc.value);
  37.  
  38. /** ------------ ----- ------------------------- */
  39.  
  40. var lock_balance = (this.balance / 100) * (config.whenToStop.value / 100);
  41. var lock_balance_profit = (this.balance / 100) * (config.whenToStopProfit.value / 100);
  42. var lock_normal = (this.balance / 100);
  43.  
  44. /** ------------ ----- --------------- */
  45. const rb = (bet) => { return Math.max(100, Math.round(bet / 100) * 100); }
  46.  
  47. class Target {
  48. constructor (payout, bet = config.baseBet.value) {
  49. this.b = bet; /* Base bet */
  50. this.p = payout; /* Payout */
  51. this.cb = bet; /* Current Bet */
  52. this.m = payout / (payout - config.betMult.value); /* Payout Multiplier */
  53. this.n = 0; /* Lose Amount in rolls */
  54. this.prob = Math.round(geoProb(payout, this.n) * prc) / prc; /* Probability */
  55. this.playing = false; /* State of Playing */
  56. this.mss = 0; /* Max Streak Seen */
  57. this.sn = 0; /* Streak Number */
  58. Targets.push(this); /* Add Target to Array of Targets */
  59. console.log(`Created target ${this.p}x successfully.`)
  60. };
  61.  
  62. update(result) {
  63. if (this.sn >= rules_max_streak && rules_allow_max_streak) { /* Statement of Rules - Allow limitation of Max Streak */
  64. this.cb = this.b; /* Set Current Bet to Base Bet */
  65. this.sn = 0; /* Reset Streak Number */
  66. recovery_attempt = rules_how_long_recover_attempts;
  67. profit_total += session_profit
  68.  
  69. this.playing = false; /* Disable Playing Phase */
  70. global_playing = 0; /* Set index to zero of active target */
  71. }
  72.  
  73. if (result.multiplier < this.p) {
  74. this.sn++; /* Increase Streak Number */
  75. session_profit -= this.cb;
  76. PROFIT -= this.cb;
  77.  
  78. this.cb *= this.m; /* Multiply Current Bet */
  79.  
  80. } else {
  81. this.playing = false; /* Disable Playing Phase */
  82. global_playing = 0; /* Set index to zero of active target */
  83.  
  84. if (this.sn > this.mss){ this.mss = this.sn } /* Update Max Streak Seen */
  85.  
  86. this.sn = 0; /* Reset Streak Number */
  87. session_profit += this.cb * (this.p - 1);
  88. PROFIT += this.cb * (this.p - 1);
  89.  
  90. profit_total += session_profit;
  91.  
  92. if (recovery_attempt > 0) {
  93. this.cb = this.b * recovery_mul;
  94. recovery_attempt--;
  95. } else {
  96. this.cb = this.b; /* Set Current Bet to Base Bet */
  97. }
  98. if (profit_total < 0) { this.cb *= recovery_mul; }
  99. game = 0; /* Reset game counter */
  100. }
  101. };
  102.  
  103. async play(context) {
  104. if (this.prob >= req) {
  105. if (global_playing == 0) {
  106. global_playing = this.p;
  107. this.playing == true;
  108. }
  109.  
  110. while(true){
  111. let result = null;
  112. await checkConditions();
  113. result = await context.bet(rb(this.cb), this.p);
  114. Targets_UpdateProbabilities(result);
  115. this.update(result);
  116.  
  117. if (this.playing == false && global_playing != this.p){break;}
  118. }
  119. }
  120. }
  121. };
  122.  
  123. function Targets_UpdateProbabilities(data){
  124. for (let i = 0; i < Targets.length; i++){
  125. Targets[i].n += (data.multiplier < Targets[i].p ? 1 : -Targets[i].n);
  126. Targets[i].prob = Math.round(geoProb(Targets[i].p, Targets[i].n) * prc) / prc;
  127. }
  128. }
  129.  
  130. function geoProb(x, n) {
  131. let p = (x > 1 ? 1 / x : 0.01);
  132. return (1 - (Math.log(1 - ((1 - p) ** n)) / Math.log(p)));
  133. }
  134.  
  135. function Targets_ShowLog(){
  136. for (let i = 0; i < Targets.length; i++){if (debug) engine.log(`${Targets[i].p}x | max streak seen ${Targets[i].mss} | ${Targets[i].prob}/${req}`)}
  137. }
  138.  
  139. function Targets_ResetBets() {
  140. for (let i = 0; i < Targets.length; i++) {Targets[ i ].cb = Targets[ i ].b}
  141. }
  142. async function Targets_Update(context) {
  143. for (let i = 0; i < Targets.length; i++) {
  144. await Targets[ i ].play(context);
  145. };
  146. }
  147.  
  148. const main = async () => {
  149. if (rules_confident_recover > 1) rules_confident_recover = 1;
  150. for (let i = config.frompayout.value; i < config.topayout.value + 1; i = i + 5) { new Target(i) }; /* Create targets from config */
  151. //var SA = new SeedAlert();
  152. for (; ;) {
  153. game++;
  154. let result = null;
  155. let output = ``;
  156.  
  157. result = await this.bet(100, 1.01);
  158. //SA.start(result);
  159.  
  160. if (result.multiplier == 1.0){PROFIT -= 100;} else {PROFIT += 1;} /* Update Profit for 1.0x instant crashes */
  161.  
  162. Targets_UpdateProbabilities(result);
  163.  
  164. await Targets_Update(this);
  165.  
  166. Targets_ShowLog();
  167.  
  168. session_profit = 0;
  169. if (profit_total > 0) profit_total = 0;
  170.  
  171.  
  172. if (recovery_attempt < 1) {
  173. req = Number(eval(config.betProb.value));
  174. } else {
  175. req = Number(rules_confident_recover);
  176. }
  177.  
  178. output += `${game}# | Profit: ${Math.round(PROFIT / 100)} bits`;
  179. if (profit_total < 0) output += ` | To recover ${Math.round(profit_total / 100)} bits`;
  180.  
  181. //this.clearLog();
  182. //printStatus();
  183.  
  184. await this.log(output);
  185. await sleep(config.intervalling.value);
  186. }
  187. }
  188.  
  189.  
  190. class SeedAlert {
  191. constructor() {
  192. this.rolls;
  193. this.target = 10;
  194. this.seek = 1000;
  195.  
  196. this.rolls = 0;
  197. this.total_rolls = 0;
  198. this.seekFound = 0;
  199. this.seekFoundMax = 0;
  200.  
  201. this.total_wins = 0;
  202. this.bad_win_rate = 7.5;
  203. this.reset_rolls_after = 2500;
  204. console.log(`Seed Alert class created.`);
  205. };
  206.  
  207. async start(multiplier){
  208. this.rolls++;
  209. this.total_rolls++;
  210.  
  211. if (multiplier >= this.seek){
  212. this.seekFound++;
  213. if (this.seekFound >= this.seekFoundMax){
  214. this.seekFoundMax = this.seekFound;
  215. }
  216. }
  217. if (multiplier > this.target){
  218. this.total_wins++;
  219. }
  220. engine.log(`Win rate ${this.target}x: ${this.getWinRate(this.total_wins, this.total_rolls)}%`)
  221. engine.log(`Current game seed diffculty is ${getSeedState()}`)
  222.  
  223. if (this.total_rolls >= this.reset_rolls_after){
  224. this.total_rolls = 0;
  225. }
  226. };
  227.  
  228. getSeedState(){
  229. if (this.getWinRate(this.total_wins, this.total_rolls) <= this.bad_win_rate){
  230. return "VERY HARD";
  231. } else {
  232. return "PLAYABLE";
  233. }
  234. };
  235.  
  236. getWinRate(wins, games){
  237. return Math.round((wins / games) * 100).toFixed(2);
  238. };
  239. };
  240.  
  241. async function checkConditions() {
  242. printStatus();
  243. if (engine.balance / 100 <= lock_balance && config.whenToStop.value != 0) {
  244. gong(1);
  245. await breakPoint();
  246. };
  247. if (engine.balance / 100 > lock_normal + lock_balance_profit && config.whenToStopProfit.value != 0) {
  248. gong(0);
  249. await breakPoint();
  250. };
  251. };
  252.  
  253. async function sleep(ms) { if (ms != 0) return new Promise(resolve => setTimeout(resolve, ms)) };
  254.  
  255. async function gong(song_number) {
  256. let song_name = ``
  257. if (song_number == 0) {
  258. song_name = "https://freesound.org/data/previews/411/411639_5121236-lq.mp3"
  259. } else {
  260. song_name = "https://freesound.org/data/previews/274/274178_5123851-lq.mp3"
  261. }
  262. const audio = new Audio(song_name);
  263. await audio.play();
  264. return new Promise(resolve => audio.onended = resolve);
  265. };
  266.  
  267. async function printStatus() {
  268. if (config.whenToStop.value > 0 && config.whenToStopProfit.value > 0) engine.log(`Till reset | ${Math.round(Math.round(lock_balance - engine.balance / 100))}- / +${Math.round(Math.round(lock_balance_profit + lock_normal) - engine.balance / 100)} |`);
  269. if (recovery_attempt > 0) { engine.log(`Recovery attempt: ${recovery_attempt}`) }
  270. }
  271.  
  272. async function breakPoint() {
  273. if (config.stopScript.value) {
  274. await engine.stop();
  275. } else {
  276. Targets_ResetBets();
  277.  
  278. lock_balance = (engine.balance / 100) * (config.whenToStop.value / 100);
  279. lock_balance_profit = (engine.balance / 100) * (config.whenToStopProfit.value / 100);
  280. lock_normal = (engine.balance / 100);
  281. engine.log(`Script recalculated lock profit stop and loss stop; new values are:`);
  282. engine.log(`Stop loss ${Math.round(lock_balance)} bits | Stop profit ${Math.round(lock_normal + lock_balance_profit)} bits`);
  283. }
  284. }
  285.  
  286. /* Prevent script from lost connection to server */
  287. while (true) {
  288. try {
  289. await main();
  290. } catch (error) {
  291. if (error.message === "connection closed") {
  292. await this.log("Connection closed. Restarting script");
  293. continue;
  294. } else if (error.message === "insufficient balance") {
  295. await this.log("Not enough balance to bet");
  296. await this.stop();
  297. } else {
  298. throw error;
  299. }
  300. }
  301. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement