lundi 27 juin 2016

Martingale method


I'm trying to simulate the martingale method, but it doesn't seem to do anything.

Here's my code:

import random

w = 1  # wager
# w1 = w  # an amount for reference when the wager has to go back to its original value
w = int(w)

br = 10000000  # Bankroll
# br1 = br  # Reference amount like w1
br = int(br)

losses = 0  # Keeps track of losses in loop
losses = int(losses)

wins = 0  # Keeps track of wins in loop
wins = int(wins)

b = 0  # Amount of bankruptcies that occur during the loop
b = int(b)

i = 1

boole = 0

x = 1
while x <= 1000:

    while i <= 100000:
        y = random.randint(0, 1)  # Picking between 1 or 0 for a %50 chance.
        if y == 1:  # If you win, you add the wager to the bankroll, add one to the wins, and set the wager to its beginning value
            br += w
            wins += 1
            w = 1

        else:
            br -= w  # If you lose, you subtract the wager from the bankroll, double the wager, and add a loss.
            w *= 2
            losses += 1

        if br <= 0:  # If the bankroll reaches 0 or below, it restarts adds to the bankruptcies variable
            b += 1
            break

        if boole == 1:
            w *= 2
            boole = 0

    i += 1  # Continues the loop
x += 1

print("Wins:", wins, "nLosses:", losses, "nBankruptcies:", b, "nNet Gain:", )  # Stating info

For some reason it just doesn't work. I want it to output things, but it doesn't.

Edit: I'd appreciate it if you guys didn't stray too far from my original idea in to things I do not understand.

I basically want it to output how many times I won the 50/50 and how many times I lost. Also how many times I went bankrupt out of the 1000 in the x loop. As well as my net gain out of all the things.


Aucun commentaire:

Enregistrer un commentaire