Skip to content

Instantly share code, notes, and snippets.

@ruslankonev
Forked from rbreve/satoshi.htm
Created December 6, 2017 16:01
Show Gist options
  • Save ruslankonev/ec7ca0d48683d62bc62c411f0404d1fc to your computer and use it in GitHub Desktop.
Save ruslankonev/ec7ca0d48683d62bc62c411f0404d1fc to your computer and use it in GitHub Desktop.
Satoshi Dice Simulator Javascript
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<style type="text/css" media="screen">
body{font-family:helvetica;}
.abutton{width:350px;height:200px;}
.green{color:green;}
.red{color:red;}
</style>
<title>Satoshi Dice Javascript Simulator</title>
<script type="text/javascript" charset="utf-8">
function rollDice(){
var gameType=document.forms["myForm"]["gameType"].value;
var bets = document.forms["myForm"]["bets"].value;
var totalBTC = document.forms["myForm"]["totalAmount"].value;
var betAmount = document.forms["myForm"]["betAmount"].value;
var percentages=[
{percentage:0.915527,mult:1.07},
{percentage:0.732422,mult:1.34} ,
{percentage:0.500000,mult:1.96} ,
{percentage:0.488281,mult:2.0} ,
{percentage:0.366211,mult:2.67},
{percentage:0.244141,mult:4},
{percentage:0.183105,mult:5.34},
{percentage:0.12207,mult:8},
{percentage:0.030518,mult:31.99},
{percentage:0.015259,mult:63.96},
{percentage:0.000015, mult:64000},
];
var values = percentages[gameType];
var div = document.getElementById('result');
var probability=values.percentage;
var multi=values.mult;
var resultHTML="";
for(i=0;i<bets;i++){
var random=Math.random();
var winOrLose="";
totalBTC-=betAmount;
if ( random <= probability){
totalBTC+=betAmount*multi;
winOrLose = "<td>Won</td><td class=green> +"+betAmount*multi+"</td>";
}else{
winOrLose = "<td>Lost</td><td class=red> -"+betAmount+"</td>";
}
resultHTML+=" <tr><td>Round "+(i+1)+"</td> "+winOrLose+" </tr>";
}
div.innerHTML="<table>"+resultHTML + "</table><H2> FINAL BALANCE: BTC " + totalBTC + "</H2>";
return false;
}
</script>
</head>
<body id="satoshi" onload="">
<form action="#" accept-charset="utf-8" id="form" onsubmit="return rollDice()" name="myForm">
<table border="0" cellspacing="5" cellpadding="5">
<tr><th colspan=2><h2>Satoshi Dice Javascript Simulator</h2></th></tr>
<tr>
<td>Game Type</td>
<td> <select name="gameType" id="some_name" onchange="" size="1">
<option value="0">91.5527%</option>
<option value="1">73.2422%</option>
<option value="2">50%</option>
<option value="3">48.8281%</option>
<option value="4">36.6211%</option>
<option value="5">24.4141%</option>
<option value="6">18.3105%</option>
<option value="7">12.207%</option>
<option value="8">3.0518%</option>
<option value="9">1.5259%</option>
<option value="10">0.0015%</option>
</select>
</td>
</tr>
<tr>
<td>Initial BTC Amount:</td>
<td><input type="text" name="totalAmount" value="10" id="totalAmount"></td>
</tr>
<tr>
<td>Bet Amount:</td>
<td><input type="text" name="betAmount" value="1" id="betAmount"></td>
</tr>
<tr>
<td>Number of Bets:</td>
<td> <input type="text" name="bets" value="20" id="bets">
</td>
</tr>
</table>
<input type="submit" value="Roll" class="abutton"></p>
</form>
<div id="result">
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment