[
"autonomous agent",
{
"init": "{
// =============== OBYSTACK AA =================
// =============================================
// OBYTE STACK GAME from Whistling Frogs
// =============================================
// First published by Crypto Girl on 21 Sep 2019
// =============================================
// Version: 1.0 - 9 Oct 2019
// =============================================
// For best game experience should be used with the OBYSTACK GAME BOT v1.0
// Pairing code:
//
[email protected]/bb-test#StackGame
// =============================================
// The object of the game is to win the Stack.
// Users make bids. Min bid is 1,000,000 bytes.
// 1st bid initiates the Stack.
// Each subsequent bid starts the timer.
// The game ends when the timer rans out.
// The Stack (less commission) is shared equally
// between the last bidder and the 1st bidder.
// The new game is initiated by the next bid.
// A 1% commission (10,000 bytes) is charged on each bid.
// ============================================
// Visit https://whistling-frogs.herokuapp.com/obyStack
// for a full description of the game.
// ============================================
//
// setting game parameters
$bot_address = 'QUONK7CUHPTGLNTZ6JE57SDVSFVDBCMM';
$commission_payout_threshold = 50000;
$commission = 10000;
$seed_amnt = 10000;
$min_bid_amnt = 1000000;
$fees = 1000;
// setting game variables
$bid_amnt = trigger.output[[asset=base]];
$game_finished = (trigger.initial_address == $bot_address) otherwise false;
if ( ($game_finished == false) AND ($bid_amnt < $min_bid_amnt) ) bounce('Your bid is too small.');
$game_status = var['game_status'] otherwise 'not started';
}",
"messages": {
"cases": [
{
"if": "{$game_finished == false AND $game_status == 'not started'}",
"messages": [
{
"app": "state",
"state": "{
var['stack_amnt'] = $bid_amnt - $commission;
var['commission_pot'] += $commission - $fees;
var['author'] = trigger.initial_address;
var['leader'] = trigger.initial_address;
var['game_status'] = 'running';
response['message'] = 'Thank you for playing';
}"
}
]
},
{
"if": "{$game_finished == false AND $game_status == 'running'}",
"messages": [
{
"app": "state",
"state": "{
var['stack_amnt'] += ($bid_amnt - $commission);
var['commission_pot'] += $commission;
var['leader'] = trigger.initial_address;
response['message'] = 'Thank you for playing';
}"
}
]
},
{
"if": "{$game_finished}",
"messages": [
{
"app": "payment",
"payload": {
"cases": [
{
"if": "{(var['author'] == var['leader']) AND (var['commission_pot'] >= $commission_payout_threshold)}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var['leader'] }",
"amount": "{ var['stack_amnt'] }"
},
{
"address": "{ $bot_address }",
"amount": "{ balance[base] - var['stack_amnt'] - $seed_amnt }"
}
]
}
},
{
"if": "{(var['author'] == var['leader']) AND (var['commission_pot'] < $commission_payout_threshold)}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var['leader'] }",
"amount": "{ var['stack_amnt'] }"
}
]
}
},
{
"if": "{(var['author'] != var['leader']) AND (var['commission_pot'] >= $commission_payout_threshold)}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var['author'] }",
"amount": "{ var['stack_amnt'] / 2 }"
},
{
"address": "{ var['leader'] }",
"amount": "{ var['stack_amnt'] / 2 }"
},
{
"address": "{ $bot_address }",
"amount": "{ balance[base] - var['stack_amnt'] - $seed_amnt }"
}
]
}
},
{
"if": "{(var['author'] != var['leader']) AND (var['commission_pot'] < $commission_payout_threshold)}",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var['author'] }",
"amount": "{ var['stack_amnt'] / 2 }"
},
{
"address": "{ var['leader'] }",
"amount": "{ var['stack_amnt'] / 2 }"
}
]
}
}
]
}
},
{
"app": "state",
"state": "{ // game is finished
var['game_status'] = 'not started';
if (var['commission_pot'] >= $commission_payout_threshold) var['commission_pot'] = 0;
var['commission_pot'] += $bid_amnt; // add money from the bot to the commission pot
var['stack_amnt'] = 0;
var['author'] = '';
var['leader'] = '';
response['message'] = 'Game finished.';
}"
}
]
}
]
}
}
]