Pages:
Author

Topic: 1st Nxt Slot Machine! - page 3. (Read 5046 times)

hero member
Activity: 695
Merit: 500
November 25, 2013, 05:15:09 PM
#15
Hmmm, send 12 nxt, but did not even get one singel nxt back

Ur bet lost, my script is trying to send 1 NXT but it's connected only to a few nodes and mining nodes don't see it. This is a great possibility to investigate what happens, so I don't restart the client. Eventually u'll get this coin anyway.

OK, cool....I don´t worry about the loss, just wantet to let you know Wink
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 04:58:41 PM
#14
Hmmm, send 12 nxt, but did not even get one singel nxt back

Ur bet lost, my script is trying to send 1 NXT but it's connected only to a few nodes and mining nodes don't see it. This is a great possibility to investigate what happens, so I don't restart the client. Eventually u'll get this coin anyway.
hero member
Activity: 695
Merit: 500
November 25, 2013, 04:51:48 PM
#13
Hmmm, send 12 nxt, but did not even get one singel nxt back
hero member
Activity: 597
Merit: 500
November 25, 2013, 04:17:23 PM
#12
ok, thanks, will update to 0.2.9 and test again.
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 04:09:42 PM
#11
thanks for sharing.

looks like i am to many hours in front of my computer. my previous post was for the nxt main thread, not for your game thread.
have to reduce my browser-tabs.

from your source (i am not a java coder) i can see you are parsing the blockchain file directly?
are there any specs about the internal storage format?

No, I don't parse the file. I use HTTP API and get JSON data back. Then I just parse JSON by myself, without a JSON library.
hero member
Activity: 597
Merit: 500
November 25, 2013, 04:08:02 PM
#10
thanks for sharing.

looks like i am to many hours in front of my computer. my previous post was for the nxt main thread, not for your game thread.
have to reduce my browser-tabs.

from your source (i am not a java coder) i can see you are parsing the blockchain file directly?
are there any specs about the internal storage format?
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 03:46:04 PM
#9
For those who may be interested here is the source code of my Slot Machine:

Code:
// (c) 2013 Come-from-Beyond

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;

public final class Tri {

public static void main(String[] args) {

while (true) {

System.out.println("Time = " + System.currentTimeMillis());

try {

Thread.sleep(120000);

} catch (final Exception e) {

return;

}

try {

final ArrayList bets = new ArrayList<>();
final HashSet payments = new HashSet<>();

String block = "2680262203532249785"; // This is the genesis block id

while (true) {

String blockData = sendRequest("getBlock&block=" + block);

int i = blockData.indexOf("\"transactions\":[");
String transactions = blockData.substring(i + 16, blockData.indexOf("]", i));
while (transactions.length() > 0) {

final String transaction = transactions.substring(1, transactions.indexOf("\"", 1));
final String transactionData = sendRequest("getTransaction&transaction=" + transaction);

// Beginning of the game logic
i = transactionData.indexOf("\"sender\":\"");
final String sender = transactionData.substring(i + 10, transactionData.indexOf("\"", i + 10));
i = transactionData.indexOf("\"recipient\":\"");
final String recipient = transactionData.substring(i + 13, transactionData.indexOf("\"", i + 13));

if (recipient.equals("4427320429393039971")) {

i = transactionData.indexOf("\"amount\":");
final int amount = Integer.parseInt(transactionData.substring(i + 9, transactionData.indexOf(",", i + 9)));

if (amount >= 10 && amount <= 1000) {

bets.add(new Bet(block, transaction, amount, sender));

}

} else if (sender.equals("3994117300242888518")) {

i = transactionData.indexOf("\"referencedTransaction\":\"");
final String referencedTransaction = transactionData.substring(i + 25, transactionData.indexOf("\"", i + 25));
payments.add(referencedTransaction);

}
// End of the game logic

if (transaction.length() + 3 > transactions.length()) {

break;

}
transactions = transactions.substring(transaction.length() + 3);

}

i = blockData.indexOf("\"nextBlock\":\"");
if (i < 0) {

break;

}
block = blockData.substring(i + 13, blockData.indexOf("\"", i + 13));

}

// Beginning of the game logic
for (final Bet bet : bets) {

if (!payments.contains(bet.transaction)) {

final String request = "sendMoney&secretPhrase=REMOVED&recipient=" + bet.sender + "&amount=" + getAmount(bet) + "&fee=1&deadline=1&referencedTransaction=" + bet.transaction;
System.out.println(request);
System.out.println(sendRequest(request));

}

}
// End of the game logic

} catch (final Exception e) {

System.out.println(e.toString());

}

}

}

public static int getAmount(final Bet bet) {

final String digits = bet.block.substring(bet.block.length() - 3);
final int digit0 = Integer.parseInt("" + digits.charAt(0));
final int digit1 = Integer.parseInt("" + digits.charAt(1));
final int digit2 = Integer.parseInt("" + digits.charAt(2));

if (digit0 == digit1 && digit0 == digit2) {

return bet.amount * 10;

}

if (digit0 == digit1 || digit0 == digit2 || digit1 == digit2) {

return bet.amount * 3;

}

return 1;

}

public static String sendRequest(final String request) throws Exception {

final HttpURLConnection connection = (HttpURLConnection)(new URL("http://localhost:7876/?request=" + request)).openConnection();
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final String response = reader.readLine();
reader.close();
connection.disconnect();

return response;

}

public static final class Bet {

final String block;
final String transaction;
final int amount;
final String sender;

public Bet(final String block, final String transaction, final int amount, final String sender) {

this.block = block;
this.transaction = transaction;
this.amount = amount;
this.sender = sender;

}

}

}

