MartinBot

HouseEdge.java

Nov 13th, 2016
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package com.bustabit;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.InputStreamReader;
  7. import java.lang.reflect.Type;
  8. import java.util.List;
  9.  
  10. import com.google.gson.Gson;
  11. import com.google.gson.reflect.TypeToken;
  12.  
  13. public class HouseEdge {
  14.  
  15. public static double prob(double c) {
  16. return (99D/101D) * (1D/(c-1D/100D));
  17. }
  18.  
  19. public static boolean game(double cashout) {
  20. final double r = Math.random();
  21. final double p = prob(cashout);
  22. return r <= p;
  23. }
  24.  
  25. public static double bet(double cashout, double amount) {
  26. return amount*.01 + (game(cashout) ? amount * cashout : 0);
  27. }
  28.  
  29. public static double cashout(List<HistogramBin> histogram) {
  30. double r = Math.random();
  31. for(int i = 0; i<histogram.size(); i++) {
  32. if(r < histogram.get(i).getCumulative()) {
  33. return histogram.get(i).getCashout();
  34. }
  35. }
  36.  
  37. return 1.0;
  38. }
  39.  
  40. // args[0] is path to CashoutHistogram.json
  41. public static void main(String[] args) {
  42. FileInputStream fstream;
  43.  
  44. try {
  45. fstream = new FileInputStream(args[0]);
  46. } catch (FileNotFoundException e) {
  47. e.printStackTrace();
  48. return;
  49. }
  50.  
  51. BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  52.  
  53. Type listType = new TypeToken<List<HistogramBin>>() {}.getType();
  54.  
  55. List<HistogramBin> histogram = new Gson().fromJson(br, listType);
  56.  
  57. double bets = 0;
  58. double paid = 0;
  59.  
  60. for(int i=0; i<1000000000; i++) {
  61. if(i%10000000 == 0) System.out.println(i);
  62. bets += 1000;
  63. double cashout = cashout(histogram);
  64. paid += bet(cashout, 1000D);
  65. }
  66.  
  67. System.out.println("House Edge: " + (1 - paid/bets));
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment