Tuesday, March 29, 2011

Roulette

//roulette gamble
result = 0

netGain = 0
POT = 50000
BET_MULTIPLY = 2.5

YEARS = 5
DAYS = 364
ROUNDS = 500

YEARS.times { it ->

DAYS.times {

money = POT
bet = 1

ROUNDS.times {
    int result = Math.round(Math.random() + 1)
    if (result == 1) { //win
        money += bet
        bet = 1
    } else if (result == 2) { //lose
        money -= bet
        bet = ((money >= bet * BET_MULTIPLY) ? bet * BET_MULTIPLY : 0)
    }
}

gain = Math.round(money) - POT
netGain += gain

}

println "\n yr#${it+1} NET TOTAL:" + netGain
}

http://groovyconsole.appspot.com/script/449006

No comments:

Post a Comment