It uses only Nxt blockchain, no need to store anything locally.

Pay attention that it uses "referencedTransaction". If a betting transaction cancelled due to blockchain reorganization, then the transaction that pays winning will be cancelled as well.
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 03:34:35 PM
#8
same in context to freeze. don't know how often i restarted a freezed client the last 24h.

test it yourself, traverse (getBlock) from genesis block (2680262203532249785) up to the current one on your local machine and see what happen.
just one connection with 1.000 repetitive request and your node is gone. this workload is normally nothing and every node should handle this easily.

My gambling service doesn't store any data. Every 2 minutes it scans the whole blockchain and sends winnings. It even sets deadline to 1 minute, so usualy it take several times to send a transaction, coz it expires before confirmation. Make sure u use the recent version which is 0.2.9 (https://dl.dropboxusercontent.com/u/67242472/Nxt.zip).
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 03:00:08 PM
#7
but i am facing the same problem here, you can't put workload on this, as soon you do, the client freeze.

What do u mean "the same"? I see nothing about API problems in this thread. Check that u work with 0.2.7 version.
eid
hero member
Activity: 616
Merit: 500
November 25, 2013, 01:46:37 PM
#6




House can run out of money......


ROFL, good one.  Cheesy
legendary
Activity: 1498
Merit: 1000
November 25, 2013, 01:35:42 PM
#5
Nice to have something to gamble with Nxt!
 I wil try it  Grin
sr. member
Activity: 400
Merit: 250
November 25, 2013, 01:25:29 PM
#4
Thank you Smiley still willing to test my luck
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 01:21:09 PM
#3
Tried it oute

Sent about 12 transactions ..no luck :/

As the 1st player u get all ur coins back. I'll send them in a min.
sr. member
Activity: 400
Merit: 250
November 25, 2013, 01:20:16 PM
#2
Tried it oute

Sent about 12 transactions ..no luck :/
legendary
Activity: 2142
Merit: 1010
Newbie
November 25, 2013, 01:01:20 PM
#1
1st Nxt Slot Machine

How it works:

1. Send from 10 to 1000 NXT to [DELETED]
2. Wait for 1 confirmation
3. Look at the last 3 digits of the block id that confirmed the bet

4. If 2 of these digits are the same then you get 3x amount back. If all 3 digits are the same then you get 10x! If you lose you'll get 1 NXT.

Winnings are paid from [DELETED] every 2 minutes.

House can run out of money, so before making a bet check that http://88.198.210.245:7876/?request=getBalance&account=3994117300242888518 shows at least "1000000" in "unconfirmedBalance"!

DISABLED
Pages:
Jump to: