Martingale Bahis Simülatörü
Script, Martingale bahis stratejisini, bir kayıp oluşana kadar sabit bir miktarla bahis yapma stratejisini simüle eder; bu noktada, bahisçi kaybı telafi etmek için bahsi ikiye katlar. Bu, bir kazanç oluşana kadar devam eder. Kazandıktan sonra, bahis orijinal bahis değerine sıfırlanır. Oranları Blackjack'i taklit edecek şekilde belirledim (% 49 kazanma şansı). Basit olması için, bir turda kazanılan veya kaybedilen miktar, bahse eşittir. Simülasyon, belirtilen tur sayısı geçtiğinde, bir sonraki bahsin boyutu mevcut mevcut fondan daha büyük olduğunda, mevcut fonlar 0'a ulaştığında veya hedef karı karşılandığında sona erer.
Python ve genel olarak kodlama konusunda yepyeni biriyim, bu nedenle herhangi bir geri bildirim takdir edilecektir.
import random
class MartGame:
def __init__(self, bet=25, starting_funds=5000, goal_profit=1000, round_n=0, rng_v=0.00,
wins=0, losses=0, loss_run=0, win_run=0):
self.bet = bet
self.starting_funds = starting_funds
self.goal_profit = goal_profit
self.round_n = round_n
self.rng_v = rng_v
self.wins = wins
self.losses = losses
self.los_run = loss_run
self.win_run = win_run
self.original_bet = bet
self.current_funds = self.starting_funds
def rng(self):
"""Generates random number"""
self.rng_v = random.random()
def winloss_generator(self):
"""Generates win/loss condition"""
if self.rng_v <= .49:
return 'win'
else:
return 'loss'
def increase_winloss(self):
"""Increases wins or losses variable based on winloss_generator output"""
if self.winloss_generator() == 'win':
self.wins += 1
return 'win'
elif self.winloss_generator() == 'loss':
self.losses += 1
return 'loss'
else:
print('error')
def increase_round(self):
"""Increases round number by 1"""
self.round_n += 1
def change_current_funds(self):
"""Increases or decreases current_funds based on winloss_generator output"""
if self.winloss_generator() == 'win':
self.current_funds += self.bet
elif self.winloss_generator() == 'loss':
self.current_funds -= self.bet
else:
print('error')
def change_bet(self):
"""If outcome is a win, bet is reset to original value. If outcome is a loss bet is doubled"""
if self.winloss_generator() == 'win':
self.bet = self.original_bet
elif self.winloss_generator() == 'loss':
self.bet = self.bet * 2
def running_profit(self):
"""Returns running profit"""
return self.current_funds - self.starting_funds
def current_funds(self):
"""Returns running total of funds"""
return self.current_funds
def print_current_record(self):
"""Prints current win/loss record to screen"""
print('Current Record: ', self.wins, 'wins, ', self.losses, 'losses')
def print_winloss(self):
"""Prints win/loss condition to screen"""
print(self.winloss_generator())
def print_profit(self):
"""Prints running profit to screen"""
print(self.running_profit(), 'running_profit'.upper())
def print_running_total(self):
"""Prints running total to the screen"""
print(self.current_funds, 'current funds'.upper())
def print_round(self):
"""Prints current round"""
print('Round:', self.round_n)
def print_current_bet(self):
"""Prints current bet"""
print('Bet:', self.bet)
def run(self, rounds, each=False):
"""Runs simulation for specified number of rounds. 'each' argument indicates
whether each round should be displayed. False will only display the final results"""
while self.running_profit() < self.goal_profit and \
self.round_n < rounds and self.current_funds > 0 \
and self.current_funds > self.bet:
self.increase_round()
self.rng()
self.winloss_generator()
self.increase_winloss()
self.change_current_funds()
if each is True:
self.print_round()
self.print_current_bet()
self.print_winloss()
self.print_running_total()
self.print_profit()
self.print_current_record()
print()
self.change_bet()
print()
self.end_script()
def end_script(self):
"""Prints final outcome of the simulation and summary of the results"""
if self.running_profit() == self.goal_profit:
print('YOU WIN!')
else:
print('YOU LOSE')
print("Total Rounds:", self.round_n)
print('Win/Loss Record: ', self.wins, 'Wins', self.losses, 'Losses')
print('Ending Funds:', self.current_funds)
print('Goal Profit:', self.goal_profit)
print("Ending Profit:", self.running_profit())
inst = MartGame(25, 5000, 1000)
inst.run(1000, True)
```
Yanıtlar
Aynı sınıftan birden fazla nesne oluşturmak veya çalışırken nesneleri oluşturmak ve yok etmek istediğinizde sınıflar kullanışlıdır. Bu durumda, sadece bir nesneniz var.
Bu, bir sınıfa ihtiyaç duyduğunuz türden bir program değildir. Bir sınıfı kullanmadıysanız, aynı programa sahip olabilir, ancak self.kodunuzdaki her şeyi kaldırabilirsiniz , bu da onu daha kısa ve kolay okuma ve yazma yapar.
Değişkenler komut dosyası içinde yalnızca genel veya main()varsa işleviniz içinde yerel olacağı için, bunların tümüne de gerek yoktur (bir sınıf kullanmadığınızda) .
self.bet = bet
self.starting_funds = starting_funds
self.goal_profit = goal_profit
self.round_n = round_n
self.rng_v = rng_v
self.wins = wins
self.losses = losses
self.los_run = loss_run
self.win_run = win_run
self.original_bet = bet
self.current_funds = self.starting_funds
Aşağıdaki işlev, sınıf kullansanız da kullanmasanız da anlamsızdır. Kodda yalnızca bir yerde kullanılır, bu nedenle geliştiricinin değişkeni bir işlev aracılığıyla değil, doğrudan o tek yerde artırması için kod satırlarını ve beyin gücünü kaydeder.
def increase_round(self):
"""Increases round number by 1"""
self.round_n += 1
Aşağıdaki işlev daha da yararsızdır. Kullanıldığı yerde doğrudan (doğru) değişkene atıfta bulunduğunuz için çağrılmaz bile. Ayrıca değişkenle aynı adı taşır current_fundsve bu da sorunlara yol açabilir.
def current_funds(self):
"""Returns running total of funds"""
return self.current_funds
Aşağıdakiler tuhaf görünüyor. Neden yazdırmıyorsun 'RUNNING_PROFIT'?
'running_profit'.upper()