Last active
October 23, 2024 16:35
-
-
Save Skarlett/7d6a79fd1d9c1ea3c2656eb1bb418857 to your computer and use it in GitHub Desktop.
Quick simulation of the HiLo Bitcoin multiplier game found on Freebitco.in, PS. It'd be really cool if you referred under me. https://freebitco.in/?r=836205
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
from os import name | |
IS_WIN = name.startswith('nt') | |
NO_COLOR = False | |
class HiLo_gamble: | |
def __init__(self, bet=float(), chance=47.5): | |
self.update(bet, chance) | |
def calc_payout(self, chance_of_win): | |
return 95 / float(chance_of_win) | |
def calc_range(self, chance_of_win): | |
low = chance_of_win * 100 | |
high = 10000-low | |
return high, low | |
def update(self, bet, chance): | |
basebet = 0.000000001 | |
if bet < basebet: | |
bet = basebet | |
payout = self.calc_payout(chance) | |
assert chance > 0.01 and chance < 94.07 | |
assert payout > 1. and payout < 4751 | |
self.bet = bet | |
self.chance = chance | |
self.payout = payout | |
self.reward = (self.bet * self.payout) - self.bet | |
def roll(self): | |
return random.randint(1, 10000) | |
def gamble(self, method): | |
result = self.roll() | |
high, low = self.calc_range(self.chance) | |
if method == 'h': | |
if high >= result: | |
return (self.bet*self.payout)+self.bet | |
else: | |
return self.bet*-1 | |
elif method == 'l': | |
if low <= result: | |
return (self.bet*self.payout)+self.bet | |
else: | |
return self.bet*-1 | |
else: | |
raise AssertionError('May only take \'h\' or \'l\' as method argument') | |
class Session: | |
game = HiLo_gamble() | |
def __init__(self, bal, bet=float(), chance=47.5): | |
self.balance = bal # 0.000000000 | |
self.game.update(bet, chance) | |
self.gains = 0 | |
self.spins = 0 | |
self.update = self.game.update | |
def gamble(self, method='h'): | |
award = self.game.gamble(method) | |
self.gains += award | |
self.balance += award | |
self.spins += 1 | |
return award | |
class Interact(Session): | |
color_map = { | |
'red': 31, | |
'light_green': 32, | |
'yellow': 33, | |
'blue': 34, | |
'purple': 35, | |
'dark_blue': 36, | |
'gray': 37, | |
'white': 30, | |
} | |
def __init__(self, bal): | |
Session.__init__(self, bal) | |
self.opt = 'h' | |
self.spin_cnt = 1 | |
def color(self, string, color, bold): | |
attr = [] | |
if type(color) == str: | |
color = self.color_map[color] | |
assert color in [v for k, v in self.color_map.items()] | |
attr.append(str(color)) | |
if bold: | |
attr.append('1') | |
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string) | |
def get_vars(self): | |
temp_opt = raw_input('Bet on [%s]: ' % self.opt) | |
if temp_opt and temp_opt[0] in ['h', 'l']: | |
self.opt = temp_opt[0] | |
temp_bet = raw_input('Bet [%.9f]: ' % self.game.bet) | |
if temp_bet: | |
self.game.bet = float(temp_bet) | |
temp_chane = raw_input('Chance to win [%.2f]: ' % self.game.chance) | |
if temp_chane: | |
self.game.chance = float(temp_chane) | |
temp_spins = raw_input('Amount of spins [%d]: ' % self.spin_cnt) | |
if temp_spins: | |
try: | |
assert temp_spins.isdigit() and int(temp_spins) > 0 | |
self.spin_cnt = int(temp_spins) | |
except AssertionError: | |
pass | |
def cprint(self, msg, color, bold): | |
if not IS_WIN and not NO_COLOR: | |
msg = self.color(msg, color, bold) | |
print(msg) | |
def spin(self): | |
for _ in xrange(self.spin_cnt): | |
if self.spin_cnt > 1: | |
time.sleep(0.1) | |
amount = self.gamble(self.opt) | |
if amount >= 0: | |
self.cprint('+%.9f' % amount, 32, True) | |
else: | |
self.cprint('%.9f' % amount, 31, True) | |
def main_loop(self): | |
while 1: | |
try: | |
print('Session gains: %.9f' % self.gains) | |
self.get_vars() | |
self.spin() | |
except KeyboardInterrupt: | |
print('\n\nSession gains: %.9f' % self.gains) | |
break | |
if __name__ == '__main__': | |
program = Interact(0.) | |
program.main_loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment