Created
April 28, 2013 04:19
-
-
Save dghodgson/5475854 to your computer and use it in GitHub Desktop.
Shell script for simulating a martingale style betting system for Satoshi Circle. Accepts a file with random sequences of numbers 0 through 16 as input (to determine which value the wheel landed on).
This file contains 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
#!/bin/bash | |
rand=$1 | |
line_start=$2 | |
float_scale=9 | |
start_bal=0.25 | |
start_bet=0.000004234 | |
max_bet=0.25 | |
bet_mult=2.5 | |
FloatEval() | |
{ | |
local stat=0 | |
local result=0.0 | |
if [[ $# -gt 0 ]]; then | |
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null) | |
stat=$? | |
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi | |
fi | |
echo $result | |
return $stat | |
} | |
FloatCond() | |
{ | |
local cond=0 | |
if [[ $# -gt 0 ]]; then | |
cond=$(echo "$*" | bc -q 2>/dev/null) | |
if [[ -z "$cond" ]]; then cond=0; fi | |
if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi | |
fi | |
local stat=$((cond == 0)) | |
return $stat | |
} | |
GetMultiplier() | |
{ | |
local input | |
local output | |
read input | |
# x0.00 | |
if (( $input < 3 )) | |
then | |
output=0.00 | |
# x0.25 | |
elif (( 3 <= $input )) && (( $input < 7 )) | |
then | |
output=0.25 | |
# x1.20 | |
elif (( $input == 7 )) | |
then | |
output=1.20 | |
# x1.25 | |
elif (( $input == 8 )) | |
then | |
output=1.25 | |
# x1.50 | |
elif (( 9 <= $input )) && (( $input < 14 )) | |
then | |
output=1.50 | |
# x2.00 | |
elif (( 14 <= $input )) && (( $input < 16 )) | |
then | |
output=2.00 | |
# x3.00 | |
elif (( $input == 16 )) | |
then | |
output=3.00 | |
fi | |
echo $output | |
} | |
GetNextMove() | |
{ | |
local input | |
local output | |
read input | |
# x0.00 - x0.25 | |
if (( $input < 7 )) | |
then | |
output="double" | |
# x1.20 - x1.50 | |
elif (( 7 <= $input )) && (( $input < 14 )) | |
then | |
output="hold" | |
# x2.00 - x3.00 | |
elif (( 14 <= $input )) | |
then | |
output="minimum" | |
fi | |
echo $output | |
} | |
current_bal=$start_bal | |
current_bet=$start_bet | |
line=$line_start | |
total_gain=0 | |
itt=0 | |
echo "Starting Balance: $current_bal" | |
echo "Half of Start Bal: $(FloatEval "$start_bal / 2")" | |
echo "1.5x Start Bal: $(FloatEval "$start_bal * 1.5")" | |
while (( $line < 29991 )) | |
do | |
current_bal=$start_bal | |
current_bet=$start_bet | |
line_start=$line | |
while FloatCond "$current_bal > ($start_bal / 2)" && FloatCond "$current_bal < ($start_bal * 1.5)" | |
do | |
seed=$(sed -n ${line}p $rand) | |
# If we're going to lose, mark the current balance so we can determine | |
#+ when we've made a net gain | |
if [[ "$(echo $seed | GetNextMove)" == "double" ]] && [[ -z "$mark_bal" ]] | |
then | |
mark_bal=$current_bal | |
mark_line=$line | |
fi | |
if FloatCond "$current_bet > $current_bal" | |
then | |
#echo -e "\n\n" | |
echo "Can't fund bet. $current_bet is more than $current_bal." | |
break | |
elif FloatCond "$current_bet > $max_bet" | |
then | |
#echo -e "\n\n" | |
echo "Can't fund bet. $current_bet is more than max allowed bet." | |
break | |
fi | |
current_bal=$(FloatEval "$current_bal - $current_bet") # Place a bet | |
return_mult=$(echo $seed | GetMultiplier) # Get the bet multiplier (X0 up to x3) | |
return_bet=$(FloatEval "$current_bet * $return_mult") # Figure out what our return is on the bet | |
current_bal=$(FloatEval "$current_bal + $return_bet") # Update our current balance | |
if [[ -n "$mark_bal" ]] | |
then | |
# if [[ -n "$mark_line" ]] | |
# then | |
# echo "Bet #${mark_line} - Mark: ${mark_bal}" | |
# unset mark_line | |
# fi | |
# if [[ "$(echo $seed | GetNextMove)" == "double" ]] | |
# then | |
# if [[ -z "$lost_count" ]] | |
# then | |
# lost_count=0 | |
# current_losses=0 | |
# fi | |
# (( lost_count++ )) | |
# echo -en "\r Lost $lost_count time(s)" | |
# current_losses=$(FloatEval "$current_losses + $current_bet") | |
# #sleep 0.05 | |
# elif [[ "$(echo $seed | GetNextMove)" == "hold" ]] | |
# then | |
# if [[ -z "$hold_count" ]] | |
# then | |
# hold_count=0 | |
# fi | |
# (( hold_count++ )) | |
# current_losses=$(FloatEval "$current_losses + $current_bet") | |
# el | |
if FloatCond "$current_bal > $mark_bal" | |
then | |
# echo "" | |
# echo " Held $hold_count time(s)" | |
# echo " Total Losses: $current_losses" | |
# echo " Total Winnings: $return_bet" | |
# echo " Net Gain: $(FloatEval "$current_bal - $mark_bal")" | |
# echo " Current Balance: $current_bal" | |
# #sleep 0.125 | |
unset current_losses | |
unset mark_bal | |
unset mark_line | |
unset lost_count | |
unset hold_count | |
fi | |
fi | |
# Decide what to do next | |
case $(echo $seed | GetNextMove) in | |
double ) | |
current_bet=$(FloatEval "$current_bet * $bet_mult") | |
;; | |
hold ) | |
if [[ -z "$mark_bal" ]] | |
then | |
current_bet=$start_bet | |
else | |
current_bet=$current_bet | |
fi | |
;; | |
minimum ) | |
current_bet=$start_bet | |
;; | |
esac | |
(( line++ )) | |
done | |
if FloatCond "$current_bal < $start_bal" | |
then | |
echo "Last bet: $(FloatEval "$current_bet / $bet_mult")" | |
echo "Ending Balance: $current_bal" | |
echo "You lost $(FloatEval "$start_bal - $current_bal")BTC" | |
echo "Number of Bets: `expr $line - $line_start`" | |
total_gain=$(FloatEval $total_gain - $(FloatEval "$start_bal - $current_bal")) | |
else | |
echo "Last bet: $(FloatEval "$current_bet / $bet_mult")" | |
echo "Ending Balance: $current_bal" | |
echo "You gained $(FloatEval "$current_bal - $start_bal")BTC" | |
echo "Number of Bets: `expr $line - $line_start`" | |
total_gain=$(FloatEval $total_gain + $(FloatEval "$current_bal - $start_bal")) | |
fi | |
echo "" | |
echo "line: $line" | |
echo "" | |
(( itt++ )) | |
done | |
echo "Total gain after $line bets over $itt itterations is:" | |
echo " $total_gain BTC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment