Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bustabit;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.InputStreamReader;
- import java.lang.reflect.Type;
- import java.util.List;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- public class HouseEdge {
- public static double prob(double c) {
- return (99D/101D) * (1D/(c-1D/100D));
- }
- public static boolean game(double cashout) {
- final double r = Math.random();
- final double p = prob(cashout);
- return r <= p;
- }
- public static double bet(double cashout, double amount) {
- return amount*.01 + (game(cashout) ? amount * cashout : 0);
- }
- public static double cashout(List<HistogramBin> histogram) {
- double r = Math.random();
- for(int i = 0; i<histogram.size(); i++) {
- if(r < histogram.get(i).getCumulative()) {
- return histogram.get(i).getCashout();
- }
- }
- return 1.0;
- }
- // args[0] is path to CashoutHistogram.json
- public static void main(String[] args) {
- FileInputStream fstream;
- try {
- fstream = new FileInputStream(args[0]);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return;
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- Type listType = new TypeToken<List<HistogramBin>>() {}.getType();
- List<HistogramBin> histogram = new Gson().fromJson(br, listType);
- double bets = 0;
- double paid = 0;
- for(int i=0; i<1000000000; i++) {
- if(i%10000000 == 0) System.out.println(i);
- bets += 1000;
- double cashout = cashout(histogram);
- paid += bet(cashout, 1000D);
- }
- System.out.println("House Edge: " + (1 - paid/bets));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment