It's a Java application. Requires
http://code.google.com/p/json-simple/ to build and parse JSON.
// (c) 2012 Come-from-Beyond
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public final class SDMB
{
public static void main(String[] args)
{
try
{
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication ("username", "password".toCharArray());
}
});
while (true)
{
double bet=((double)(balance(1)/135))/100000000;
if (bet<0.01)
{
Thread.sleep(1000);
continue;
}
for (int i=0; i<7; i++)
{
final long balance1=balance(0);
final JSONObject request=new JSONObject();
request.put("method", "sendtoaddress");
final JSONArray params;
(params=new JSONArray()).add("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp");
params.add(bet);
request.put("params", params);
sendRequest(request);
final long balance2=balance(0);
long balance3;
do
{
Thread.sleep(1000);
} while ((balance3=balance(0))<=balance2);
if (balance3>=balance1) break;
bet=bet+bet;
}
}
}
catch (final Exception e)
{
System.out.println(e.toString());
}
}
public static JSONObject sendRequest(final JSONObject request) throws Exception
{
final HttpURLConnection connection;
(connection=(HttpURLConnection)(new URL("http://localhost:9876")).openConnection()).setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
final OutputStream outputStream;
(outputStream=connection.getOutputStream()).write(request.toJSONString().getBytes("UTF-8"));
outputStream.close();
final InputStream inputStream=connection.getInputStream();
final byte[] response=new byte[65536];
int ptr=0;
int numberOfBytes;
do
{
if ((numberOfBytes=inputStream.read(response, ptr, 65536-ptr))>=0) ptr+=numberOfBytes;
} while (numberOfBytes>=0);
inputStream.close();
connection.disconnect();
return (JSONObject)JSONValue.parse(new String(response, 0, ptr, "UTF-8"));
}
public static long balance(final int numberOfConfirmations) throws Exception
{
final JSONObject request=new JSONObject();
request.put("method", "listaccounts");
final JSONArray params;
(params=new JSONArray()).add(numberOfConfirmations);
request.put("params", params);
return (long)(((Double)((JSONObject)sendRequest(request).get("result")).get("")).doubleValue()*100000000);
}
}
It starts with 1/128 of current
confirmed balance as an initial bet and then double amount if lose. I divide by 135, not 128, to have some BTC for tx fees:
double bet=((double)(balance(1)/135))/100000000;
if (bet<0.01)
...is used to avoid too low bets.
I tested it on 2000 bets using "lessthen 32000". Went from 0 BTC to 14 BTC and back to 0 BTC. At the beginning I used my own bitcoins which were removed from the capital when I got 10 BTC from SatoshiDice. After my bitcoin-qt.exe had reached 1500 thx it started to lag much. After 2000 thx I became bored and made a couple of big bets manually until I lost all won money. Nothing surprising, but at least miners earned 1 BTC as fees.
NB: In the long run SatoshiDice wins so don't miss a right moment to stop.